getCustomTheme method
Implementation
@override
Future<CustomThemeData?> getCustomTheme() async {
try {
final themeJson = _prefs.getString(_customThemeKey);
if (themeJson == null) return null;
final Map<String, dynamic> json = jsonDecode(themeJson);
return CustomThemeData(
primaryColor: Color(
int.parse(json['primaryColor'].toString().replaceAll('#', '0xFF')),
),
accentColor: Color(
int.parse(json['accentColor'].toString().replaceAll('#', '0xFF')),
),
backgroundColor: Color(
int.parse(json['backgroundColor'].toString().replaceAll('#', '0xFF')),
),
textColor: Color(
int.parse(json['textColor'].toString().replaceAll('#', '0xFF')),
),
brightness:
json['brightness'] == 'dark' ? Brightness.dark : Brightness.light,
surfaceColor: json['surfaceColor'] != null
? Color(
int.parse(
json['surfaceColor'].toString().replaceAll('#', '0xFF'),
),
)
: Colors.white,
errorColor: json['errorColor'] != null
? Color(
int.parse(
json['errorColor'].toString().replaceAll('#', '0xFF'),
),
)
: Colors.red,
fontFamily: json['fontFamily'],
);
} catch (e) {
await _prefs.remove(_customThemeKey);
return null;
}
}