fromDynamic static method
Builds the builder from a Map-like dynamic structure. This expects the JSON format to be of the following structure:
{
"alignment": "<Alignment>",
"autofocus": "<bool>",
"color": "<Color>",
"constraints": "<BoxConstraints>",
"disabledColor": "<Color>",
"enableFeedback": "<bool>",
"focusColor": "<Color>",
"focusNode": "<FocusNode>",
"highlightColor": "<Color>",
"hoverColor": "<Color>",
"icon": "<JsonWidgetData>",
"iconSize": "<double>",
"isSelected": "<bool>",
"mouseCursor": "<MouseCursor>",
"onPressed": "<VoidCallback>",
"padding": "<EdgeInsetsGeometry>",
"selectedIcon": "<JsonWidgetData>",
"splashColor": "<Color>",
"splashRadius": "<double>",
"style": "<ButtonStyle>",
"tooltip": "<String>",
"visualDensity": "<VisualDensity>"
}
This can accept a "child" in place of the "icon". This considers both of those as synonyms and if both are set, the "icon" will take preference.
As a note, the FocusNode, and VoidCallback cannot be decoded 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:
ThemeDecoder.decodeAlignment
ThemeDecoder.decodeBoxConstraints
ThemeDecoder.decodeButtonStyle
ThemeDecoder.decodeColor
ThemeDecoder.decodeEdgeInsetsGeometry
ThemeDecoder.decodeMouseCursor
ThemeDecoder.decodeVisualDensity
Implementation
static JsonIconButtonBuilder? fromDynamic(
dynamic map, {
JsonWidgetRegistry? registry,
}) {
JsonIconButtonBuilder? result;
if (map != null) {
result = JsonIconButtonBuilder(
alignment: ThemeDecoder.decodeAlignment(
map['alignment'],
validate: false,
) ??
Alignment.center,
autofocus: JsonClass.parseBool(map['autofocus']),
color: ThemeDecoder.decodeColor(
map['color'],
validate: false,
),
constraints: ThemeDecoder.decodeBoxConstraints(
map['constraints'],
validate: false,
),
disabledColor: ThemeDecoder.decodeColor(
map['disabledColor'],
validate: false,
),
enableFeedback: map['enableFeedback'] == null
? true
: JsonClass.parseBool(map['enableFeedback']),
focusColor: ThemeDecoder.decodeColor(
map['focusColor'],
validate: false,
),
focusNode: map['focusColor'],
highlightColor: ThemeDecoder.decodeColor(
map['highlightColor'],
validate: false,
),
hoverColor: ThemeDecoder.decodeColor(
map['hoverColor'],
validate: false,
),
icon: JsonWidgetData.fromDynamic(map['icon'], registry: registry),
iconSize: JsonClass.maybeParseDouble(map['iconSize'], 24.0)!,
isSelected: map['isSelected'] == null
? null
: JsonClass.parseBool(map['isSelected']),
mouseCursor: ThemeDecoder.decodeMouseCursor(
map['mouseCursor'],
validate: false,
) ??
SystemMouseCursors.click,
onPressed: map['onPressed'],
padding: ThemeDecoder.decodeEdgeInsetsGeometry(
map['padding'],
validate: false,
) ??
const EdgeInsets.all(8.0),
selectedIcon:
JsonWidgetData.fromDynamic(map['selectedIcon'], registry: registry),
splashColor: ThemeDecoder.decodeColor(
map['splashColor'],
validate: false,
),
splashRadius: JsonClass.maybeParseDouble(map['splashRadius']),
style: ThemeDecoder.decodeButtonStyle(
map['style'],
validate: false,
),
tooltip: map['tooltip']?.toString(),
visualDensity: ThemeDecoder.decodeVisualDensity(
map['visualDensity'],
validate: false,
),
);
}
return result;
}