forked from bdlukaa/fluent_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.dart
150 lines (142 loc) · 4.52 KB
/
settings.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:provider/provider.dart';
import '../theme.dart';
const List<String> accentColorNames = [
'System',
'Yellow',
'Orange',
'Red',
'Magenta',
'Purple',
'Blue',
'Teal',
'Green',
];
class Settings extends StatelessWidget {
const Settings({Key? key, this.controller}) : super(key: key);
final ScrollController? controller;
@override
Widget build(BuildContext context) {
final appTheme = context.watch<AppTheme>();
final tooltipThemeData = TooltipThemeData(decoration: () {
final radius = BorderRadius.zero;
final shadow = [
BoxShadow(
color: Colors.black.withOpacity(0.2),
offset: Offset(1, 1),
blurRadius: 10.0,
),
];
final border = Border.all(color: Colors.grey[100], width: 0.5);
if (context.theme.brightness == Brightness.light) {
return BoxDecoration(
color: Colors.white,
borderRadius: radius,
border: border,
boxShadow: shadow,
);
} else {
return BoxDecoration(
color: Colors.grey,
borderRadius: radius,
border: border,
boxShadow: shadow,
);
}
}());
return ScaffoldPage(
header: PageHeader(title: Text('Settings')),
content: ListView(
padding: EdgeInsets.only(
bottom: kPageDefaultVerticalPadding,
left: PageHeader.horizontalPadding(context),
right: PageHeader.horizontalPadding(context),
),
controller: controller,
children: [
Text('Theme mode', style: context.theme.typography.subtitle),
...List.generate(ThemeMode.values.length, (index) {
final mode = ThemeMode.values[index];
return RadioListTile(
checked: appTheme.mode == mode,
onChanged: (value) {
if (value) {
appTheme.mode = mode;
}
},
title: Text(
'$mode'.replaceAll('ThemeMode.', ''),
style: TextStyle(fontWeight: FontWeight.normal),
),
);
}),
/// MediaQuery.of(context).brightness only doesn't work on windows
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows)
Text(
'ThemeMode.system may not work because MediaQuery.of(context).brightness is not implemented on windows yet.'
'\nWe must wait until Flutter Desktop stable release',
style: context.theme.typography.caption,
),
Text(
'Navigation Pane Display Mode',
style: context.theme.typography.subtitle,
),
...List.generate(PaneDisplayMode.values.length, (index) {
final mode = PaneDisplayMode.values[index];
return RadioListTile(
checked: appTheme.displayMode == mode,
onChanged: (value) {
if (value) {
appTheme.displayMode = mode;
}
},
title: Text(
mode.toString().replaceAll('PaneDisplayMode.', ''),
style: TextStyle(fontWeight: FontWeight.normal),
),
);
}),
Text('Accent Color', style: context.theme.typography.subtitle),
Wrap(children: [
Tooltip(
style: tooltipThemeData,
child: _buildColorBlock(appTheme, systemAccentColor),
message: accentColorNames[0],
),
...List.generate(Colors.accentColors.length, (index) {
final color = Colors.accentColors[index];
return Tooltip(
style: tooltipThemeData,
message: accentColorNames[index + 1],
child: _buildColorBlock(appTheme, color),
);
}),
]),
],
),
);
}
Widget _buildColorBlock(AppTheme appTheme, AccentColor color) {
return Button(
onPressed: () {
appTheme.color = color;
},
style: ButtonThemeData(
padding: EdgeInsets.zero,
margin: EdgeInsets.all(2.0),
),
builder: (context, state) {
return Container(
height: 40,
width: 40,
color: color,
alignment: Alignment.center,
child: appTheme.color == color
? Icon(Icons.check, color: color.basedOnLuminance())
: null,
);
},
);
}
}