Skip to content

Instantly share code, notes, and snippets.

@rodolfofranco
Created May 24, 2020 04:28
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 rodolfofranco/405a5af87f5bb181f1a342118a3568ca to your computer and use it in GitHub Desktop.
Save rodolfofranco/405a5af87f5bb181f1a342118a3568ca to your computer and use it in GitHub Desktop.
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String mode = 'Light';
bool isDark = false;
@override
Widget build(BuildContext context) {
final themeNotifier = Provider.of<ThemeNotifier>(context);
return Scaffold(
body: Stack(
children: <Widget>[
Center(child: Text('Mode is: ' + mode)),
Align(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.all(40.0),
child: Switch(
value: isDark,
onChanged: (bool newVal) {
setState(() {
isDark = newVal;
});
if (isDark) {
mode = 'Dark';
themeNotifier.setTheme(darkTheme);
} else {
mode = 'Light';
themeNotifier.setTheme(lightTheme);
}
}),
))
],
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment