mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
* Manually fix every use of Point.x and Point.y
Some of these were moved to dx/dy, but not all.
* Manually convert uses of the old gradient API
* Remove old reference to Point.
* Mechanical changes
I applied the following at the root of the Flutter repository:
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]origin\b/Offset.zero/g'
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]lerp\b/Offset.lerp/g'
git ls-files -z | xargs -0 sed -i 's/\bnew Point\b/new Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bconst Point\b/const Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bstatic Point /static Offset /g'
git ls-files -z | xargs -0 sed -i 's/\bfinal Point /final Offset /g'
git ls-files -z | xargs -0 sed -i 's/^\( *\)Point /\1Offset /g'
git ls-files -z | xargs -0 sed -i 's/ui[.]Point\b/ui.Offset/g'
git ls-files -z | xargs -0 sed -i 's/(Point\b/(Offset/g'
git ls-files -z | xargs -0 sed -i 's/\([[{,]\) Point\b/\1 Offset/g'
git ls-files -z | xargs -0 sed -i 's/@required Point\b/@required Offset/g'
git ls-files -z | xargs -0 sed -i 's/<Point>/<Offset>/g'
git ls-files -z | xargs -0 sed -i 's/[.]toOffset()//g'
git ls-files -z | xargs -0 sed -i 's/[.]toPoint()//g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point, /show /g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point;/show Offset;/g'
* Mechanical changes - dartdocs
I applied the following at the root of the Flutter repository:
git ls-files -z | xargs -0 sed -i 's/\ba \[Point\]/an [Offset]/g'
git ls-files -z | xargs -0 sed -i 's/\[Point\]/[Offset]/g'
* Further improvements and a test
* Fix minor errors from rebasing...
* Roll engine
293 lines
9.1 KiB
Dart
293 lines
9.1 KiB
Dart
// 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';
|
|
|
|
bool refreshCalled = false;
|
|
|
|
Future<Null> refresh() {
|
|
refreshCalled = true;
|
|
return new Future<Null>.value();
|
|
}
|
|
|
|
Future<Null> holdRefresh() {
|
|
refreshCalled = true;
|
|
return new Completer<Null>().future;
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('RefreshIndicator', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: refresh,
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <String>['A', 'B', 'C', 'D', 'E', 'F'].map((String item) {
|
|
return new SizedBox(
|
|
height: 200.0,
|
|
child: new Text(item),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.fling(find.text('A'), const Offset(0.0, 300.0), 1000.0);
|
|
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
|
|
expect(refreshCalled, true);
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - bottom', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: refresh,
|
|
child: new ListView(
|
|
reverse: true,
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0);
|
|
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
|
|
expect(refreshCalled, true);
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - top - position', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: holdRefresh,
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.fling(find.text('X'), const Offset(0.0, 300.0), 1000.0);
|
|
await tester.pump();
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(tester.getCenter(find.byType(RefreshProgressIndicator)).dy, lessThan(300.0));
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - bottom - position', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: holdRefresh,
|
|
child: new ListView(
|
|
reverse: true,
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0);
|
|
await tester.pump();
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(tester.getCenter(find.byType(RefreshProgressIndicator)).dy, greaterThan(300.0));
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - no movement', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: refresh,
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
// this fling is horizontal, not up or down
|
|
await tester.fling(find.text('X'), const Offset(1.0, 0.0), 1000.0);
|
|
await tester.pump();
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, false);
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - not enough', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: refresh,
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.fling(find.text('X'), const Offset(0.0, 100.0), 1000.0);
|
|
await tester.pump();
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, false);
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - show - slow', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: holdRefresh, // this one never returns
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
bool completed = false;
|
|
tester.state<RefreshIndicatorState>(find.byType(RefreshIndicator))
|
|
.show()
|
|
.then<Null>((Null value) { completed = true; });
|
|
await tester.pump();
|
|
expect(completed, false);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, true);
|
|
expect(completed, false);
|
|
completed = false;
|
|
refreshCalled = false;
|
|
tester.state<RefreshIndicatorState>(find.byType(RefreshIndicator))
|
|
.show()
|
|
.then<Null>((Null value) { completed = true; });
|
|
await tester.pump();
|
|
expect(completed, false);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, false);
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - show - fast', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: refresh,
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
bool completed = false;
|
|
tester.state<RefreshIndicatorState>(find.byType(RefreshIndicator))
|
|
.show()
|
|
.then<Null>((Null value) { completed = true; });
|
|
await tester.pump();
|
|
expect(completed, false);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, true);
|
|
expect(completed, true);
|
|
completed = false;
|
|
refreshCalled = false;
|
|
tester.state<RefreshIndicatorState>(find.byType(RefreshIndicator))
|
|
.show()
|
|
.then<Null>((Null value) { completed = true; });
|
|
await tester.pump();
|
|
expect(completed, false);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, true);
|
|
expect(completed, true);
|
|
});
|
|
|
|
testWidgets('RefreshIndicator - show - fast - twice', (WidgetTester tester) async {
|
|
refreshCalled = false;
|
|
await tester.pumpWidget(
|
|
new RefreshIndicator(
|
|
onRefresh: refresh,
|
|
child: new ListView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 200.0,
|
|
child: const Text('X'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
bool completed1 = false;
|
|
tester.state<RefreshIndicatorState>(find.byType(RefreshIndicator))
|
|
.show()
|
|
.then<Null>((Null value) { completed1 = true; });
|
|
bool completed2 = false;
|
|
tester.state<RefreshIndicatorState>(find.byType(RefreshIndicator))
|
|
.show()
|
|
.then<Null>((Null value) { completed2 = true; });
|
|
await tester.pump();
|
|
expect(completed1, false);
|
|
expect(completed2, false);
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
await tester.pump(const Duration(seconds: 1));
|
|
expect(refreshCalled, true);
|
|
expect(completed1, true);
|
|
expect(completed2, true);
|
|
});
|
|
}
|