1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | import 'package:flutter/material.dart'; |
6 | import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.2.dart' |
7 | as example; |
8 | import 'package:flutter_test/flutter_test.dart'; |
9 | |
10 | void main() { |
11 | testWidgets('Modal bottom sheet animation can be customized using AnimationStyle' , ( |
12 | WidgetTester tester, |
13 | ) async { |
14 | await tester.pumpWidget(const example.ModalBottomSheetApp()); |
15 | |
16 | // Show the bottom sheet with default animation style. |
17 | await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet' )); |
18 | await tester.pump(); |
19 | // Advance the animation by 1/2 of the default forward duration. |
20 | await tester.pump(const Duration(milliseconds: 125)); |
21 | |
22 | // The bottom sheet is partially visible. |
23 | expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(316.7, 0.1)); |
24 | |
25 | // Advance the animation by 1/2 of the default forward duration. |
26 | await tester.pump(const Duration(milliseconds: 125)); |
27 | |
28 | // The bottom sheet is fully visible. |
29 | expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(262.5)); |
30 | |
31 | // Dismiss the bottom sheet. |
32 | await tester.tap(find.widgetWithText(ElevatedButton, 'Close' )); |
33 | await tester.pumpAndSettle(); |
34 | |
35 | // Select custom animation style. |
36 | await tester.tap(find.text('Custom' )); |
37 | await tester.pumpAndSettle(); |
38 | |
39 | // Show the bottom sheet with custom animation style. |
40 | await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet' )); |
41 | await tester.pump(); |
42 | // Advance the animation by 1/2 of the custom forward duration. |
43 | await tester.pump(const Duration(milliseconds: 1500)); |
44 | |
45 | // The bottom sheet is partially visible. |
46 | expect(tester.getTopLeft(find.byType(BottomSheet)).dy, closeTo(316.7, 0.1)); |
47 | |
48 | // Advance the animation by 1/2 of the custom forward duration. |
49 | await tester.pump(const Duration(milliseconds: 1500)); |
50 | |
51 | // The bottom sheet is fully visible. |
52 | expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(262.5)); |
53 | |
54 | // Dismiss the bottom sheet. |
55 | await tester.tap(find.widgetWithText(ElevatedButton, 'Close' )); |
56 | await tester.pumpAndSettle(); |
57 | |
58 | // Select no animation style. |
59 | await tester.tap(find.text('None' )); |
60 | await tester.pumpAndSettle(); |
61 | |
62 | // Show the bottom sheet with no animation style. |
63 | await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet' )); |
64 | await tester.pump(); |
65 | expect(tester.getTopLeft(find.byType(BottomSheet)).dy, equals(262.5)); |
66 | }); |
67 | } |
68 | |