|
| 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/dismissible/dismissible.0.dart' |
| 7 | + as example; |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + Future<void> dismissHorizontally({ |
| 12 | + required WidgetTester tester, |
| 13 | + required Finder finder, |
| 14 | + required AxisDirection direction, |
| 15 | + }) async { |
| 16 | + final double width = (tester.renderObject(finder) as RenderBox).size.width; |
| 17 | + final double dx = width * 0.8; |
| 18 | + |
| 19 | + final Offset offset = switch (direction) { |
| 20 | + AxisDirection.left => Offset(-dx, 0.0), |
| 21 | + AxisDirection.right => Offset(dx, 0.0), |
| 22 | + _ => throw ArgumentError('$direction is not supported'), |
| 23 | + }; |
| 24 | + |
| 25 | + await tester.drag(finder, offset); |
| 26 | + } |
| 27 | + |
| 28 | + testWidgets( |
| 29 | + 'ListTiles can be dismissed from right to left', |
| 30 | + (WidgetTester tester) async { |
| 31 | + await tester.pumpWidget( |
| 32 | + const example.DismissibleExampleApp(), |
| 33 | + ); |
| 34 | + |
| 35 | + for (final int index in <int>[0, 33, 66, 99]) { |
| 36 | + final ValueKey<int> key = ValueKey<int>(index); |
| 37 | + |
| 38 | + await tester.scrollUntilVisible(find.byKey(key), 100); |
| 39 | + |
| 40 | + expect(find.byKey(key), findsOneWidget); |
| 41 | + |
| 42 | + await dismissHorizontally( |
| 43 | + tester: tester, |
| 44 | + finder: find.byKey(key), |
| 45 | + direction: AxisDirection.left, |
| 46 | + ); |
| 47 | + |
| 48 | + await tester.pumpAndSettle(); |
| 49 | + |
| 50 | + expect(find.byKey(key), findsNothing); |
| 51 | + } |
| 52 | + }, |
| 53 | + ); |
| 54 | + |
| 55 | + testWidgets( |
| 56 | + 'ListTiles can be dismissed from left to right', |
| 57 | + (WidgetTester tester) async { |
| 58 | + await tester.pumpWidget( |
| 59 | + const example.DismissibleExampleApp(), |
| 60 | + ); |
| 61 | + |
| 62 | + for (final int index in <int>[0, 33, 66, 99]) { |
| 63 | + final ValueKey<int> key = ValueKey<int>(index); |
| 64 | + |
| 65 | + await tester.scrollUntilVisible(find.byKey(key), 100); |
| 66 | + |
| 67 | + expect(find.byKey(key), findsOneWidget); |
| 68 | + |
| 69 | + await dismissHorizontally( |
| 70 | + tester: tester, |
| 71 | + finder: find.byKey(key), |
| 72 | + direction: AxisDirection.right, |
| 73 | + ); |
| 74 | + |
| 75 | + await tester.pumpAndSettle(); |
| 76 | + |
| 77 | + expect(find.byKey(key), findsNothing); |
| 78 | + } |
| 79 | + }, |
| 80 | + ); |
| 81 | +} |
0 commit comments