listview_end_append_test.dart 2.43 KB
Newer Older
1 2 3 4 5 6
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

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

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

    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);
  });
}