Last active
April 13, 2021 00:32
-
-
Save IsmailAlamKhan/5bbb8898b44bd867f51dba018d8f0c06 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
import 'package:flutter/material.dart'; | |
import 'package:get/get.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Material App', | |
themeMode: ThemeMode.system, | |
darkTheme: ThemeData.dark(), | |
theme: ThemeData.light(), | |
home: Home(), | |
); | |
} | |
} | |
class Home extends StatelessWidget { | |
const Home({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: ThemeClass.of(context).color, | |
); | |
} | |
} | |
class ThemeClass { | |
final Color _darkColor = Colors.blue; | |
final Color _lightColor = Colors.green; | |
Color? color; | |
ThemeClass.of(BuildContext context) { | |
print(context.mediaQuery.platformBrightness); | |
if (MediaQuery.of(context).platformBrightness == Brightness.dark) { | |
color = _darkColor; | |
} else { | |
color = _lightColor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment