Skip to content

Instantly share code, notes, and snippets.

@RodBr
Last active May 18, 2020 05:52
Show Gist options
  • Select an option

  • Save RodBr/31cd45bcfc5afbe8e64f8747105845c6 to your computer and use it in GitHub Desktop.

Select an option

Save RodBr/31cd45bcfc5afbe8e64f8747105845c6 to your computer and use it in GitHub Desktop.
Themes in 3 lines
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ThemeMode _themeMode = ThemeMode.system;
@override
Widget build(BuildContext context) {
print('${MediaQuery.of(context).platformBrightness}');
print('${Theme.of(context).brightness}');
return Scaffold(
appBar: AppBar(),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Center(
child: Text(
'System Brightness: ${Get.mediaQuery.platformBrightness.toString()}',
style: TextStyle(fontSize: 20),
),
),
SizedBox(height: 24),
Center(
child: Text(
'Theme Brightness: ${Get.theme.brightness.toString()}',
style: TextStyle(fontSize: 20),
),
),
SizedBox(height: 24),
Text(
'ThemeMode',
style: TextStyle(fontSize: 20),
textAlign: TextAlign.left,
),
RadioListTile(
title: Text('system'),
value: ThemeMode.system,
groupValue: _themeMode,
onChanged: (value) {
setState(() {
_themeMode = value;
Get.changeThemeMode(_themeMode); //STEP 3 - change themes
});
},
),
RadioListTile(
title: Text('dark'),
value: ThemeMode.dark,
groupValue: _themeMode,
onChanged: (value) {
setState(() {
_themeMode = value;
Get.changeThemeMode(_themeMode);
});
},
),
RadioListTile(
title: Text('light'),
value: ThemeMode.light,
groupValue: _themeMode,
onChanged: (value) {
setState(() {
_themeMode = value;
Get.changeThemeMode(_themeMode);
});
},
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment