-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
67 lines (61 loc) · 2.07 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import 'package:flutter/material.dart';
import 'package:reactive_theme/reactive_theme.dart';
void main() async {
//Get the saved thememode here
final thememode = await ReactiveMode.getSavedThemeMode();
// then pass it to the MyApp()
runApp(MyApp(savedThemeMode: thememode));
}
class MyApp extends StatelessWidget {
const MyApp({super.key, required this.savedThemeMode});
final ThemeMode? savedThemeMode;
@override
Widget build(BuildContext context) {
// Wrap with [Reactive Themer] Widget
return ReactiveThemer(
// loads the saved thememode.
// If null then ThemeMode.system is used
savedThemeMode: savedThemeMode,
builder: (reactiveMode) => MaterialApp(
debugShowCheckedModeBanner: false,
//Pass the reactiveMode to the themeMode parameter in order to toggle theme
themeMode: reactiveMode,
title: 'Reactive Theme Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
brightness: Brightness.light, seedColor: Colors.deepPurple),
useMaterial3: true,
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
brightness: Brightness.dark, seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const HomePage(),
),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//Change Theme Using these [ReactiveSwitch]
const Center(child: ReactiveSwitch()),
const SizedBox(height: 20),
//Change Theme Using these [ReactiveThemeBtn]
const Center(child: ReactiveThemeBtn()),
const SizedBox(height: 20),
//Accessible Bool for checking isDarkmode and !isDarkmode
ReactiveMode.isDarkMode(context)
? const Text('is darkmode')
: const Text('is not darkmode changed'),
],
),
);
}
}