Created
April 13, 2020 18:09
-
-
Save ritesh-sharma33/4df706c0e928ea4411d8d313004cb501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
List<ThemeItem> data = List(); | |
String dynTheme; | |
Future<void> getDefault() async { | |
data = ThemeItem.getThemeItems(); | |
SharedPreferences prefs = await SharedPreferences.getInstance(); | |
dynTheme = prefs.getString("dynTheme") ?? 'light-purple-amber'; | |
} | |
@override | |
Widget build(BuildContext context) { | |
getDefault(); | |
return DynamicTheme( | |
defaultBrightness: Brightness.light, | |
data: (Brightness brightness) { | |
getDefault(); | |
for (int i = 0; i < data.length; i++) { | |
if (data[i].slug == this.dynTheme) { | |
return data[i].themeData; | |
} | |
} | |
return data[0].themeData; | |
}, | |
themedWidgetBuilder: (context, theme) { | |
return MaterialApp( | |
theme: theme, | |
title: "Switching themes like a fox", | |
debugShowCheckedModeBanner: false, | |
home: HomePage(), | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment