Add AnimationStyle to showBottomSheet and showModalBottomSheet (#145536)

fixes [Introduce animation customizable with `AnimationStyle` to `BottomSheet`](https://github.com/flutter/flutter/issues/145532)

### Default bottom sheet animation
![00-ezgif com-video-to-gif-converter](https://github.com/flutter/flutter/assets/48603081/a295b002-b310-4dea-8bc4-23b1d299748c)

### Custom bottom sheet animation
![01-ezgif com-video-to-gif-converter](https://github.com/flutter/flutter/assets/48603081/8c5c3d5f-e67d-4ed5-880d-f17d262087e1)

### No bottom sheet animation
![02-ezgif com-video-to-gif-converter](https://github.com/flutter/flutter/assets/48603081/872409d8-8a8d-4db9-b95b-7f96a62cdffc)
This commit is contained in:
Taha Tesser
2024-03-25 10:39:05 +02:00
committed by GitHub
parent 62adaff870
commit 23687c5260
12 changed files with 1007 additions and 6 deletions

View File

@@ -0,0 +1,66 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_sheet/show_bottom_sheet.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Bottom sheet animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomSheetExampleApp(),
);
// Show the bottom sheet with default animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));
await tester.pump();
// Advance the animation by 1/2 of the default forward duration.
await tester.pump(const Duration(milliseconds: 125));
// The bottom sheet is partially visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(178.0, 0.1));
// Advance the animation by 1/2 of the default forward duration.
await tester.pump(const Duration(milliseconds: 125));
// The bottom sheet is fully visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(56.0));
// Dismiss the bottom sheet.
await tester.tap(find.widgetWithText(ElevatedButton, 'Close'));
await tester.pumpAndSettle();
// Select custom animation style.
await tester.tap(find.text('Custom'));
await tester.pumpAndSettle();
// Show the bottom sheet with custom animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));
await tester.pump();
// Advance the animation by 1/2 of the custom forward duration.
await tester.pump(const Duration(milliseconds: 1500));
// The bottom sheet is partially visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(178.0, 0.1));
// Advance the animation by 1/2 of the custom forward duration.
await tester.pump(const Duration(milliseconds: 1500));
// The bottom sheet is fully visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(56.0));
// Dismiss the bottom sheet.
await tester.tap(find.widgetWithText(ElevatedButton, 'Close'));
await tester.pumpAndSettle();
// Select no animation style.
await tester.tap(find.text('None'));
await tester.pumpAndSettle();
// Show the bottom sheet with no animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));
await tester.pump();
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(56.0));
});
}

View File

@@ -0,0 +1,66 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Modal bottom sheet animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ModalBottomSheetApp(),
);
// Show the bottom sheet with default animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet'));
await tester.pump();
// Advance the animation by 1/2 of the default forward duration.
await tester.pump(const Duration(milliseconds: 125));
// The bottom sheet is partially visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(316.7, 0.1));
// Advance the animation by 1/2 of the default forward duration.
await tester.pump(const Duration(milliseconds: 125));
// The bottom sheet is fully visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(262.5));
// Dismiss the bottom sheet.
await tester.tap(find.widgetWithText(ElevatedButton, 'Close'));
await tester.pumpAndSettle();
// Select custom animation style.
await tester.tap(find.text('Custom'));
await tester.pumpAndSettle();
// Show the bottom sheet with custom animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet'));
await tester.pump();
// Advance the animation by 1/2 of the custom forward duration.
await tester.pump(const Duration(milliseconds: 1500));
// The bottom sheet is partially visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(316.7, 0.1));
// Advance the animation by 1/2 of the custom forward duration.
await tester.pump(const Duration(milliseconds: 1500));
// The bottom sheet is fully visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(262.5));
// Dismiss the bottom sheet.
await tester.tap(find.widgetWithText(ElevatedButton, 'Close'));
await tester.pumpAndSettle();
// Select no animation style.
await tester.tap(find.text('None'));
await tester.pumpAndSettle();
// Show the bottom sheet with no animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet'));
await tester.pump();
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(262.5));
});
}

View File

@@ -0,0 +1,66 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/scaffold/scaffold_state.show_bottom_sheet.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Scaffold showBottomSheet animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ShowBottomSheetExampleApp(),
);
// Show the bottom sheet with default animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));
await tester.pump();
// Advance the animation by 1/2 of the default forward duration.
await tester.pump(const Duration(milliseconds: 125));
// The bottom sheet is partially visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(444.8, 0.1));
// Advance the animation by 1/2 of the default forward duration.
await tester.pump(const Duration(milliseconds: 125));
// The bottom sheet is fully visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(400.0));
// Dismiss the bottom sheet.
await tester.tap(find.widgetWithText(ElevatedButton, 'Close'));
await tester.pumpAndSettle();
// Select custom animation style.
await tester.tap(find.text('Custom'));
await tester.pumpAndSettle();
// Show the bottom sheet with custom animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));
await tester.pump();
// Advance the animation by 1/2 of the custom forward duration.
await tester.pump(const Duration(milliseconds: 1500));
// The bottom sheet is partially visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(444.8, 0.1));
// Advance the animation by 1/2 of the custom forward duration.
await tester.pump(const Duration(milliseconds: 1500));
// The bottom sheet is fully visible.
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(400.0));
// Dismiss the bottom sheet.
await tester.tap(find.widgetWithText(ElevatedButton, 'Close'));
await tester.pumpAndSettle();
// Select no animation style.
await tester.tap(find.text('None'));
await tester.pumpAndSettle();
// Show the bottom sheet with no animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));
await tester.pump();
expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(400.0));
});
}