encodeCupertinoThemeData static method
Encodes the given value
to a JSON representation.
{
"barBackgroundColor": <Color>,
"brightness": <Brightness>,
"primaryColor": <Color>,
"primaryContrastingColor": <Color>,
"scaffoldBackgroundColor": <Color>,
"textTheme": <CupertinoTextThemeData>
}
See also:
Implementation
static Map<String, dynamic>? encodeCupertinoThemeData(
// Set as dynamic rather than CupertinoThemeData to be compatible with 1.22 and 1.24 where the type switches.
dynamic value,
// TODO: 1.24
// NoDefaultCupertinoThemeData value,
) {
Map<String, dynamic>? result;
if (value != null) {
var runtimeTypeStr = value.runtimeType.toString();
// In Flutter < 1.24, the type is: CupertinoThemeData or _NoDefaultCupertinoThemeData
// In Flutter >= 1.24, the type is: NoDefaultCupertinoThemeData
assert(runtimeTypeStr == 'CupertinoThemeData' ||
runtimeTypeStr == 'NoDefaultCupertinoThemeData' ||
runtimeTypeStr == '_NoDefaultCupertinoThemeData');
if (runtimeTypeStr == 'CupertinoThemeData' ||
runtimeTypeStr == 'NoDefaultCupertinoThemeData' ||
runtimeTypeStr == '_NoDefaultCupertinoThemeData') {
result = <String, dynamic>{
'barBackgroundColor': encodeColor(value.barBackgroundColor),
'brightness': encodeBrightness(value.brightness),
'primaryColor': encodeColor(value.primaryColor),
'primaryContrastingColor': encodeColor(value.primaryContrastingColor),
'scaffoldBackgroundColor': encodeColor(value.scaffoldBackgroundColor),
'textTheme': encodeCupertinoTextThemeData(value.textTheme),
};
} else {
throw Exception(
'Unknown type passed in to [encodeCupertinoThemeData]: [$runtimeTypeStr]',
);
}
}
return _stripNull(result);
}