dropdownFieldBuilder function
Widget
dropdownFieldBuilder(
- BuildContext context,
- ChampionFormController controller,
- List<
MultiselectOption> choices, - ChampionOptionSelect field,
- FieldState currentState,
- FieldColorScheme currentColors,
- List<
String> ? defaultValue, - dynamic updateFocus(
- bool focused
- dynamic updateSelectedOption(
- MultiselectOption? selectedOption
Implementation
Widget dropdownFieldBuilder(
BuildContext context,
ChampionFormController controller,
List<MultiselectOption> choices,
ChampionOptionSelect field,
FieldState currentState,
FieldColorScheme currentColors,
List<String>? defaultValue,
Function(bool focused) updateFocus,
Function(MultiselectOption? selectedOption) updateSelectedOption,
) {
return MultiselectWidget(
id: field.id,
controller: controller,
requestFocus: field.requestFocus,
child: DropdownButtonFormField<String>(
value: defaultValue != null && defaultValue.isNotEmpty
? defaultValue.first
: null,
dropdownColor: currentColors.backgroundColor,
items: field.options
.map((option) => DropdownMenuItem<String>(
value: option.value.toString(),
child: Text(
option.label,
style: TextStyle(
color: currentColors.textColor,
),
),
))
.toList(),
onSaved: field.onSubmit != null
? (String? value) {
final FormResults results = FormResults.getResults(
controller: controller, fields: [field]);
field.onSubmit!(results);
}
: null,
onChanged: (String? value) {
// Find the value we're going to pass.
if (value != null) {
final selectedOption =
field.options.firstWhere((val) => value == val.value.toString());
updateSelectedOption(selectedOption);
} else {
updateSelectedOption(null);
}
// Handle onchanged behavior
if (field.onChange != null) {
final FormResults results =
FormResults.getResults(controller: controller, fields: [field]);
field.onChange!(results);
}
},
decoration: getInputDecorationFromScheme(currentColors)?.copyWith(
prefixIcon: field.leading,
suffixIcon: field.trailing,
icon: field.icon,
),
),
);
}