Skip to content

Commit 41556ae

Browse files
committed
Refactor window example to use MaterialApp per window
Replaces the global MyApp widget with individual MaterialApp instances for each window (Primary, Secondary, Tertiary). This change improves window isolation and ensures each window has its own navigation and theming context.
1 parent 923dcd3 commit 41556ae

1 file changed

Lines changed: 42 additions & 47 deletions

File tree

  • examples/multiple_window_example/lib

examples/multiple_window_example/lib/main.dart

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,11 @@ void main() {
1111
WindowManager.instance.setWillHideHook((windowId) {
1212
print('Window $windowId will hide');
1313
});
14-
runApp(const MyApp());
15-
}
16-
17-
class MyApp extends StatelessWidget {
18-
const MyApp({super.key});
19-
20-
// This widget is the root of your application.
21-
@override
22-
Widget build(BuildContext context) {
23-
return MaterialApp(
24-
title: 'Multiple Window Example',
25-
theme: ThemeData(
26-
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
27-
),
28-
home: ViewCollection(
29-
views: [TertiaryWindow(), SecondaryWindow(), PrimaryWindow()],
30-
),
31-
);
32-
}
14+
runWidget(
15+
ViewCollection(
16+
views: [TertiaryWindow(), SecondaryWindow(), PrimaryWindow()],
17+
),
18+
);
3319
}
3420

3521
class PrimaryWindow extends StatefulWidget {
@@ -49,29 +35,32 @@ class _PrimaryWindowState extends State<PrimaryWindow> {
4935
Widget build(BuildContext context) {
5036
return RegularWindow(
5137
controller: _windowController,
52-
child: Scaffold(
53-
appBar: AppBar(title: const Text('Primary Window')),
54-
body: Center(
55-
child: Column(
56-
children: [
57-
FilledButton(
58-
onPressed: () {
59-
Window? primaryWindow;
60-
final windows = WindowManager.instance.getAll();
61-
for (var window in windows) {
62-
if (window.title == 'Primary Window') {
63-
primaryWindow = window;
64-
break;
38+
child: MaterialApp(
39+
title: 'Primary Window',
40+
home: Scaffold(
41+
appBar: AppBar(title: const Text('Primary Window')),
42+
body: Center(
43+
child: Column(
44+
children: [
45+
FilledButton(
46+
onPressed: () {
47+
Window? primaryWindow;
48+
final windows = WindowManager.instance.getAll();
49+
for (var window in windows) {
50+
if (window.title == 'Primary Window') {
51+
primaryWindow = window;
52+
break;
53+
}
6554
}
66-
}
67-
if (primaryWindow != null) {
68-
primaryWindow.setSize(1000, 1000);
69-
primaryWindow.show();
70-
}
71-
},
72-
child: const Text('A Window'),
73-
),
74-
],
55+
if (primaryWindow != null) {
56+
primaryWindow.setSize(1000, 1000);
57+
primaryWindow.show();
58+
}
59+
},
60+
child: const Text('A Window'),
61+
),
62+
],
63+
),
7564
),
7665
),
7766
),
@@ -96,9 +85,12 @@ class _SecondaryWindowState extends State<SecondaryWindow> {
9685
Widget build(BuildContext context) {
9786
return RegularWindow(
9887
controller: _windowController,
99-
child: Scaffold(
100-
appBar: AppBar(title: const Text('Secondary Window')),
101-
body: const Center(child: Text('Secondary Window')),
88+
child: MaterialApp(
89+
title: 'Secondary Window',
90+
home: Scaffold(
91+
appBar: AppBar(title: const Text('Secondary Window')),
92+
body: const Center(child: Text('Secondary Window')),
93+
),
10294
),
10395
);
10496
}
@@ -121,9 +113,12 @@ class _TertiaryWindowState extends State<TertiaryWindow> {
121113
Widget build(BuildContext context) {
122114
return RegularWindow(
123115
controller: _windowController,
124-
child: Scaffold(
125-
appBar: AppBar(title: const Text('Tertiary Window')),
126-
body: const Center(child: Text('Tertiary Window')),
116+
child: MaterialApp(
117+
title: 'Tertiary Window',
118+
home: Scaffold(
119+
appBar: AppBar(title: const Text('Tertiary Window')),
120+
body: const Center(child: Text('Tertiary Window')),
121+
),
127122
),
128123
);
129124
}

0 commit comments

Comments
 (0)