decodeWidgetStatePropertyTextStyle static method
WidgetStateProperty<TextStyle?> ?
decodeWidgetStatePropertyTextStyle(
- dynamic value, {
- bool validate = true,
Decodes a value
into a TextStyle based WidgetStateProperty. This
accepts a TextStyle or a String which will be resolved for all states.
Alternatively, if the value
is a Map then this expects the following
format:
{
"disabled": "<TextStyle>",
"dragged": "<TextStyle>",
"empty": "<TextStyle>",
"error": "<TextStyle>",
"focused": "<TextStyle>",
"hovered": "<TextStyle>",
"pressed": "<TextStyle>",
"scrolledUnder": "<TextStyle>",
"selected": "<TextStyle>"
}
See also:
Implementation
static WidgetStateProperty<TextStyle?>? decodeWidgetStatePropertyTextStyle(
dynamic value, {
bool validate = true,
}) {
WidgetStateProperty<TextStyle?>? result;
if (value is WidgetStateProperty<TextStyle?>) {
result = value;
} else if (value != null) {
if (value is TextStyle) {
result = WidgetStateProperty.all<TextStyle?>(value);
} else if (value is String) {
result = WidgetStateProperty.all<TextStyle?>(decodeTextStyle(
value,
validate: false,
));
} else if (value is Map) {
final testValues = [
'disabled',
'dragged',
'empty',
'error',
'focused',
'hovered',
'pressed',
'scrolledUnder',
'selected',
];
var isMsp = false;
for (var key in value.keys) {
if (testValues.contains(key)) {
isMsp = true;
break;
}
}
if (isMsp != true) {
result = WidgetStateProperty.all<TextStyle?>(
decodeTextStyle(
value,
validate: false,
),
);
} else {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/widget_state_property_text_style',
value: value,
validate: validate,
));
result = MapWidgetStateProperty.resolveWith((states) {
TextStyle? result;
if (states.contains(WidgetState.disabled)) {
result = decodeTextStyle(
value['disabled'],
validate: false,
);
} else if (states.contains(WidgetState.dragged)) {
result = decodeTextStyle(
value['dragged'],
validate: false,
);
} else if (states.contains(WidgetState.error)) {
result = decodeTextStyle(
value['error'],
validate: false,
);
} else if (states.contains(WidgetState.focused)) {
result = decodeTextStyle(
value['focused'],
validate: false,
);
} else if (states.contains(WidgetState.hovered)) {
result = decodeTextStyle(
value['hovered'],
validate: false,
);
} else if (states.contains(WidgetState.pressed)) {
result = decodeTextStyle(
value['pressed'],
validate: false,
);
} else if (states.contains(WidgetState.scrolledUnder)) {
result = decodeTextStyle(
value['scrolledUnder'],
validate: false,
);
} else if (states.contains(WidgetState.selected)) {
result = decodeTextStyle(
value['selected'],
validate: false,
);
} else {
result = decodeTextStyle(
value['empty'],
validate: false,
);
}
return result;
});
}
} else {
result = WidgetStateProperty.all<TextStyle?>(value);
}
}
return result;
}