select form field widget
a flutter select field widget. it shows a list of options in a dropdown menu.
this widget extend textfield and has a similar behavior as textformfield
usage
in the pubspec.yaml
of your flutter project, add the following dependency:
dependencies:
...
select_form_field: "^1.0.0"
in your library add the following import:
import 'package:select_form_field/select_form_field.dart';
for help getting started with flutter, view the online documentation.
example
set items using a list map passing:
value
: [string],textstyle
: [textstyle | null],label
: [string | null],icon
: [widget | null],enable
: [bool | null],
final list<map<string, dynamic>> _items = [
{
'value': 'boxvalue',
'label': 'box label',
'icon': icon(icons.stop),
},
{
'value': 'circlevalue',
'label': 'circle label',
'icon': icon(icons.fiber_manual_record),
'textstyle': textstyle(color: colors.red),
},
{
'value': 'starvalue',
'label': 'star label',
'enable': false,
'icon': icon(icons.grade),
},
];
selectformfield(
initialvalue: 'circle',
icon: icon(icons.format_shapes),
labeltext: 'shape',
items: _items,
onchanged: (val) => print(val),
onsaved: (val) => print(val),
);
the result of val in onchanged
, validator
and onsaved
will be a string.
so, if you tap on box label item on select menu the result will be boxvalue
.
Comments are closed.