listview_end_append_test.dart 2.45 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
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

7 8
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
9
import 'package:flutter/gestures.dart' show DragStartBehavior;
10 11 12 13 14 15

void main() {
  testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/9506

    Widget buildFrame(int itemCount) {
16
      return Directionality(
17
        textDirection: TextDirection.ltr,
18
        child: ListView.builder(
19
          dragStartBehavior: DragStartBehavior.down,
20 21
          itemExtent: 200.0,
          itemCount: itemCount,
22
          itemBuilder: (BuildContext context, int index) => Text('item $index'),
23
        ),
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
      );
    }

    await tester.pumpWidget(buildFrame(3));
    expect(find.text('item 0'), findsOneWidget);
    expect(find.text('item 1'), findsOneWidget);
    expect(find.text('item 2'), findsOneWidget);

    await tester.pumpWidget(buildFrame(4));
    expect(find.text('item 3'), findsNothing);
    final TestGesture gesture = await tester.startGesture(const Offset(0.0, 300.0));
    await gesture.moveBy(const Offset(0.0, -200.0));
    await tester.pumpAndSettle();
    expect(find.text('item 3'), findsOneWidget);
  });

  testWidgets('ListView.builder() fixed itemExtent, scroll to end, append, scroll', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/9506

    Widget buildFrame(int itemCount) {
44
      return Directionality(
45
        textDirection: TextDirection.ltr,
46
        child: ListView.builder(
47
          dragStartBehavior: DragStartBehavior.down,
48 49
          itemCount: itemCount,
          itemBuilder: (BuildContext context, int index) {
50
            return SizedBox(
51
              height: 200.0,
52
              child: Text('item $index'),
53 54 55
            );
          },
        ),
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
      );
    }

    await tester.pumpWidget(buildFrame(3));
    expect(find.text('item 0'), findsOneWidget);
    expect(find.text('item 1'), findsOneWidget);
    expect(find.text('item 2'), findsOneWidget);

    await tester.pumpWidget(buildFrame(4));
    final TestGesture gesture = await tester.startGesture(const Offset(0.0, 300.0));
    await gesture.moveBy(const Offset(0.0, -200.0));
    await tester.pumpAndSettle();
    expect(find.text('item 3'), findsOneWidget);
  });
}