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

import 'package:flutter/material.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8 9 10 11

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

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

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

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