fromDynamic static method
- dynamic map, {
- Map<
String, dynamic> args = const {}, - JsonWidgetRegistry? registry,
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:
Implementation
static JsonDropdownButtonFormFieldBuilderModel fromDynamic(
dynamic map, {
Map<String, dynamic> args = const {},
JsonWidgetRegistry? registry,
}) {
final result = maybeFromDynamic(
map,
args: args,
registry: registry,
);
if (result == null) {
throw Exception(
'[JsonDropdownButtonFormFieldBuilder]: requested to parse from dynamic, but the input is null.',
);
}
return result;
}