@@ -6,16 +6,23 @@ import 'package:flutter/services.dart';
66import 'package:flutter/widgets.dart' ;
77import 'package:flutter_test/flutter_test.dart' ;
88
9- Future <Object ?>? Function (MethodCall )? _createWindowMethodCallHandler (WidgetTester tester) {
9+ Future <Object ?>? Function (MethodCall )? _createWindowMethodCallHandler ({
10+ required WidgetTester tester,
11+ void Function (MethodCall )? onMethodCall,
12+ }) {
1013 return (MethodCall call) async {
14+ onMethodCall? .call (call);
1115 final Map <Object ?, Object ?> args = call.arguments as Map <Object ?, Object ?>;
1216 if (call.method == 'createWindow' ) {
1317 final List <Object ?> size = args['size' ]! as List <Object ?>;
1418
1519 await tester.binding.defaultBinaryMessenger.handlePlatformMessage (
1620 SystemChannels .windowing.name,
1721 SystemChannels .windowing.codec.encodeMethodCall (
18- MethodCall ('onWindowCreated' , < String , Object ? > {'viewId' : tester.view.viewId, 'parentViewId' : null }),
22+ MethodCall ('onWindowCreated' , < String , Object ? > {
23+ 'viewId' : tester.view.viewId,
24+ 'parentViewId' : null ,
25+ }),
1926 ),
2027 (ByteData ? data) {},
2128 );
@@ -26,11 +33,32 @@ Future<Object?>? Function(MethodCall)? _createWindowMethodCallHandler(WidgetTest
2633 'size' : size,
2734 'parentViewId' : null ,
2835 };
36+ } else if (call.method == 'createPopup' ) {
37+ final int parent = args['parent' ]! as int ;
38+ final List <Object ?> size = args['size' ]! as List <Object ?>;
39+
40+ await tester.binding.defaultBinaryMessenger.handlePlatformMessage (
41+ SystemChannels .windowing.name,
42+ SystemChannels .windowing.codec.encodeMethodCall (
43+ MethodCall ('onWindowCreated' , < String , Object ? > {
44+ 'viewId' : tester.view.viewId,
45+ 'parentViewId' : parent,
46+ }),
47+ ),
48+ (ByteData ? data) {},
49+ );
50+
51+ return < String , Object ? > {
52+ 'viewId' : tester.view.viewId,
53+ 'archetype' : WindowArchetype .regular.index,
54+ 'size' : size,
55+ 'parentViewId' : parent,
56+ };
2957 } else if (call.method == 'destroyWindow' ) {
3058 await tester.binding.defaultBinaryMessenger.handlePlatformMessage (
3159 SystemChannels .windowing.name,
3260 SystemChannels .windowing.codec.encodeMethodCall (
33- MethodCall ('onWindowDestroyed' , < String , Object ? > {'viewId' : tester.view.viewId}),
61+ MethodCall ('onWindowDestroyed' , < String , Object ? > {'viewId' : tester.view.viewId}),
3462 ),
3563 (ByteData ? data) {},
3664 );
@@ -50,7 +78,7 @@ void main() {
5078
5179 tester.binding.defaultBinaryMessenger.setMockMethodCallHandler (
5280 SystemChannels .windowing,
53- _createWindowMethodCallHandler (tester),
81+ _createWindowMethodCallHandler (tester: tester ),
5482 );
5583
5684 final RegularWindowController controller = RegularWindowController ();
@@ -123,7 +151,7 @@ void main() {
123151
124152 tester.binding.defaultBinaryMessenger.setMockMethodCallHandler (
125153 SystemChannels .windowing,
126- _createWindowMethodCallHandler (tester),
154+ _createWindowMethodCallHandler (tester: tester ),
127155 );
128156
129157 bool destroyed = false ;
@@ -163,7 +191,7 @@ void main() {
163191
164192 tester.binding.defaultBinaryMessenger.setMockMethodCallHandler (
165193 SystemChannels .windowing,
166- _createWindowMethodCallHandler (tester),
194+ _createWindowMethodCallHandler (tester: tester ),
167195 );
168196
169197 final RegularWindowController controller = RegularWindowController ();
@@ -189,7 +217,7 @@ void main() {
189217 await tester.binding.defaultBinaryMessenger.handlePlatformMessage (
190218 SystemChannels .windowing.name,
191219 SystemChannels .windowing.codec.encodeMethodCall (
192- MethodCall ('onWindowChanged' , < String , Object ? > {
220+ MethodCall ('onWindowChanged' , < String , Object ? > {
193221 'viewId' : tester.view.viewId,
194222 'size' : < int > [newSize.width.toInt (), newSize.height.toInt ()],
195223 }),
@@ -201,4 +229,171 @@ void main() {
201229 expect (controller.size, newSize);
202230 },
203231 );
232+
233+ testWidgets ('PopupWindow widget populates the controller with proper values' , (
234+ WidgetTester tester,
235+ ) async {
236+ const Size windowSize = Size (800 , 600 );
237+ const Size childWindow = Size (400 , 300 );
238+
239+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler (
240+ SystemChannels .windowing,
241+ _createWindowMethodCallHandler (tester: tester),
242+ );
243+
244+ final PopupWindowController controller = PopupWindowController ();
245+ await tester.pumpWidget (
246+ wrapWithView: false ,
247+ Builder (
248+ builder: (BuildContext context) {
249+ return WindowingApp (
250+ children: < Widget > [
251+ RegularWindow (
252+ preferredSize: windowSize,
253+ child: ViewAnchor (
254+ view: PopupWindow (
255+ controller: controller,
256+ preferredSize: childWindow,
257+ child: Container (),
258+ ),
259+ child: Container (),
260+ ),
261+ ),
262+ ],
263+ );
264+ },
265+ ),
266+ );
267+
268+ await tester.pump ();
269+
270+ expect (controller.type, WindowArchetype .popup);
271+ expect (controller.size, childWindow);
272+ expect (controller.view! .viewId, tester.view.viewId);
273+ expect (controller.parentViewId, tester.view.viewId);
274+ });
275+
276+ testWidgets ('PopupWindow widget can specify anchorRect' , (WidgetTester tester) async {
277+ const Size windowSize = Size (800 , 600 );
278+ const Size childWindow = Size (400 , 300 );
279+
280+ bool called = false ;
281+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler (
282+ SystemChannels .windowing,
283+ _createWindowMethodCallHandler (
284+ tester: tester,
285+ onMethodCall: (MethodCall call) {
286+ final Map <Object ?, Object ?> args = call.arguments as Map <Object ?, Object ?>;
287+ if (call.method == 'createPopup' ) {
288+ final List <Object ?>? anchorRect = args['anchorRect' ] as List <Object ?>? ;
289+ expect (anchorRect, < Object ? > [0 , 0 , 100 , 100 ]);
290+ called = true ;
291+ }
292+ },
293+ ),
294+ );
295+
296+ final PopupWindowController controller = PopupWindowController ();
297+ await tester.pumpWidget (
298+ wrapWithView: false ,
299+ Builder (
300+ builder: (BuildContext context) {
301+ return WindowingApp (
302+ children: < Widget > [
303+ RegularWindow (
304+ preferredSize: windowSize,
305+ child: ViewAnchor (
306+ view: PopupWindow (
307+ controller: controller,
308+ preferredSize: childWindow,
309+ anchorRect: const Rect .fromLTWH (0 , 0 , 100 , 100 ),
310+ child: Container (),
311+ ),
312+ child: Container (),
313+ ),
314+ ),
315+ ],
316+ );
317+ },
318+ ),
319+ );
320+
321+ await tester.pump ();
322+
323+ expect (called, true );
324+ });
325+
326+ testWidgets ('PopupWindow widget can specify positioner' , (WidgetTester tester) async {
327+ const Size windowSize = Size (800 , 600 );
328+ const Size childWindow = Size (400 , 300 );
329+ const Set <WindowPositionerConstraintAdjustment > constraintAdjustment =
330+ < WindowPositionerConstraintAdjustment > {
331+ WindowPositionerConstraintAdjustment .flipX,
332+ WindowPositionerConstraintAdjustment .resizeX,
333+ };
334+
335+ bool called = false ;
336+ tester.binding.defaultBinaryMessenger.setMockMethodCallHandler (
337+ SystemChannels .windowing,
338+ _createWindowMethodCallHandler (
339+ tester: tester,
340+ onMethodCall: (MethodCall call) {
341+ final Map <Object ?, Object ?> args = call.arguments as Map <Object ?, Object ?>;
342+ if (call.method == 'createPopup' ) {
343+ final int positionerParentAnchor = args['positionerParentAnchor' ]! as int ;
344+ final int positionerChildAnchor = args['positionerChildAnchor' ]! as int ;
345+ final List <Object ?> positionerOffset = args['positionerOffset' ]! as List <Object ?>;
346+
347+ final int positionerConstraintAdjustment =
348+ args['positionerConstraintAdjustment' ]! as int ;
349+
350+ expect (positionerParentAnchor, WindowPositionerAnchor .left.index);
351+ expect (positionerChildAnchor, WindowPositionerAnchor .left.index);
352+ expect (positionerOffset, < Object ? > [100 , 100 ]);
353+
354+ int constraintAdjustmentBitmask = 0 ;
355+ for (final WindowPositionerConstraintAdjustment adjustment in constraintAdjustment) {
356+ constraintAdjustmentBitmask | = 1 << adjustment.index;
357+ }
358+ expect (positionerConstraintAdjustment, constraintAdjustmentBitmask);
359+ called = true ;
360+ }
361+ },
362+ ),
363+ );
364+
365+ final PopupWindowController controller = PopupWindowController ();
366+ await tester.pumpWidget (
367+ wrapWithView: false ,
368+ Builder (
369+ builder: (BuildContext context) {
370+ return WindowingApp (
371+ children: < Widget > [
372+ RegularWindow (
373+ preferredSize: windowSize,
374+ child: ViewAnchor (
375+ view: PopupWindow (
376+ controller: controller,
377+ preferredSize: childWindow,
378+ positioner: const WindowPositioner (
379+ parentAnchor: WindowPositionerAnchor .left,
380+ childAnchor: WindowPositionerAnchor .left,
381+ offset: Offset (100 , 100 ),
382+ constraintAdjustment: constraintAdjustment,
383+ ),
384+ child: Container (),
385+ ),
386+ child: Container (),
387+ ),
388+ ),
389+ ],
390+ );
391+ },
392+ ),
393+ );
394+
395+ await tester.pump ();
396+
397+ expect (called, true );
398+ });
204399}
0 commit comments