fromDynamic static method
Builds the builder from a Map-like dynamic structure. This expects the JSON format to be of the following structure:
{
"color": <Color>,
"constraints": <BoxConstraints>,
"elevation": <double>,
"enableFeedback": <bool>,
"enabled": <bool>,
"icon": <JsonWidgetData>,
"iconSize": <double>
"initialValue": <T>,
"itemBuilder": <PopupMenuItemBuilder<T>>,
"offset": <Offset>,
"onCanceled": <PopupMenuCanceled>,
"onSelected": <PopupMenuItemSelected<T>>,
"padding": <EdgeInsetsGeometry>,
"shape": <ShapeBorder>,
"splashRadius": <SplashRadius>,
"tooltip": <String>
}
As a note, the PopupMenuItemBuilder<T>, PopupMenuCanceled and PopupMenuItemSelected<T> cannot b eecoded via JSON. Instead, the only way to bind those values to the builder is to use a function or a variable reference via the JsonWidgetRegistry.
See also:
- JsonWidgetData.fromDynamic
ThemeDecoder.decodeBoxConstraints
ThemeDecoder.decodeColor
ThemeDecoder.decodeEdgeInsetsGeometry
ThemeDecoder.decodeOffset
ThemeDecoder.decodePopupMenuPosition
ThemeDecoder.decodeShapeBorder
Implementation
static JsonPopupMenuButtonBuilder? fromDynamic(
dynamic map, {
JsonWidgetRegistry? registry,
}) {
JsonPopupMenuButtonBuilder? result;
if (map != null) {
result = JsonPopupMenuButtonBuilder(
color: ThemeDecoder.decodeColor(
map['color'],
validate: false,
),
constraints: ThemeDecoder.decodeBoxConstraints(
map['constraints'],
validate: false,
),
elevation: JsonClass.parseDouble(
map['elevation'],
),
enableFeedback: map['enableFeedback'] == null
? true
: JsonClass.parseBool(
map['enableFeedback'],
),
enabled: map['enabled'] == null
? true
: JsonClass.parseBool(
map['enabled'],
),
icon: JsonWidgetData.fromDynamic(
map['icon'],
registry: registry,
),
iconSize: JsonClass.parseDouble(map['iconSize']),
initialValue: map['initialValue'],
itemBuilder: map['itemBuilder'],
offset: ThemeDecoder.decodeOffset(
map['offset'],
validate: false,
) ??
Offset.zero,
onCanceled: map['onCanceled'],
onSelected: map['onSelected'],
padding: ThemeDecoder.decodeEdgeInsetsGeometry(
map['padding'],
validate: false,
) ??
EdgeInsets.all(8.0),
position: ThemeDecoder.decodePopupMenuPosition(
map['position'],
validate: false,
),
shape: ThemeDecoder.decodeShapeBorder(
map['shape'],
validate: false,
),
splashRadius: JsonClass.parseDouble(map['splashRadius']),
tooltip: map['tooltip'],
);
}
return result;
}