Created
July 3, 2024 03:25
-
-
Save luo3house/bc86e104037ae8be72ffccf7ba49c40f to your computer and use it in GitHub Desktop.
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'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
home: StatefulBuilder(builder: (_, setState) { | |
onChange() { | |
MyTheme.instance = | |
MyTheme.instance == MyTheme.light ? MyTheme.dark : MyTheme.light; | |
setState(() {}); | |
} | |
return Scaffold( | |
backgroundColor: MyTheme.instance.bgColor, | |
body: GestureDetector( | |
onTap: onChange, | |
behavior: HitTestBehavior.opaque, | |
child: Center( | |
child: Text( | |
"Change Theme", | |
style: TextStyle(color: MyTheme.instance.color), | |
), | |
), | |
), | |
); | |
}), | |
); | |
} | |
} | |
class MyTheme { | |
static var instance = light; | |
static var light = MyTheme(); | |
static var dark = MyTheme() | |
..color = Colors.white | |
..bgColor = Colors.black; | |
var color = Colors.black; | |
var bgColor = Colors.white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment