buildDropdownButton method
Implementation
@protected
Widget buildDropdownButton(BuildParameters params) {
final alias = params.props["alias"] ?? params.id;
final nameKey = params.props["nameKey"] ?? "name";
final valueKey = params.props["valueKey"] ?? "id";
final valueList = getMenuValues(params.props["values"], nameKey, valueKey);
final menuItems = <DropdownMenuItem<String>>[];
for (var map in valueList) {
menuItems.add(DropdownMenuItem<String>(
value: map[valueKey],
alignment:
params.buildProp("alignment") ?? AlignmentDirectional.centerStart,
child: Text(properties.getText(map[nameKey], "menu"),
overflow: TextOverflow.ellipsis),
));
}
final enabled = parseBool(params.props["enabled"], defaultValue: true);
final textStyle =
enabled ? params.buildProp("style") : params.buildProp("disabledStyle");
ValueChanged<String?>? onChangeFunc;
if (enabled) {
final onChangeAction = events.getValueFunction<String?>(params.context,
params.actions["onChanged"], params.state, params.parentContext);
onChangeFunc = (newValue) {
if (onChangeAction != null) {
onChangeAction(newValue);
}
};
}
final widgetMap = <String, Widget>{};
for (var key in params.widgets.keys) {
if (params.widgets[key] is List) {
continue;
}
widgetMap[key] = builder.buildWidget(params.context, params.widgets[key],
params.state, params.parentContext);
}
return DropdownButtonFormField<String>(
key: properties.getKey(params.id),
style: textStyle,
focusColor: tryParseColor(params.props["focusColor"]),
dropdownColor: tryParseColor(params.props["dropdownColor"]),
iconEnabledColor: tryParseColor(params.props["iconEnabledColor"]),
iconDisabledColor: tryParseColor(params.props["iconDisabledColor"]),
elevation: parseInt(params.props["elevation"], defaultValue: 8),
isExpanded: true,
itemHeight: tryParseDouble(params.props["itemHeight"]),
alignment:
params.buildProp("alignment") ?? AlignmentDirectional.centerStart,
decoration: params.buildProp("decoration", argument: widgetMap),
autovalidateMode: AutovalidateMode.disabled,
hint: builder.tryBuildWidget(params.context, params.widgets["hint"],
params.state, params.parentContext),
value: params.props["value"]?.toString(),
validator: builder.getStringValidator(params.props),
icon: builder.tryBuildWidget(params.context, params.widgets["icon"],
params.state, params.parentContext),
iconSize: parseDouble(params.props["iconSize"], defaultValue: 24.0),
menuMaxHeight: tryParseDouble(params.props["menuMaxHeight"]),
items: menuItems,
onChanged: onChangeFunc,
onSaved: (v) {
if (alias != null) {
params.state[alias] = v;
}
},
);
}