Created
May 24, 2020 04:28
-
-
Save rodolfofranco/405a5af87f5bb181f1a342118a3568ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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