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>",
"autovalidateMode": "<AutovalidateMode>",
"borderRadius": "<BorderRadius>",
"decoration": "<InputDecorationDecoder>",
"disabledHint": "<JsonWidgetData>",
"dropdownColor": "<Color>",
"elevation": "<int>",
"enabled": "<bool>",
"focusColor": "<Color>",
"focusNode": "<FocusNode>",
"hint": "<JsonWidgetData>",
"icon": "<JsonWidgetData>",
"items": "<List<String>> || <Map<String, dynamic>>",
"iconDisabledColor": "<Color>",
"iconEnabledColor": "<Color>",
"iconSize": "<double>",
"isDense": "<bool>",
"isExpanded": "<bool>",
"itemHeight": "<double>",
"onChanged": "<ValueChanged>",
"onSaved": "<FormFieldSetter>",
"onTap": "<VoidCallback>",
"selectedItemBuilder": "<DropdownButtonBuilder> || <JsonWidgetData>",
"validators": "<List<ValueValidator>>",
"style": "<TextStyle>",
"value": "<dynamic>"
}
As a note, the FocusNode, ValueChanged, FormFieldSetter, and VoidCallback objects 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.
The selectedItemBuilder
can be a DropdownButtonBuilder or
JsonWidgetData. The DropdownButtonBuilder cannot be decoded via JSON
and would have to be bound via the JsonWidgetRegistry. If a
JsonWidgetData object is used then the item's display will be bound to
the dropdown_item_display
variable on the registry and the item's value
will be bound to dropdown_item_value
. This way the widget can associate
properties to those two keys for proper rendering.
The items
can be either a string array where the string will be used for
both the display and the value or a map of strings to values where the key
will be used as the display and the value will be the internal dropdown
value.
See also:
- buildCustom
- InputDecorationDecoder.fromDynamic
- JsonWidgetData.fromDynamic
ThemeDecoder.decodeAutovalidateMode
ThemeDecoder.decodeColor
ThemeDecoder.decodeTextStyle
Validator
Implementation
static JsonDropdownButtonFormFieldBuilder? fromDynamic(
dynamic map, {
JsonWidgetRegistry? registry,
}) {
JsonDropdownButtonFormFieldBuilder? result;
if (map != null) {
result = JsonDropdownButtonFormFieldBuilder(
alignment: ThemeDecoder.decodeAlignment(
map['alignment'],
validate: false,
),
autofocus: JsonClass.parseBool(map['autofocus']),
autovalidateMode: map['autovalidate'] == null
? ThemeDecoder.decodeAutovalidateMode(
map['autovalidateMode'],
validate: false,
)
: JsonClass.parseBool(map['autovalidate']) == true
? AutovalidateMode.always
: AutovalidateMode.disabled,
borderRadius: ThemeDecoder.decodeBorderRadius(
map['borderRadius'],
validate: false,
),
decoration: map['decoration'],
disabledHint: JsonWidgetData.fromDynamic(map['disabledHint']),
dropdownColor: ThemeDecoder.decodeColor(
map['dropdownColor'],
validate: false,
),
elevation: JsonClass.maybeParseInt(map['elevation']) ?? 8,
enableFeedback: map['enableFeedback'] == null
? true
: JsonClass.parseBool(map['enableFeedback']),
enabled:
map['enabled'] == null ? true : JsonClass.parseBool(map['enabled']),
hint: JsonWidgetData.fromDynamic(map['hint']),
icon: JsonWidgetData.fromDynamic(map['icon']),
items: map['items'],
iconDisabledColor: ThemeDecoder.decodeColor(
map['iconDisabledColor'],
validate: false,
),
iconEnabledColor: ThemeDecoder.decodeColor(
map['iconEnabledColor'],
validate: false,
),
iconSize: JsonClass.maybeParseDouble(map['iconSize'], 24.0),
isDense:
map['isDense'] == null ? true : JsonClass.parseBool(map['isDense']),
isExpanded: JsonClass.parseBool(map['isExpanded']),
itemHeight: JsonClass.maybeParseDouble(map['itemHeight']),
menuMaxHeight: JsonClass.maybeParseDouble(map['menuMaxHeight']),
onChanged: map['onChanged'],
onSaved: map['onSaved'],
onTap: map['onTap'],
selectedItemBuilder: map['selectedItemBuilder'],
style: ThemeDecoder.decodeTextStyle(
map['style'],
validate: false,
),
validator: map['validators'] == null
? null
: Validator.fromDynamic({'validators': map['validators']}),
value: map['value'],
);
}
return result;
}