forked from bdlukaa/fluent_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
220 lines (202 loc) · 6.63 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';
import 'package:provider/provider.dart';
import 'package:system_theme/system_theme.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'screens/colors.dart';
import 'screens/forms.dart';
import 'screens/inputs.dart';
import 'screens/others.dart';
import 'screens/settings.dart';
import 'theme.dart';
const String appTitle = 'Fluent UI Showcase for Flutter';
late bool darkMode;
/// Checks if the current environment is a desktop environment.
bool get isDesktop {
if (kIsWeb) return false;
return [
TargetPlatform.windows,
TargetPlatform.linux,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// The platforms the plugin support (01/04/2021 - DD/MM/YYYY):
// - Windows
// - Web
// - Android
if (defaultTargetPlatform == TargetPlatform.windows ||
defaultTargetPlatform == TargetPlatform.android ||
kIsWeb) {
darkMode = await SystemTheme.darkMode;
await SystemTheme.accentInstance.load();
} else {
darkMode = true;
}
runApp(MyApp());
if (isDesktop)
doWhenWindowReady(() {
final win = appWindow;
win.minSize = Size(360, 640);
win.size = Size(755, 545);
win.alignment = Alignment.center;
win.title = appTitle;
win.show();
});
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => AppTheme(),
builder: (context, _) {
final appTheme = context.watch<AppTheme>();
return FluentApp(
title: appTitle,
themeMode: appTheme.mode,
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {'/': (_) => MyHomePage()},
theme: ThemeData(
accentColor: appTheme.color,
brightness: appTheme.mode == ThemeMode.system
? darkMode
? Brightness.dark
: Brightness.light
: appTheme.mode == ThemeMode.dark
? Brightness.dark
: Brightness.light,
focusTheme: FocusThemeData(
glowFactor: is10footScreen() ? 2.0 : 0.0,
),
),
);
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool value = false;
int index = 0;
final colorsController = ScrollController();
final settingsController = ScrollController();
@override
void dispose() {
colorsController.dispose();
settingsController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final appTheme = context.watch<AppTheme>();
return NavigationView(
appBar: NavigationAppBar(
height: !kIsWeb ? appWindow.titleBarHeight : 31.0,
title: () {
if (kIsWeb) return Text(appTitle);
return MoveWindow(
child: Align(alignment: Alignment.center, child: Text(appTitle)),
);
}(),
actions: kIsWeb
? null
: MoveWindow(
child: Row(children: [Spacer(), WindowButtons()]),
),
),
useAcrylic: false,
pane: NavigationPane(
selected: index,
onChanged: (i) => setState(() => index = i),
header: FlutterLogo(),
displayMode: appTheme.displayMode,
onDisplayModeRequested: (mode) {
appTheme.displayMode = mode;
},
// Uncomment the following lines to use the end navigation indicator
// indicatorBuilder: ({
// required BuildContext context,
// int? index,
// double? y,
// required List<Offset> Function() offsets,
// required List<Size> Function() sizes,
// required Axis axis,
// required Widget child,
// }) {
// if (index == null) return child;
// assert(debugCheckHasFluentTheme(context));
// final theme = NavigationPaneThemeData.of(context);
// return EndNavigationIndicator(
// index: index,
// offsets: offsets,
// sizes: sizes,
// child: child,
// color: theme.highlightColor,
// curve: theme.animationCurve ?? Curves.linear,
// y: y ?? 0,
// axis: axis,
// );
// },
items: [
PaneItemHeader(header: Text('User Interaction')),
PaneItem(icon: Icon(Icons.input), title: 'Inputs'),
PaneItem(icon: Icon(Icons.format_align_center), title: 'Forms'),
PaneItemSeparator(),
PaneItemHeader(header: Text('Extra Widgets')),
PaneItem(icon: Icon(Icons.miscellaneous_services), title: 'Others'),
PaneItem(icon: Icon(Icons.color_lens_outlined), title: 'Colors'),
],
autoSuggestBox: AutoSuggestBox(
controller: TextEditingController(),
items: ['Item 1', 'Item 2', 'Item 3', 'Item 4'],
),
autoSuggestBoxReplacement: Icon(Icons.search),
footerItems: [
PaneItemSeparator(),
PaneItem(icon: Icon(Icons.settings), title: 'Settings'),
],
),
content: NavigationBody(index: index, children: [
InputsPage(),
Forms(),
Others(),
ColorsPage(controller: colorsController),
Settings(controller: settingsController),
]),
);
}
}
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
final ThemeData theme = FluentTheme.of(context);
final buttonColors = WindowButtonColors(
iconNormal: theme.inactiveColor,
iconMouseDown: theme.inactiveColor,
iconMouseOver: theme.inactiveColor,
mouseOver: ButtonThemeData.buttonColor(theme, [ButtonStates.hovering]),
mouseDown: ButtonThemeData.buttonColor(theme, [ButtonStates.pressing]),
);
final closeButtonColors = WindowButtonColors(
mouseOver: Colors.red,
mouseDown: Colors.red.dark,
iconNormal: theme.inactiveColor,
iconMouseOver: Colors.red.basedOnLuminance(),
iconMouseDown: Colors.red.dark.basedOnLuminance(),
);
return Row(children: [
MinimizeWindowButton(colors: buttonColors),
MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
]);
}
}