Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions packages/flutter_adaptive_scaffold/test/adaptive_layout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<SlideTransition>(slideOut('0')).position.value,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<SlideTransition>(slideOut('0')).position.value,
offsetMoreOrLessEquals(const Offset(-0.1, 0), epsilon: 0.05));
expect(tester.widget<SlideTransition>(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);
Expand Down Expand Up @@ -415,10 +415,9 @@ AnimatedWidget leftInOut(Widget child, Animation<double> 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(
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter_adaptive_scaffold/test/breakpoint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter_adaptive_scaffold/test/simulated_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(),
Expand Down