list_view_fling_test.dart 1.22 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 9 10 11 12 13
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

const double kHeight = 10.0;
const double kFlingOffset = kHeight * 20.0;

void main() {
14
  testWidgets("Flings don't stutter", (WidgetTester tester) async {
15
    await tester.pumpWidget(
16
      Directionality(
17
        textDirection: TextDirection.ltr,
18
        child: ListView.builder(
19
          itemBuilder: (BuildContext context, int index) {
20
            return Container(height: kHeight);
21 22 23 24
          },
        ),
      ),
    );
25 26

    double getCurrentOffset() {
Adam Barth's avatar
Adam Barth committed
27
      return tester.state<ScrollableState>(find.byType(Scrollable)).position.pixels;
28 29 30 31
    }

    await tester.fling(find.byType(ListView), const Offset(0.0, -kFlingOffset), 1000.0);
    expect(getCurrentOffset(), kFlingOffset);
32
    await tester.pump(); // process the up event
33
    while (tester.binding.transientCallbackCount > 0) {
34
      final double lastOffset = getCurrentOffset();
35 36 37
      await tester.pump(const Duration(milliseconds: 20));
      expect(getCurrentOffset(), greaterThan(lastOffset));
    }
38
  });
39
}