refresh_indicator_test.dart 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2015 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 'dart:async';

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';

10
final GlobalKey<ScrollableState> scrollableKey = new GlobalKey<ScrollableState>();
11

12
void main() {
13 14 15 16 17 18 19
  bool refreshCalled = false;

  Future<Null> refresh() {
    refreshCalled = true;
    return new Future<Null>.value();
  }

20 21
  testWidgets('RefreshIndicator', (WidgetTester tester) async {
    await tester.pumpWidget(
22
      new RefreshIndicator(
23
        scrollableKey: scrollableKey,
24 25
        refresh: refresh,
        child: new Block(
26
          scrollableKey: scrollableKey,
27 28 29 30 31 32
          children: <String>['A', 'B', 'C', 'D', 'E', 'F'].map((String item) {
            return new SizedBox(
              height: 200.0,
              child: new Text(item)
            );
          }).toList()
33
        )
34 35
      )
    );
36

37
    await tester.fling(find.text('A'), const Offset(0.0, 300.0), -1000.0);
38 39 40 41
    await tester.pump();
    await tester.pump(const Duration(seconds: 1)); // finish the scroll animation
    await tester.pump(const Duration(seconds: 1)); // finish the indicator settle animation
    await tester.pump(const Duration(seconds: 1)); // finish the indicator hide animation
42
    expect(refreshCalled, true);
43 44
  });
}