scrollable_list_vertical_test.dart 2.03 KB
Newer Older
1
import 'package:flutter/widgets.dart';
2 3
import 'package:test/test.dart';

Adam Barth's avatar
Adam Barth committed
4
import 'widget_tester.dart';
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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

Widget buildFrame() {
  return new ScrollableList<int>(
    items: items,
    itemBuilder: (BuildContext context, int item) {
      return new Container(
        key: new ValueKey<int>(item),
        child: new Text('$item')
      );
    },
    itemExtent: 290.0,
    scrollDirection: ScrollDirection.vertical
  );
}

void main() {
23 24 25
  test('Drag vertically', () {
    testWidgets((WidgetTester tester) {
      tester.pumpWidget(buildFrame());
26

27 28 29 30 31 32 33 34 35 36 37 38 39
      tester.pump();
      tester.scroll(tester.findText('1'), const Offset(0.0, -300.0));
      tester.pump();
      // screen is 600px high, and has the following items:
      //   -10..280 = 1
      //   280..570 = 2
      //   570..860 = 3
      expect(tester.findText('0'), isNull);
      expect(tester.findText('1'), isNotNull);
      expect(tester.findText('2'), isNotNull);
      expect(tester.findText('3'), isNotNull);
      expect(tester.findText('4'), isNull);
      expect(tester.findText('5'), isNull);
40

41 42 43 44 45 46 47 48 49 50 51 52 53
      tester.pump();
      tester.scroll(tester.findText('2'), const Offset(0.0, -290.0));
      tester.pump();
      // screen is 600px high, and has the following items:
      //   -10..280 = 2
      //   280..570 = 3
      //   570..860 = 4
      expect(tester.findText('0'), isNull);
      expect(tester.findText('1'), isNull);
      expect(tester.findText('2'), isNotNull);
      expect(tester.findText('3'), isNotNull);
      expect(tester.findText('4'), isNotNull);
      expect(tester.findText('5'), isNull);
54

55 56 57 58 59 60 61 62 63 64 65
      tester.pump();
      tester.scroll(tester.findText('3'), const Offset(-300.0, 0.0));
      tester.pump();
      // nothing should have changed
      expect(tester.findText('0'), isNull);
      expect(tester.findText('1'), isNull);
      expect(tester.findText('2'), isNotNull);
      expect(tester.findText('3'), isNotNull);
      expect(tester.findText('4'), isNotNull);
      expect(tester.findText('5'), isNull);
    });
66 67
  });
}