fromDynamic static method
Builds the builder from a Map-like dynamic structure. This expects the JSON format to be of the following structure:
{
"activeColor": <Color>,
"autovalidatMode": <AutovalidateMode>,
"dragStartBehavior": <DragStartBehavior>,
"enabled": <bool>,
"label": <String>,
"onChanged": <ValueCallback<bool>>,
"onSaved": <ValueCallback<bool>>,
"thumbColor": <Color>,
"trackColor": <Color>,
"validators": <ValueValidator[]>,
"value": <bool>,
"visualDensity": <VisualDensity>,
}
As a note, the ValueCallback<bool>
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:
- buildCustom
ThemeDecoder.decodeAutovalidateMode
ThemeDecoder.decodeColor
ThemeDecoder.decodeDragStartBehavior
ThemeDecoder.decodeVisualDensity
Validator
Implementation
static JsonCupertinoSwitchBuilder? fromDynamic(
dynamic map, {
JsonWidgetRegistry? registry,
}) {
JsonCupertinoSwitchBuilder? result;
if (map != null) {
result = JsonCupertinoSwitchBuilder(
activeColor: ThemeDecoder.decodeColor(
map['activeColor'],
validate: false,
),
autovalidateMode: map['autovalidate'] == null
? ThemeDecoder.decodeAutovalidateMode(map['autovalidateMode'])
: JsonClass.parseBool(map['autovalidate']) == true
? AutovalidateMode.always
: AutovalidateMode.disabled,
dragStartBehavior: ThemeDecoder.decodeDragStartBehavior(
map['dragStartBehavior'],
validate: false,
),
enabled:
map['enabled'] == null ? true : JsonClass.parseBool(map['enabled']),
label: map['label'],
onChanged: map['onChanged'],
onSaved: map['onSaved'],
thumbColor: ThemeDecoder.decodeColor(
map['thumbColor'],
validate: false,
),
trackColor: ThemeDecoder.decodeColor(
map['trackColor'],
validate: false,
),
validator: map['validators'] == null
? null
: Validator.fromDynamic({'validators': map['validators']}),
value: JsonClass.parseBool(map['value']),
visualDensity: ThemeDecoder.decodeVisualDensity(
map['visualDensity'],
validate: false,
),
);
}
return result;
}