buildPopupMenuButton method
Widget
buildPopupMenuButton(
)
Implementation
@protected
Widget buildPopupMenuButton(BuildParameters params) {
final alias = params.props["alias"] ?? params.id;
final function = events.getValueFunction<Object?>(params.context,
params.actions["onSelected"], params.state, params.parentContext);
final nameKey = params.props["nameKey"] ?? "name";
final valueKey = params.props["valueKey"] ?? "id";
final valueList = getMenuValues(params.props["values"], nameKey, valueKey);
var menuItems = <PopupMenuItem<String>>[];
for (var map in valueList) {
menuItems.add(PopupMenuItem<String>(
value: map[valueKey],
child: Text(properties.getText(map[nameKey], "menu")),
));
}
return PopupMenuButton<String>(
itemBuilder: (a) => menuItems,
key: properties.getKey(params.id),
initialValue: params.props["value"]?.toString(),
color: tryParseColor(params.props["color"]),
tooltip: params.props["tooltip"] != null
? properties.getText(params.props["tooltip"], "label")
: null,
shape: params.buildProp("shape"),
padding: params.buildProp("padding") ?? const EdgeInsets.all(8.0),
enabled: parseBool(params.props["enabled"], defaultValue: true),
offset: params.buildProp("offset") ?? Offset.zero,
elevation: tryParseDouble(params.props["elevation"]),
icon: builder.tryBuildWidget(params.context, params.widgets["icon"],
params.state, params.parentContext),
iconSize: tryParseDouble(params.props["iconSize"]),
child: builder.tryBuildWidget(params.context, params.widgets["child"],
params.state, params.parentContext),
onSelected: (v) {
if (alias != null) {
params.state[alias] = v;
}
if (function != null) {
function.call(v);
}
},
);
}