|
| 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/interactive_viewer/interactive_viewer.transformation_controller.0.dart' |
| 7 | + as example; |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + testWidgets('The reset button resets the view with an animation', (WidgetTester tester) async { |
| 12 | + await tester.pumpWidget( |
| 13 | + const example.TransformationControllerExampleApp(), |
| 14 | + ); |
| 15 | + |
| 16 | + expect(find.widgetWithText(AppBar, 'Controller demo'), findsOne); |
| 17 | + expect(find.byType(InteractiveViewer), findsOne); |
| 18 | + |
| 19 | + expect( |
| 20 | + tester.getRect(find.byType(Container).first), |
| 21 | + rectMoreOrLessEquals(const Rect.fromLTRB(0.0, 56.0, 800.0, 535.0)), |
| 22 | + ); |
| 23 | + |
| 24 | + await tester.drag(find.byType(Container).first, const Offset(20, 20)); |
| 25 | + |
| 26 | + // Pans. |
| 27 | + const Offset panStart = Offset(400.0, 300.0); |
| 28 | + final Offset panEnd = panStart + const Offset(20.0, 20.0); |
| 29 | + final TestGesture gesture = await tester.startGesture(panStart); |
| 30 | + await tester.pump(); |
| 31 | + await gesture.moveTo(panEnd); |
| 32 | + await tester.pump(); |
| 33 | + await gesture.up(); |
| 34 | + await tester.pumpAndSettle(); |
| 35 | + |
| 36 | + expect( |
| 37 | + tester.getRect(find.byType(Container).first), |
| 38 | + rectMoreOrLessEquals(const Rect.fromLTRB(40.0, 96.0, 840.0, 575.0)), |
| 39 | + ); |
| 40 | + |
| 41 | + // Zooms. |
| 42 | + const Offset scaleStart1 = Offset(400.0, 300.0); |
| 43 | + final Offset scaleStart2 = scaleStart1 + const Offset(10.0, 0.0); |
| 44 | + final Offset scaleEnd1 = scaleStart1 - const Offset(10.0, 0.0); |
| 45 | + final Offset scaleEnd2 = scaleStart2 + const Offset(10.0, 0.0); |
| 46 | + final TestGesture gesture1 = await tester.createGesture(); |
| 47 | + final TestGesture gesture2 = await tester.createGesture(); |
| 48 | + await gesture1.down(scaleStart1); |
| 49 | + await gesture2.down(scaleStart2); |
| 50 | + await tester.pump(); |
| 51 | + await gesture1.moveTo(scaleEnd1); |
| 52 | + await gesture2.moveTo(scaleEnd2); |
| 53 | + await tester.pump(); |
| 54 | + await gesture1.up(); |
| 55 | + await gesture2.up(); |
| 56 | + await tester.pumpAndSettle(); |
| 57 | + |
| 58 | + expect( |
| 59 | + tester.getRect(find.byType(Container).first), |
| 60 | + rectMoreOrLessEquals(const Rect.fromLTRB(45.0, 96.0, 845.0, 575.0)), |
| 61 | + ); |
| 62 | + |
| 63 | + await tester.tap(find.widgetWithIcon(IconButton, Icons.replay)); |
| 64 | + await tester.pump(); |
| 65 | + await tester.pump(const Duration(milliseconds: 200)); |
| 66 | + |
| 67 | + expect( |
| 68 | + tester.getRect(find.byType(Container).first), |
| 69 | + rectMoreOrLessEquals(const Rect.fromLTRB(22.5, 76.0, 822.5, 555.0)), |
| 70 | + ); |
| 71 | + |
| 72 | + await tester.pump(const Duration(milliseconds: 200)); |
| 73 | + |
| 74 | + expect( |
| 75 | + tester.getRect(find.byType(Container).first), |
| 76 | + rectMoreOrLessEquals(const Rect.fromLTRB(0.0, 56.0, 800.0, 535.0)), |
| 77 | + ); |
| 78 | + }); |
| 79 | +} |
0 commit comments