Skip to content

Instantly share code, notes, and snippets.

@nonsocchi
Last active May 17, 2023 19:59
Show Gist options
  • Save nonsocchi/94d13992e632131e2d53bad3a9a41646 to your computer and use it in GitHub Desktop.
Save nonsocchi/94d13992e632131e2d53bad3a9a41646 to your computer and use it in GitHub Desktop.
riverpod_app_theme: switching theme with provider
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Consumer(
builder: (_, ref, __) => MaterialApp(
debugShowCheckedModeBanner: false,
// Define a light and dark color theme. Then, read the user's
// preferred ThemeMode (light, dark, or system default) from the
// ThemingController to display the correct theme.
theme: ThemeData(useMaterial3: true),
darkTheme: ThemeData.dark(useMaterial3: true),
themeMode: ref.watch(themingControllerProvider),
home: const ThemingView(),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment