5
5
import 'dart:ui' show FlutterView;
6
6
7
7
import 'package:flutter/material.dart' ;
8
+ import 'package:flutter/scheduler.dart' ;
8
9
import 'package:flutter/services.dart' ;
9
10
10
11
/// Defines the type of a [Window]
@@ -81,27 +82,34 @@ class _RegularWindowState extends State<RegularWindow> {
81
82
@override
82
83
void initState () {
83
84
super .initState ();
84
- final _WindowingAppContext ? windowingAppContext =
85
- _WindowingAppContext .of (context);
86
85
widget._future.then ((RegularWindowMetadata metadata) async {
87
- assert (windowingAppContext != null );
88
- _listener = _WindowListener (
89
- viewId: metadata.view.viewId,
90
- onChanged: (_WindowChangeProperties properties) {
91
- if (widget.controller == null ) {
92
- return ;
93
- }
94
-
95
- if (properties.size != null ) {
96
- widget.controller! ._size = properties.size! ;
97
- }
98
-
99
- if (properties.parentViewId != null ) {
100
- widget.controller! ._parentViewId = properties.parentViewId;
101
- }
102
- },
103
- onDestroyed: widget.onDestroyed);
104
- windowingAppContext! .windowingApp._registerListener (_listener! );
86
+ if (widget.controller != null ) {
87
+ widget.controller! ._parentViewId = metadata.parentViewId;
88
+ widget.controller! ._size = metadata.size;
89
+ }
90
+
91
+ SchedulerBinding .instance.addPostFrameCallback ((_) async {
92
+ final _WindowingAppContext ? windowingAppContext =
93
+ _WindowingAppContext .of (context);
94
+ assert (windowingAppContext != null );
95
+ _listener = _WindowListener (
96
+ viewId: metadata.view.viewId,
97
+ onChanged: (_WindowChangeProperties properties) {
98
+ if (widget.controller == null ) {
99
+ return ;
100
+ }
101
+
102
+ if (properties.size != null ) {
103
+ widget.controller! ._size = properties.size! ;
104
+ }
105
+
106
+ if (properties.parentViewId != null ) {
107
+ widget.controller! ._parentViewId = properties.parentViewId;
108
+ }
109
+ },
110
+ onDestroyed: widget.onDestroyed);
111
+ windowingAppContext! .windowingApp._registerListener (_listener! );
112
+ });
105
113
});
106
114
}
107
115
@@ -123,7 +131,8 @@ class _RegularWindowState extends State<RegularWindow> {
123
131
builder: (BuildContext context,
124
132
AsyncSnapshot <RegularWindowMetadata > metadata) {
125
133
if (! metadata.hasData) {
126
- return Container ();
134
+ final WidgetsBinding binding = WidgetsFlutterBinding .ensureInitialized ();
135
+ return binding.wrapWithDefaultView (Container ());
127
136
}
128
137
129
138
return View (
@@ -202,6 +211,7 @@ Future<RegularWindowMetadata> createRegular({required Size size}) async {
202
211
Future <_WindowMetadata > _createWindow (
203
212
{required Future <Map <Object ?, Object ?>> Function (MethodChannel channel)
204
213
viewBuilder}) async {
214
+ WidgetsFlutterBinding .ensureInitialized ();
205
215
final Map <Object ?, Object ?> creationData =
206
216
await viewBuilder (SystemChannels .windowing);
207
217
final int viewId = creationData['viewId' ]! as int ;
@@ -260,6 +270,7 @@ class _WindowListener {
260
270
/// The current [Window] can be looked up with [WindowContext.of] .
261
271
class WindowingApp extends StatelessWidget {
262
272
WindowingApp ({super .key, required this .children}) {
273
+ WidgetsFlutterBinding .ensureInitialized ();
263
274
SystemChannels .windowing.setMethodCallHandler (_methodCallHandler);
264
275
}
265
276
0 commit comments