diff --git a/packages/flutter_adaptive_scaffold/test/adaptive_layout_test.dart b/packages/flutter_adaptive_scaffold/test/adaptive_layout_test.dart index add379423f0..5924f0a8a74 100644 --- a/packages/flutter_adaptive_scaffold/test/adaptive_layout_test.dart +++ b/packages/flutter_adaptive_scaffold/test/adaptive_layout_test.dart @@ -14,7 +14,7 @@ void main() { (WidgetTester tester) async { MediaQuery slot(double width) { return MediaQuery( - data: MediaQueryData.fromWindow(WidgetsBinding.instance.window) + data: MediaQueryData.fromView(tester.view) .copyWith(size: Size(width, 800)), child: Directionality( textDirection: TextDirection.ltr, @@ -120,11 +120,11 @@ void main() { testWidgets( 'slot layout properly switches between items with the appropriate animation', (WidgetTester tester) async { - await tester.pumpWidget(slot(300)); + await tester.pumpWidget(slot(300, tester)); expect(begin, findsOneWidget); expect(end, findsNothing); - await tester.pumpWidget(slot(500)); + await tester.pumpWidget(slot(500, tester)); await tester.pump(); await tester.pump(const Duration(milliseconds: 500)); expect(tester.widget(slideOut('0')).position.value, @@ -146,7 +146,7 @@ void main() { testWidgets('AnimatedSwitcher does not spawn duplicate keys on rapid resize', (WidgetTester tester) async { // Populate the smaller slot layout and let the animation settle. - await tester.pumpWidget(slot(300)); + await tester.pumpWidget(slot(300, tester)); await tester.pumpAndSettle(); expect(begin, findsOneWidget); expect(end, findsNothing); @@ -157,12 +157,12 @@ void main() { for (int i = 0; i < 2; i++) { // Resize between the two slot layouts, but do not pump the animation // until completion. - await tester.pumpWidget(slot(500)); + await tester.pumpWidget(slot(500, tester)); await tester.pump(const Duration(milliseconds: 100)); expect(begin, findsOneWidget); expect(end, findsOneWidget); - await tester.pumpWidget(slot(300)); + await tester.pumpWidget(slot(300, tester)); await tester.pump(const Duration(milliseconds: 100)); expect(begin, findsOneWidget); expect(end, findsOneWidget); @@ -171,18 +171,18 @@ void main() { testWidgets('slot layout can tolerate rapid changes in breakpoints', (WidgetTester tester) async { - await tester.pumpWidget(slot(300)); + await tester.pumpWidget(slot(300, tester)); expect(begin, findsOneWidget); expect(end, findsNothing); - await tester.pumpWidget(slot(500)); + await tester.pumpWidget(slot(500, tester)); await tester.pump(); await tester.pump(const Duration(milliseconds: 100)); expect(tester.widget(slideOut('0')).position.value, offsetMoreOrLessEquals(const Offset(-0.1, 0), epsilon: 0.05)); expect(tester.widget(slideIn('400')).position.value, offsetMoreOrLessEquals(const Offset(-0.9, 0), epsilon: 0.05)); - await tester.pumpWidget(slot(300)); + await tester.pumpWidget(slot(300, tester)); await tester.pumpAndSettle(); expect(begin, findsOneWidget); expect(end, findsNothing); @@ -415,10 +415,9 @@ AnimatedWidget leftInOut(Widget child, Animation animation) { ); } -MediaQuery slot(double width) { +MediaQuery slot(double width, WidgetTester tester) { return MediaQuery( - data: MediaQueryData.fromWindow(WidgetsBinding.instance.window) - .copyWith(size: Size(width, 800)), + data: MediaQueryData.fromView(tester.view).copyWith(size: Size(width, 800)), child: Directionality( textDirection: TextDirection.ltr, child: SlotLayout( diff --git a/packages/flutter_adaptive_scaffold/test/breakpoint_test.dart b/packages/flutter_adaptive_scaffold/test/breakpoint_test.dart index 9eada7dc9f2..6ecb20a2701 100644 --- a/packages/flutter_adaptive_scaffold/test/breakpoint_test.dart +++ b/packages/flutter_adaptive_scaffold/test/breakpoint_test.dart @@ -12,19 +12,19 @@ void main() { (WidgetTester tester) async { // Pump a small layout on a mobile device. The small slot // should give the mobile slot layout, not the desktop layout. - await tester.pumpWidget(SimulatedLayout.small.slot); + await tester.pumpWidget(SimulatedLayout.small.slot(tester)); await tester.pumpAndSettle(); expect(find.byKey(const Key('Breakpoints.smallMobile')), findsOneWidget); expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsNothing); // Do the same with a medium layout on a mobile - await tester.pumpWidget(SimulatedLayout.medium.slot); + await tester.pumpWidget(SimulatedLayout.medium.slot(tester)); await tester.pumpAndSettle(); expect(find.byKey(const Key('Breakpoints.mediumMobile')), findsOneWidget); expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsNothing); // Large layout on mobile - await tester.pumpWidget(SimulatedLayout.large.slot); + await tester.pumpWidget(SimulatedLayout.large.slot(tester)); await tester.pumpAndSettle(); expect(find.byKey(const Key('Breakpoints.largeMobile')), findsOneWidget); expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsNothing); @@ -34,19 +34,19 @@ void main() { (WidgetTester tester) async { // Pump a small layout on a desktop device. The small slot // should give the mobile slot layout, not the desktop layout. - await tester.pumpWidget(SimulatedLayout.small.slot); + await tester.pumpWidget(SimulatedLayout.small.slot(tester)); await tester.pumpAndSettle(); expect(find.byKey(const Key('Breakpoints.smallDesktop')), findsOneWidget); expect(find.byKey(const Key('Breakpoints.smallMobile')), findsNothing); // Do the same with a medium layout on a desktop - await tester.pumpWidget(SimulatedLayout.medium.slot); + await tester.pumpWidget(SimulatedLayout.medium.slot(tester)); await tester.pumpAndSettle(); expect(find.byKey(const Key('Breakpoints.mediumDesktop')), findsOneWidget); expect(find.byKey(const Key('Breakpoints.mediumMobile')), findsNothing); // Large layout on desktop - await tester.pumpWidget(SimulatedLayout.large.slot); + await tester.pumpWidget(SimulatedLayout.large.slot(tester)); await tester.pumpAndSettle(); expect(find.byKey(const Key('Breakpoints.largeDesktop')), findsOneWidget); expect(find.byKey(const Key('Breakpoints.largeMobile')), findsNothing); diff --git a/packages/flutter_adaptive_scaffold/test/simulated_layout.dart b/packages/flutter_adaptive_scaffold/test/simulated_layout.dart index 17d84e935a4..706883d997d 100644 --- a/packages/flutter_adaptive_scaffold/test/simulated_layout.dart +++ b/packages/flutter_adaptive_scaffold/test/simulated_layout.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart'; +import 'package:flutter_test/flutter_test.dart'; import 'test_breakpoints.dart'; @@ -149,9 +150,9 @@ enum SimulatedLayout { ); } - MediaQuery get slot { + MediaQuery slot(WidgetTester tester) { return MediaQuery( - data: MediaQueryData.fromWindow(WidgetsBinding.instance.window) + data: MediaQueryData.fromView(tester.view) .copyWith(size: Size(_width, _height)), child: Theme( data: ThemeData(),