|
| 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/widgets/implicit_animations/animated_align.0.dart' |
| 7 | + as example; |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + testWidgets('AnimatedAlign animates on tap', (WidgetTester tester) async { |
| 12 | + await tester.pumpWidget( |
| 13 | + const example.AnimatedAlignExampleApp(), |
| 14 | + ); |
| 15 | + |
| 16 | + final Finder alignFinder = find.descendant( |
| 17 | + of: find.byType(AnimatedAlign), |
| 18 | + matching: find.byType(Align), |
| 19 | + ); |
| 20 | + |
| 21 | + const Alignment beginAlignment = Alignment.bottomLeft; |
| 22 | + const Alignment endAlignment = Alignment.topRight; |
| 23 | + |
| 24 | + Align align = tester.widget(alignFinder); |
| 25 | + expect(align.alignment, beginAlignment); |
| 26 | + |
| 27 | + // Tap on the AnimatedAlignExample to start the forward animation. |
| 28 | + await tester.tap(find.byType(example.AnimatedAlignExample)); |
| 29 | + await tester.pump(); |
| 30 | + |
| 31 | + align = tester.widget(alignFinder); |
| 32 | + expect(align.alignment, beginAlignment); |
| 33 | + |
| 34 | + // Advance animation to the middle. |
| 35 | + await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2); |
| 36 | + |
| 37 | + align = tester.widget(alignFinder); |
| 38 | + expect( |
| 39 | + align.alignment, |
| 40 | + Alignment.lerp( |
| 41 | + beginAlignment, |
| 42 | + endAlignment, |
| 43 | + example.AnimatedAlignExampleApp.curve.transform(0.5), |
| 44 | + ), |
| 45 | + ); |
| 46 | + |
| 47 | + // Advance animation to the end. |
| 48 | + await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2); |
| 49 | + |
| 50 | + align = tester.widget(alignFinder); |
| 51 | + expect(align.alignment, endAlignment); |
| 52 | + |
| 53 | + // Tap on the AnimatedAlignExample again to start the reverse animation. |
| 54 | + await tester.tap(find.byType(example.AnimatedAlignExample)); |
| 55 | + await tester.pump(); |
| 56 | + |
| 57 | + align = tester.widget(alignFinder); |
| 58 | + expect(align.alignment, endAlignment); |
| 59 | + |
| 60 | + // Advance animation to the middle. |
| 61 | + await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2); |
| 62 | + |
| 63 | + align = tester.widget(alignFinder); |
| 64 | + expect( |
| 65 | + align.alignment, |
| 66 | + Alignment.lerp( |
| 67 | + endAlignment, |
| 68 | + beginAlignment, |
| 69 | + example.AnimatedAlignExampleApp.curve.transform(0.5), |
| 70 | + ), |
| 71 | + ); |
| 72 | + |
| 73 | + // Advance animation to the end. |
| 74 | + await tester.pump(example.AnimatedAlignExampleApp.duration ~/ 2); |
| 75 | + |
| 76 | + align = tester.widget(alignFinder); |
| 77 | + expect(align.alignment, beginAlignment); |
| 78 | + }); |
| 79 | +} |
0 commit comments