decodeButtonStyle static method
Decodes the value
to a ButtonStyle.
{
"alignment": <AlignmentGeometry>,
"animationDuration": <MaterialStateProperty<double>>,
"backgroundColor": <MaterialStateProperty<Color>>,
"elevation": <MaterialStateProperty<double>>,
"enableFeedback": <bool>,
"fixedSize": <MaterialStateProperty<double>>,
"foregroundColor": <MaterialStateProperty<Color>>,
"maximumSize": <MaterialStateProperty<double>>,
"minimumSize": <MaterialStateProperty<Size>>,
"mouseCursor": <MaterialStateProperty<MouseCursor>>,
"overlayColor": <MaterialStateProperty<Color>>,
"padding": <MaterialStateProperty<EdgeInsetsGeometry>>,
"shadowColor": <MaterialStateProperty<Color>>,
"shape": <MaterialStateProperty<OutlinedBorder>>,
"side": <MaterialStateProperty<BorderSide>>,
"splashFactory": <InteractiveInkSplashFactory>,
"surfaceTintColor": <MaterialStateProperty<Color>>,
"tapTargetSize": <MaterialTapTargetSize>,
"textStyle": <MaterialStateProperty<TextStyle>>,
"visualDensity": <VisualDensity>
}
This will use the properties passed through JSON to create the MaterialStateProperty of each corresponding property by using the MaterialStateProperty.all function with the value passed in.
See also:
- decodeBorderSide
- decodeColor
- decodeEdgeInsetsGeometry
- decodeInteractiveInkFeatureFactory
- decodeMaterialStatePropertyBorderSide
- decodeMaterialStatePropertyColor
- decodeMaterialStatePropertyDouble
- decodeMaterialStatePropertyEdgeInsetsGeometry
- decodeMaterialStatePropertyMouseCursor
- decodeMaterialStatePropertyOutlinedBorder
- decodeMaterialStatePropertySize
- decodeMaterialStatePropertyTextStyle
- decodeMaterialTapTargetSize
- decodeMouseCursor
- decodeOutlinedBorder
- decodeSize
- decodeTextStyle
- decodeVisualDensity
Implementation
static ButtonStyle? decodeButtonStyle(
dynamic value, {
bool validate = true,
}) {
ButtonStyle? result;
if (value is ButtonStyle) {
result = value;
} else if (value != null) {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/button_style',
value: value,
validate: validate,
));
result = ButtonStyle(
alignment: decodeAlignment(value['alignment']),
animationDuration: JsonClass.parseDurationFromMillis(
value['animationDuration'],
),
backgroundColor: decodeMaterialStatePropertyColor(
value['backgroundColor'],
validate: false,
),
elevation: decodeMaterialStatePropertyDouble(value['elevation']),
enableFeedback: value['enableFeedback'] == null
? null
: JsonClass.parseBool(value['enableFeedback']),
fixedSize: decodeMaterialStatePropertySize(
value['fixedSize'],
validate: false,
),
foregroundColor: decodeMaterialStatePropertyColor(
value['foregroundColor'],
validate: false,
),
maximumSize: decodeMaterialStatePropertySize(
value['maximumSize'],
validate: false,
),
minimumSize: decodeMaterialStatePropertySize(
value['minimumSize'],
validate: false,
),
mouseCursor: decodeMaterialStatePropertyMouseCursor(
value['mouseCursor'],
validate: false,
),
overlayColor: decodeMaterialStatePropertyColor(
value['overlayColor'],
validate: false,
),
padding: decodeMaterialStatePropertyEdgeInsetsGeometry(
value['padding'],
validate: false,
),
shadowColor: decodeMaterialStatePropertyColor(
value['shadowColor'],
validate: false,
),
shape: decodeMaterialStatePropertyOutlinedBorder(
value['shape'],
validate: false,
),
side: decodeMaterialStatePropertyBorderSide(
value['side'],
validate: false,
),
splashFactory: decodeInteractiveInkFeatureFactory(
value['splashFactory'],
),
surfaceTintColor: decodeMaterialStatePropertyColor(
value['surfaceTintColor'],
),
tapTargetSize: decodeMaterialTapTargetSize(
value['tapTargetSize'],
validate: false,
),
textStyle: decodeMaterialStatePropertyTextStyle(
value['textStyle'],
validate: false,
),
visualDensity: decodeVisualDensity(
value['visualDensity'],
validate: false,
),
);
}
return result;
}