Created
October 29, 2021 11:08
-
-
Save AbhishekDoshi26/cb3a90a671fe546d590f6e97dc403959 to your computer and use it in GitHub Desktop.
main.dart file for theme example
This file contains 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:theme_example/home.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
static _MyAppState? of(BuildContext context) => context.findAncestorStateOfType<_MyAppState>(); | |
} | |
class _MyAppState extends State<MyApp> { | |
ThemeMode _themeMode = ThemeMode.light; | |
void changeTheme(ThemeMode themeMode) { | |
setState(() { | |
_themeMode = themeMode; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Material App', | |
themeMode: _themeMode, | |
theme: ThemeData(), | |
darkTheme: ThemeData.dark(), | |
home: Home(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment