decodeMaterialStatePropertyTextStyle static method
MaterialStateProperty<TextStyle?> ?
decodeMaterialStatePropertyTextStyle(
- dynamic value, {
- bool validate = true,
Decodes a value
into a TextStyle based MaterialStateProperty. 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 MaterialStateProperty<TextStyle?>?
decodeMaterialStatePropertyTextStyle(
dynamic value, {
bool validate = true,
}) {
MaterialStateProperty<TextStyle?>? result;
if (value is MaterialStateProperty<TextStyle?>) {
result = value;
} else if (value != null) {
if (value is TextStyle) {
result = MaterialStateProperty.all<TextStyle?>(value);
} else if (value is String) {
result = MaterialStateProperty.all<TextStyle?>(decodeTextStyle(value));
} else if (value is Map) {
var 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 = MaterialStateProperty.all<TextStyle?>(
decodeTextStyle(value),
);
} else {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/material_state_property_text_style',
value: value,
validate: validate,
));
result = MaterialStateProperty.resolveWith((states) {
TextStyle? result;
if (states.contains(MaterialState.disabled)) {
result = decodeTextStyle(value['disabled']);
} else if (states.contains(MaterialState.dragged)) {
result = decodeTextStyle(value['dragged']);
} else if (states.contains(MaterialState.error)) {
result = decodeTextStyle(value['error']);
} else if (states.contains(MaterialState.focused)) {
result = decodeTextStyle(value['focused']);
} else if (states.contains(MaterialState.hovered)) {
result = decodeTextStyle(value['hovered']);
} else if (states.contains(MaterialState.pressed)) {
result = decodeTextStyle(value['pressed']);
} else if (states.contains(MaterialState.scrolledUnder)) {
result = decodeTextStyle(value['scrolledUnder']);
} else if (states.contains(MaterialState.selected)) {
result = decodeTextStyle(value['selected']);
} else {
result = decodeTextStyle(value['empty']);
}
return result;
});
}
} else {
result = MaterialStateProperty.all<TextStyle?>(value);
}
}
return result;
}