Skip to content

Instantly share code, notes, and snippets.

@ritesh-sharma33
Created April 13, 2020 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritesh-sharma33/4df706c0e928ea4411d8d313004cb501 to your computer and use it in GitHub Desktop.
Save ritesh-sharma33/4df706c0e928ea4411d8d313004cb501 to your computer and use it in GitHub Desktop.
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