Skip to content

Instantly share code, notes, and snippets.

@AbhishekDoshi26
Created October 29, 2021 11:08
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 AbhishekDoshi26/cb3a90a671fe546d590f6e97dc403959 to your computer and use it in GitHub Desktop.
Save AbhishekDoshi26/cb3a90a671fe546d590f6e97dc403959 to your computer and use it in GitHub Desktop.
main.dart file for theme example
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