-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flutter_adaptive_scaffold] Allows for the animation duration to be adjusted using SlotLayout.from() #6510
[flutter_adaptive_scaffold] Allows for the animation duration to be adjusted using SlotLayout.from() #6510
Changes from 5 commits
c8ab2d4
ac390ee
4d7259c
b41dbf1
0d069aa
c1d0f3c
1c4742a
f5da939
d49bb8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, tester)); | ||
await tester.pumpWidget(slot(300, 1000, tester)); | ||
expect(begin, findsOneWidget); | ||
expect(end, findsNothing); | ||
|
||
await tester.pumpWidget(slot(500, tester)); | ||
await tester.pumpWidget(slot(500, 1000, tester)); | ||
await tester.pump(); | ||
await tester.pump(const Duration(milliseconds: 500)); | ||
expect(tester.widget<SlideTransition>(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, tester)); | ||
await tester.pumpWidget(slot(300, 1000, 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, tester)); | ||
await tester.pumpWidget(slot(500, 1000, tester)); | ||
await tester.pump(const Duration(milliseconds: 100)); | ||
expect(begin, findsOneWidget); | ||
expect(end, findsOneWidget); | ||
|
||
await tester.pumpWidget(slot(300, tester)); | ||
await tester.pumpWidget(slot(300, 1000, 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, tester)); | ||
await tester.pumpWidget(slot(300, 1000, tester)); | ||
expect(begin, findsOneWidget); | ||
expect(end, findsNothing); | ||
|
||
await tester.pumpWidget(slot(500, tester)); | ||
await tester.pumpWidget(slot(500, 1000, 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, tester)); | ||
await tester.pumpWidget(slot(300, 1000, tester)); | ||
await tester.pumpAndSettle(); | ||
expect(begin, findsOneWidget); | ||
expect(end, findsNothing); | ||
|
@@ -243,11 +243,33 @@ void main() { | |
tester.getBottomRight(secondaryTestBreakpoint), const Offset(390, 790)); | ||
}); | ||
|
||
testWidgets('adaptive layout can adjust animation duration', | ||
(WidgetTester tester) async { | ||
// Populate the smaller slot layout and let the animation settle. | ||
await tester.pumpWidget(slot(300, 100, tester)); | ||
await tester.pumpAndSettle(); | ||
expect(begin, findsOneWidget); | ||
expect(end, findsNothing); | ||
|
||
// expand in 1/5 second | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format all comments as sentences, with capitalization and punctuation (applies here and below). |
||
await tester.pumpWidget(slot(500, 200, tester)); | ||
|
||
// after 100ms, we expect both widgets to be present | ||
await tester.pump(const Duration(milliseconds: 50)); | ||
expect(begin, findsOneWidget); | ||
expect(end, findsOneWidget); | ||
|
||
// After 1/5 second, all animations should be done | ||
await tester.pump(const Duration(milliseconds: 200)); | ||
expect(begin, findsNothing); | ||
expect(end, findsOneWidget); | ||
|
||
await tester.pumpAndSettle(); | ||
}); | ||
|
||
testWidgets('adaptive layout does not animate when animations off', | ||
(WidgetTester tester) async { | ||
final Finder testBreakpoint = find.byKey(const Key('Test Breakpoint')); | ||
final Finder secondaryTestBreakpoint = | ||
find.byKey(const Key('Secondary Test Breakpoint')); | ||
|
||
await tester.pumpWidget( | ||
await layout(width: 400, tester: tester, animations: false)); | ||
|
@@ -257,9 +279,6 @@ void main() { | |
|
||
expect(tester.getTopLeft(testBreakpoint), const Offset(10, 10)); | ||
expect(tester.getBottomRight(testBreakpoint), const Offset(200, 790)); | ||
expect(tester.getTopLeft(secondaryTestBreakpoint), const Offset(200, 10)); | ||
expect( | ||
tester.getBottomRight(secondaryTestBreakpoint), const Offset(390, 790)); | ||
}); | ||
} | ||
|
||
|
@@ -306,6 +325,7 @@ Future<MediaQuery> layout({ | |
TextDirection directionality = TextDirection.ltr, | ||
double? bodyRatio, | ||
bool animations = true, | ||
int durationMs = 1000, | ||
}) async { | ||
await tester.binding.setSurfaceSize(Size(width, 800)); | ||
return MediaQuery( | ||
|
@@ -415,7 +435,7 @@ AnimatedWidget leftInOut(Widget child, Animation<double> animation) { | |
); | ||
} | ||
|
||
MediaQuery slot(double width, WidgetTester tester) { | ||
MediaQuery slot(double width, int durationMs, WidgetTester tester) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this an int with the type in the name rather than a |
||
return MediaQuery( | ||
data: MediaQueryData.fromView(tester.view).copyWith(size: Size(width, 800)), | ||
child: Directionality( | ||
|
@@ -425,12 +445,14 @@ MediaQuery slot(double width, WidgetTester tester) { | |
TestBreakpoint0(): SlotLayout.from( | ||
inAnimation: leftOutIn, | ||
outAnimation: leftInOut, | ||
duration: Duration(milliseconds: durationMs), | ||
key: const Key('0'), | ||
builder: (_) => const SizedBox(width: 10, height: 10), | ||
), | ||
TestBreakpoint400(): SlotLayout.from( | ||
inAnimation: leftOutIn, | ||
outAnimation: leftInOut, | ||
duration: Duration(milliseconds: durationMs), | ||
key: const Key('400'), | ||
builder: (_) => const SizedBox(width: 10, height: 10), | ||
), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is missing the period at the end.