-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.dart
185 lines (172 loc) · 5.27 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
import 'package:example/basic.dart';
import 'package:example/dialog_tabs.dart';
import 'package:example/input.dart';
import 'package:fluent_ui/fluent_ui.dart' as FluentUI;
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:platform_ui/platform_ui.dart';
void main() {
platform = TargetPlatform.macOS;
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => MyAppState();
static MyAppState of(context) =>
context.findAncestorStateOfType<MyAppState>()!;
}
class MyAppState extends State<MyApp> {
ThemeMode themeMode = ThemeMode.system;
bool isMaximized = false;
toggleTheme() {
setState(() {
themeMode =
themeMode == ThemeMode.dark ? ThemeMode.light : ThemeMode.dark;
});
}
@override
Widget build(BuildContext context) {
return PlatformApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
themeMode: themeMode,
androidTheme: ThemeData.light(),
androidDarkTheme: ThemeData.dark(),
macosTheme: MacosThemeData.light(),
macosDarkTheme: MacosThemeData.dark(),
windowsTheme: FluentUI.ThemeData.light(),
windowsDarkTheme: FluentUI.ThemeData.dark(),
home: const MyHomePage(
title: 'Platform UI Demo (AppBar)',
),
windowButtonConfig: PlatformWindowButtonConfig(
onClose: () => print('close'),
onMinimize: () => print('minimize'),
onMaximize: () {
setState(() {
isMaximized = true;
});
print('maximize');
},
onRestore: () {
setState(() {
isMaximized = false;
});
print('restore');
},
isMaximized: () => isMaximized,
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool checked = false;
@override
Widget build(BuildContext context) {
final platforms = List<TargetPlatform>.from(TargetPlatform.values)
..remove(TargetPlatform.fuchsia);
return PlatformScaffold(
appBar: PlatformAppBar(
title: PlatformText(widget.title),
actions: [
PlatformIconButton(
icon: const Icon(
Icons.notifications_active_rounded,
),
onPressed: () {},
),
PlatformIconButton(
icon: Icon(
MyApp.of(context).themeMode == ThemeMode.dark
? Icons.light_mode_outlined
: Icons.dark_mode_outlined,
),
onPressed: MyApp.of(context).toggleTheme,
),
PlatformPopupMenuButton<TargetPlatform>(
items: platforms
.map(
(e) => PlatformPopupMenuItem(
value: e,
child: PlatformText(e.name),
),
)
.toList(),
onCanceled: () {
print("Canceled");
},
onSelected: (value) {
MyApp.of(context).setState(() {
platform = value;
});
},
child: const Icon(Icons.more_vert_rounded),
),
const PlatformWindowButtons(),
],
),
body: PlatformSidebar(
header: Center(child: PlatformText.headline("Header")),
windowsFooterItems: [
FluentUI.PaneItem(
icon: const Icon(Icons.home),
body: const PlatformText("Footer"),
),
],
footer: PlatformTextButton(
child: const Center(child: PlatformText("Footer")),
onPressed: () {},
),
body: {
PlatformSidebarItem(
title: const Text("Basic Widgets"),
icon: const Icon(Icons.widgets_rounded),
): const Basic(),
PlatformSidebarItem(
title: const Text("Form/Input Widgets"),
icon: const Icon(Icons.file_present_rounded),
): const Input(),
PlatformSidebarItem(
title: const Text("Dialog and Tabbar"),
icon: const Icon(Icons.home_rounded),
): PlatformTabView(
body: {
PlatformTab(
label: "Widgets",
icon: const Icon(Icons.collections_bookmark_rounded),
): const DialogTabs(),
PlatformTab(
label: "More Widgets",
icon: const Icon(Icons.format_align_justify),
): const SizedBox.shrink(),
},
),
PlatformSidebarItem(
title: const Text("Settings"),
icon: const Icon(Icons.settings_rounded),
): const Center(
child: PlatformText("Settings"),
),
PlatformSidebarItem(
title: const Text("About"),
icon: const Icon(Icons.info_rounded),
): const Center(
child: PlatformText("About"),
),
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}