55import 'dart:ui' show FlutterView;
66
77import 'package:flutter/material.dart' ;
8+ import 'package:flutter/scheduler.dart' ;
89import 'package:flutter/services.dart' ;
910
1011/// Defines the type of a [Window]
@@ -81,27 +82,34 @@ class _RegularWindowState extends State<RegularWindow> {
8182 @override
8283 void initState () {
8384 super .initState ();
84- final _WindowingAppContext ? windowingAppContext =
85- _WindowingAppContext .of (context);
8685 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+ });
105113 });
106114 }
107115
@@ -123,7 +131,8 @@ class _RegularWindowState extends State<RegularWindow> {
123131 builder: (BuildContext context,
124132 AsyncSnapshot <RegularWindowMetadata > metadata) {
125133 if (! metadata.hasData) {
126- return Container ();
134+ final WidgetsBinding binding = WidgetsFlutterBinding .ensureInitialized ();
135+ return binding.wrapWithDefaultView (Container ());
127136 }
128137
129138 return View (
@@ -202,6 +211,7 @@ Future<RegularWindowMetadata> createRegular({required Size size}) async {
202211Future <_WindowMetadata > _createWindow (
203212 {required Future <Map <Object ?, Object ?>> Function (MethodChannel channel)
204213 viewBuilder}) async {
214+ WidgetsFlutterBinding .ensureInitialized ();
205215 final Map <Object ?, Object ?> creationData =
206216 await viewBuilder (SystemChannels .windowing);
207217 final int viewId = creationData['viewId' ]! as int ;
@@ -260,6 +270,7 @@ class _WindowListener {
260270/// The current [Window] can be looked up with [WindowContext.of] .
261271class WindowingApp extends StatelessWidget {
262272 WindowingApp ({super .key, required this .children}) {
273+ WidgetsFlutterBinding .ensureInitialized ();
263274 SystemChannels .windowing.setMethodCallHandler (_methodCallHandler);
264275 }
265276
0 commit comments