list_view_vertical_test.dart 3.45 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Hixie's avatar
Hixie committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

Adam Barth's avatar
Adam Barth committed
7
import 'package:flutter_test/flutter_test.dart';
8
import 'package:flutter/widgets.dart';
9

10
const List<int> items = <int>[0, 1, 2, 3, 4, 5];
11 12

Widget buildFrame() {
13
  return Directionality(
14
    textDirection: TextDirection.ltr,
15
    child: ListView(
16 17
      itemExtent: 290.0,
      scrollDirection: Axis.vertical,
18
      children: items.map<Widget>((int item) {
19
        return Container(
20
          child: Text('$item'),
21 22 23
        );
      }).toList(),
    ),
24 25 26 27
  );
}

void main() {
28 29
  testWidgets('Drag vertically', (WidgetTester tester) async {
    await tester.pumpWidget(buildFrame());
30

31
    await tester.pump();
32
    await tester.drag(find.text('1'), const Offset(0.0, -300.0));
33
    await tester.pump();
34 35 36 37 38 39 40 41 42 43
    // screen is 600px high, and has the following items:
    //   -10..280 = 1
    //   280..570 = 2
    //   570..860 = 3
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsOneWidget);
    expect(find.text('2'), findsOneWidget);
    expect(find.text('3'), findsOneWidget);
    expect(find.text('4'), findsNothing);
    expect(find.text('5'), findsNothing);
44

45
    await tester.pump();
46
    await tester.drag(find.text('2'), const Offset(0.0, -290.0));
47
    await tester.pump();
48 49 50 51 52 53 54 55 56 57
    // screen is 600px high, and has the following items:
    //   -10..280 = 2
    //   280..570 = 3
    //   570..860 = 4
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsNothing);
    expect(find.text('2'), findsOneWidget);
    expect(find.text('3'), findsOneWidget);
    expect(find.text('4'), findsOneWidget);
    expect(find.text('5'), findsNothing);
58

59
    await tester.pump();
60
    await tester.drag(find.text('3'), const Offset(-300.0, 0.0));
61
    await tester.pump();
62 63 64 65 66 67 68
    // nothing should have changed
    expect(find.text('0'), findsNothing);
    expect(find.text('1'), findsNothing);
    expect(find.text('2'), findsOneWidget);
    expect(find.text('3'), findsOneWidget);
    expect(find.text('4'), findsOneWidget);
    expect(find.text('5'), findsNothing);
69
  });
70

71 72
  testWidgets('Drag vertically', (WidgetTester tester) async {
    await tester.pumpWidget(
73
      Directionality(
74
        textDirection: TextDirection.ltr,
75
        child: ListView(
76 77 78
          itemExtent: 290.0,
          padding: const EdgeInsets.only(top: 250.0),
          scrollDirection: Axis.vertical,
79
          children: items.map<Widget>((int item) {
80
            return Container(
81
              child: Text('$item'),
82 83 84
            );
          }).toList(),
        ),
85
      ),
86
    );
87

88
    await tester.pump();
89 90 91 92 93 94 95 96 97
    // screen is 600px high, and has the following items:
    //   250..540 = 0
    //   540..830 = 1
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsOneWidget);
    expect(find.text('2'), findsNothing);
    expect(find.text('3'), findsNothing);
    expect(find.text('4'), findsNothing);
    expect(find.text('5'), findsNothing);
98

99
    await tester.drag(find.text('0'), const Offset(0.0, -300.0));
100
    await tester.pump();
101 102 103 104 105 106 107 108 109 110
    // screen is 600px high, and has the following items:
    //   -50..240 = 0
    //   240..530 = 1
    //   530..820 = 2
    expect(find.text('0'), findsOneWidget);
    expect(find.text('1'), findsOneWidget);
    expect(find.text('2'), findsOneWidget);
    expect(find.text('3'), findsNothing);
    expect(find.text('4'), findsNothing);
    expect(find.text('5'), findsNothing);
111
  });
112
}