fromDynamic static method
Builds the builder from a Map-like dynamic structure. This expects the JSON format to be of the following structure:
{
"clipBehavior": <Clip>,
"color": "<Color>",
"constraints": "<BoxConstraints>",
"elevation": "<double>",
"enableFeedback": "<bool>",
"enabled": "<bool>",
"icon": "<JsonWidgetData>",
"iconSize": "<double>",
"initialValue": "<T>",
"itemBuilder": "<PopupMenuItemBuilder<T>>",
"offset": "<Offset>",
"onCanceled": "<PopupMenuCanceled>",
"onOpened": "<VoidCallback>",
"onSelected": "<PopupMenuItemSelected<T>>",
"padding": "<EdgeInsetsGeometry>",
"shadowColor": "<Color>",
"shape": "<ShapeBorder>",
"splashRadius": "<SplashRadius>",
"surfaceTintColor": "<Color>",
"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.decodeClip
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(
clipBehavior: ThemeDecoder.decodeClip(
map['clipBehavior'],
validate: false,
) ??
Clip.hardEdge,
color: ThemeDecoder.decodeColor(
map['color'],
validate: false,
),
constraints: ThemeDecoder.decodeBoxConstraints(
map['constraints'],
validate: false,
),
elevation: JsonClass.maybeParseDouble(
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.maybeParseDouble(map['iconSize']),
initialValue: map['initialValue'],
itemBuilder: map['itemBuilder'],
offset: ThemeDecoder.decodeOffset(
map['offset'],
validate: false,
) ??
Offset.zero,
onCanceled: map['onCanceled'],
onOpened: map['onSelected'],
onSelected: map['onSelected'],
padding: ThemeDecoder.decodeEdgeInsetsGeometry(
map['padding'],
validate: false,
) ??
const EdgeInsets.all(8.0),
position: ThemeDecoder.decodePopupMenuPosition(
map['position'],
validate: false,
),
shadowColor: ThemeDecoder.decodeColor(
map['shadowColor'],
validate: false,
),
shape: ThemeDecoder.decodeShapeBorder(
map['shape'],
validate: false,
),
splashRadius: JsonClass.maybeParseDouble(map['splashRadius']),
surfaceTintColor: ThemeDecoder.decodeColor(
map['surfaceTintColor'],
validate: false,
),
tooltip: map['tooltip'],
);
}
return result;
}