@@ -33,10 +33,10 @@ abstract class WindowController with ChangeNotifier {
33
33
WindowController ._({
34
34
VoidCallback ? onDestroyed,
35
35
void Function (String )? onError,
36
- required Future <WindowCreationResult > future,
36
+ required Future <_WindowCreationResult > future,
37
37
}) : _future = future {
38
38
_future
39
- .then ((WindowCreationResult metadata) async {
39
+ .then ((_WindowCreationResult metadata) async {
40
40
_view = metadata.view;
41
41
_state = metadata.state;
42
42
_size = metadata.size;
@@ -70,7 +70,7 @@ abstract class WindowController with ChangeNotifier {
70
70
/// created and is ready to be used. Otherwise, returns false.
71
71
bool get isReady => _view != null ;
72
72
73
- final Future <WindowCreationResult > _future;
73
+ final Future <_WindowCreationResult > _future;
74
74
75
75
late _WindowListener _listener;
76
76
@@ -98,7 +98,7 @@ abstract class WindowController with ChangeNotifier {
98
98
}
99
99
100
100
_isPendingDestroy = true ;
101
- return destroyWindow (view.viewId);
101
+ return _destroyWindow (view.viewId);
102
102
}
103
103
}
104
104
@@ -126,7 +126,7 @@ class RegularWindowController extends WindowController {
126
126
}) : super ._(
127
127
onDestroyed: onDestroyed,
128
128
onError: onError,
129
- future: createRegular (
129
+ future: _createRegular (
130
130
size: size,
131
131
sizeConstraints: sizeConstraints,
132
132
title: title,
@@ -165,55 +165,56 @@ class _RegularWindowState extends State<RegularWindow> {
165
165
Future <void > dispose () async {
166
166
super .dispose ();
167
167
168
- // In the event that we're being disposed before we've been destroyed
169
- // we need to destroy the window on our way out.
170
- if (widget.controller.isReady) {
168
+ if (widget.controller.isReady && ! widget.controller._isPendingDestroy) {
171
169
await widget.controller.destroy ();
172
170
}
173
171
}
174
172
175
173
@override
176
174
Widget build (BuildContext context) {
177
- return FutureBuilder <WindowCreationResult >(
175
+ return FutureBuilder <_WindowCreationResult >(
178
176
key: widget.key,
179
177
future: widget.controller._future,
180
- builder: (BuildContext context, AsyncSnapshot <WindowCreationResult > metadata) {
178
+ builder: (BuildContext context, AsyncSnapshot <_WindowCreationResult > metadata) {
181
179
if (! metadata.hasData) {
182
180
return const ViewCollection (views: < Widget > []);
183
181
}
184
182
185
183
return View (
186
184
view: metadata.data! .view,
187
- child: WindowContext (viewId : metadata.data ! .view.viewId , child: widget.child),
185
+ child: WindowControllerContext (controller : widget.controller , child: widget.child),
188
186
);
189
187
},
190
188
);
191
189
}
192
190
}
193
191
194
- /// Provides descendents with access to the [Window] in which they are rendered
195
- class WindowContext extends InheritedWidget {
196
- /// [window] the [Window]
197
- const WindowContext ({super .key, required this .viewId, required super .child});
192
+ /// Provides descendents with access to the [WindowController] in which
193
+ /// they are being rendered
194
+ class WindowControllerContext extends InheritedWidget {
195
+ /// Creates a new [WindowControllerContext]
196
+ /// [controller] the controller associated with this window
197
+ /// [child] the child widget
198
+ const WindowControllerContext ({super .key, required this .controller, required super .child});
198
199
199
- /// The view ID in this context
200
- final int viewId ;
200
+ /// The controller associated with this window.
201
+ final WindowController controller ;
201
202
202
203
/// Returns the [WindowContext] if any
203
- static WindowContext ? of (BuildContext context) {
204
- return context.dependOnInheritedWidgetOfExactType <WindowContext >();
204
+ static WindowControllerContext ? of (BuildContext context) {
205
+ return context.dependOnInheritedWidgetOfExactType <WindowControllerContext >();
205
206
}
206
207
207
208
@override
208
- bool updateShouldNotify (WindowContext oldWidget) {
209
- return viewId != oldWidget.viewId ;
209
+ bool updateShouldNotify (WindowControllerContext oldWidget) {
210
+ return controller != oldWidget.controller ;
210
211
}
211
212
}
212
213
213
214
/// The raw data returned as a result of creating a window.
214
- class WindowCreationResult {
215
+ class _WindowCreationResult {
215
216
/// Creates a new window.
216
- WindowCreationResult ({
217
+ _WindowCreationResult ({
217
218
required this .view,
218
219
required this .archetype,
219
220
required this .size,
@@ -238,15 +239,7 @@ class WindowCreationResult {
238
239
final int ? parent;
239
240
}
240
241
241
- /// Creates a regular window for the platform and returns the metadata associated
242
- /// with the new window. Users should prefer using the [RegularWindow]
243
- /// widget instead of this method.
244
- ///
245
- /// [size] the size of the new [Window] in pixels.
246
- /// [sizeConstraints] the size constraints of the new [Window] .
247
- /// [title] the window title
248
- /// [state] the initial window state
249
- Future <WindowCreationResult > createRegular ({
242
+ Future <_WindowCreationResult > _createRegular ({
250
243
required Size size,
251
244
BoxConstraints ? sizeConstraints,
252
245
String ? title,
@@ -273,7 +266,7 @@ Future<WindowCreationResult> createRegular({
273
266
);
274
267
}
275
268
276
- Future <WindowCreationResult > _createWindow ({
269
+ Future <_WindowCreationResult > _createWindow ({
277
270
required WindowArchetype archetype,
278
271
required Future <Map <Object ?, Object ?>> Function (MethodChannel channel) viewBuilder,
279
272
}) async {
@@ -298,18 +291,15 @@ Future<WindowCreationResult> _createWindow({
298
291
},
299
292
);
300
293
301
- return WindowCreationResult (
294
+ return _WindowCreationResult (
302
295
view: flView,
303
296
archetype: archetype,
304
297
size: Size (size[0 ]! as double , size[1 ]! as double ),
305
298
state: state,
306
299
);
307
300
}
308
301
309
- /// Destroys the window associated with the provided view ID.
310
- ///
311
- /// [viewId] the view id of the window that should be destroyed
312
- Future <void > destroyWindow (int viewId) async {
302
+ Future <void > _destroyWindow (int viewId) async {
313
303
try {
314
304
await SystemChannels .windowing.invokeMethod ('destroyWindow' , < String , dynamic > {
315
305
'viewId' : viewId,
0 commit comments