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/scaffold/scaffold.floating_action_button_animator.0.dart' |
7 | as example; |
8 | import 'package:flutter_test/flutter_test.dart'; |
9 | |
10 | void main() { |
11 | testWidgets('FloatingActionButton animation can be customized' , (WidgetTester tester) async { |
12 | await tester.pumpWidget(const example.ScaffoldFloatingActionButtonAnimatorApp()); |
13 | |
14 | expect(find.byType(FloatingActionButton), findsNothing); |
15 | |
16 | // Test default FloatingActionButtonAnimator. |
17 | // Tap the toggle button to show the FAB. |
18 | await tester.tap(find.text('Toggle FAB' )); |
19 | await tester.pump(); |
20 | await tester.pump(const Duration(milliseconds: 100)); // Advance animation by 100ms. |
21 | // FAB is partially animated in. |
22 | expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, closeTo(743.8, 0.1)); |
23 | |
24 | await tester.pump(const Duration(milliseconds: 100)); // Advance animation by 100ms. |
25 | // FAB is fully animated in. |
26 | expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, equals(728.0)); |
27 | |
28 | // Tap the toggle button to hide the FAB. |
29 | await tester.tap(find.text('Toggle FAB' )); |
30 | await tester.pump(); |
31 | await tester.pump(const Duration(milliseconds: 100)); // Advance animation by 100ms. |
32 | // FAB is partially animated out. |
33 | expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, closeTo(747.1, 0.1)); |
34 | |
35 | await tester.pump(const Duration(milliseconds: 100)); // Advance animation by 100ms. |
36 | // FAB is fully animated out. |
37 | expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, equals(756.0)); |
38 | |
39 | await tester.pump(const Duration(milliseconds: 50)); // Advance animation by 50ms. |
40 | // FAB is hidden. |
41 | expect(find.byType(FloatingActionButton), findsNothing); |
42 | |
43 | // Select 'None' to disable animation. |
44 | await tester.tap(find.text('None' )); |
45 | await tester.pump(); |
46 | |
47 | // Test no animation FloatingActionButtonAnimator. |
48 | await tester.tap(find.text('Toggle FAB' )); |
49 | await tester.pump(); |
50 | // FAB is immediately shown. |
51 | expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, equals(728.0)); |
52 | |
53 | // Tap the toggle button to hide the FAB. |
54 | await tester.tap(find.text('Toggle FAB' )); |
55 | await tester.pump(); |
56 | // FAB is immediately hidden. |
57 | expect(find.byType(FloatingActionButton), findsNothing); |
58 | }); |
59 | } |
60 | |