Skip to content

Instantly share code, notes, and snippets.

@AbhishekDoshi26
Created October 29, 2021 11:13
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/3c64b9d88115db7de031264ae4348ada to your computer and use it in GitHub Desktop.
Save AbhishekDoshi26/3c64b9d88115db7de031264ae4348ada to your computer and use it in GitHub Desktop.
home file for theme example
import 'package:flutter/material.dart';
import 'package:theme_example/main.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool _value = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Switch(
value: _value,
onChanged: (value) {
setState(() {
_value = value;
if (_value)
MyApp.of(context)!.changeTheme(ThemeMode.dark);
else
MyApp.of(context)!.changeTheme(ThemeMode.light);
});
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment