generated from Stacked-Org/package-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dark_light_view.dart
79 lines (76 loc) · 2.74 KB
/
dark_light_view.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
68
69
70
71
72
73
74
75
76
77
78
79
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_themes/stacked_themes.dart';
import 'dark_light_viewmodel.dart';
class DarkLightView extends StatelessWidget {
const DarkLightView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<DarkLightViewModel>.reactive(
builder: (context, model, child) => Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'This adjusts Dark/Light depending on the System brightness setting and if you set themeMode to system in the main file.',
textAlign: TextAlign.center,
),
SizedBox(
height: 30,
),
GestureDetector(
onTap: () {
var themeManger = getThemeManager(context);
themeManger.toggleDarkLightTheme();
},
child: Text(
'Tapping this toggles Dark/Light theme',
textAlign: TextAlign.center,
),
),
SizedBox(
height: 30,
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MaterialButton(
child: Text('Dark'),
color: Colors.grey,
onPressed: () {
var themeManger = getThemeManager(context);
themeManger.setThemeMode(ThemeMode.dark);
},
),
MaterialButton(
child: Text('Light'),
color: Colors.grey,
onPressed: () {
var themeManger = getThemeManager(context);
themeManger.setThemeMode(ThemeMode.light);
},
),
MaterialButton(
child: Text('System'),
color: Colors.grey,
onPressed: () {
var themeManger = getThemeManager(context);
themeManger.setThemeMode(ThemeMode.system);
},
),
],
)
],
),
),
),
),
viewModelBuilder: () => DarkLightViewModel(),
);
}
}