prefer_void_to_null in flutter_test (#22847)
* prefer_void_to_null in flutter_test * fix CI
This commit is contained in:
committed by
GitHub
parent
dba54316f4
commit
0e76cb4c10
@@ -12,7 +12,7 @@ import '../widgets/semantics_tester.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
Future<Null> _dragSlider(WidgetTester tester, Key sliderKey) {
|
||||
Future<void> _dragSlider(WidgetTester tester, Key sliderKey) {
|
||||
final Offset topLeft = tester.getTopLeft(find.byKey(sliderKey));
|
||||
const double unit = CupertinoThumbPainter.radius;
|
||||
const double delta = 3.0 * unit;
|
||||
|
||||
@@ -545,7 +545,7 @@ void main() {
|
||||
|
||||
testWidgets('Avatar drawer works as expected on RawChip', (WidgetTester tester) async {
|
||||
final GlobalKey labelKey = GlobalKey();
|
||||
Future<Null> pushChip({Widget avatar}) async {
|
||||
Future<void> pushChip({Widget avatar}) async {
|
||||
return tester.pumpWidget(
|
||||
_wrapForChip(
|
||||
child: Wrap(
|
||||
@@ -659,7 +659,7 @@ void main() {
|
||||
final UniqueKey labelKey = UniqueKey();
|
||||
final UniqueKey deleteButtonKey = UniqueKey();
|
||||
bool wasDeleted = false;
|
||||
Future<Null> pushChip({bool deletable = false}) async {
|
||||
Future<void> pushChip({bool deletable = false}) async {
|
||||
return tester.pumpWidget(
|
||||
_wrapForChip(
|
||||
child: Wrap(
|
||||
@@ -774,7 +774,7 @@ void main() {
|
||||
testWidgets('Selection with avatar works as expected on RawChip', (WidgetTester tester) async {
|
||||
bool selected = false;
|
||||
final UniqueKey labelKey = UniqueKey();
|
||||
Future<Null> pushChip({Widget avatar, bool selectable = false}) async {
|
||||
Future<void> pushChip({Widget avatar, bool selectable = false}) async {
|
||||
return tester.pumpWidget(
|
||||
_wrapForChip(
|
||||
child: Wrap(
|
||||
@@ -857,7 +857,7 @@ void main() {
|
||||
testWidgets('Selection without avatar works as expected on RawChip', (WidgetTester tester) async {
|
||||
bool selected = false;
|
||||
final UniqueKey labelKey = UniqueKey();
|
||||
Future<Null> pushChip({bool selectable = false}) async {
|
||||
Future<void> pushChip({bool selectable = false}) async {
|
||||
return tester.pumpWidget(
|
||||
_wrapForChip(
|
||||
child: Wrap(
|
||||
@@ -933,7 +933,7 @@ void main() {
|
||||
testWidgets('Activation works as expected on RawChip', (WidgetTester tester) async {
|
||||
bool selected = false;
|
||||
final UniqueKey labelKey = UniqueKey();
|
||||
Future<Null> pushChip({Widget avatar, bool selectable = false}) async {
|
||||
Future<void> pushChip({Widget avatar, bool selectable = false}) async {
|
||||
return tester.pumpWidget(
|
||||
_wrapForChip(
|
||||
child: Wrap(
|
||||
|
||||
@@ -353,7 +353,7 @@ void main() {
|
||||
group('Nested viewports (same orientation) showOnScreen', () {
|
||||
List<Widget> children;
|
||||
|
||||
Future<Null> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) {
|
||||
Future<void> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
@@ -346,7 +346,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('AnimatedSwitcher updates widgets without animating if they are isomorphic.', (WidgetTester tester) async {
|
||||
Future<Null> pumpChild(Widget child) async {
|
||||
Future<void> pumpChild(Widget child) async {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
|
||||
@@ -1444,7 +1444,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('a11y copy/cut/paste', () {
|
||||
Future<Null> _buildApp(
|
||||
Future<void> _buildApp(
|
||||
MockTextSelectionControls controls, WidgetTester tester) {
|
||||
return tester.pumpWidget(MaterialApp(
|
||||
home: EditableText(
|
||||
|
||||
@@ -126,7 +126,7 @@ void main() {
|
||||
bool didReceivePointerDown;
|
||||
bool didTap;
|
||||
|
||||
Future<Null> pumpWidgetTree(HitTestBehavior behavior) {
|
||||
Future<void> pumpWidgetTree(HitTestBehavior behavior) {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
@@ -156,7 +156,7 @@ TestImage getTestImage(WidgetTester tester, Key key) {
|
||||
return tester.renderObject<RenderImage>(find.byKey(key)).image;
|
||||
}
|
||||
|
||||
Future<Null> pumpTreeToLayout(WidgetTester tester, Widget widget) {
|
||||
Future<void> pumpTreeToLayout(WidgetTester tester, Widget widget) {
|
||||
const Duration pumpDuration = Duration(milliseconds: 0);
|
||||
const EnginePhase pumpPhase = EnginePhase.layout;
|
||||
return tester.pumpWidget(widget, pumpDuration, pumpPhase);
|
||||
|
||||
@@ -697,7 +697,7 @@ void main() {
|
||||
group('Nested SingleChildScrollView (same orientation) showOnScreen', () {
|
||||
List<Widget> children;
|
||||
|
||||
Future<Null> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) {
|
||||
Future<void> buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
@@ -24,7 +24,7 @@ class _GenerationTextState extends State<GenerationText> {
|
||||
|
||||
// Creates a SliverList with `keys.length` children and each child having a key from `keys` and a text of `key:generation`.
|
||||
// The generation is increased with every call to this method.
|
||||
Future<Null> test(WidgetTester tester, double offset, List<int> keys) {
|
||||
Future<void> test(WidgetTester tester, double offset, List<int> keys) {
|
||||
globalGeneration += 1;
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../rendering/mock_canvas.dart';
|
||||
|
||||
Future<Null> test(WidgetTester tester, double offset) {
|
||||
Future<void> test(WidgetTester tester, double offset) {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
Future<Null> test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) {
|
||||
Future<void> test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: textDirection,
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
Future<Null> test(WidgetTester tester, double offset, { double anchor = 0.0 }) {
|
||||
Future<void> test(WidgetTester tester, double offset, { double anchor = 0.0 }) {
|
||||
return tester.pumpWidget(
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
|
||||
@@ -197,7 +197,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
///
|
||||
/// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how
|
||||
/// this method works when the test is run with `flutter run`.
|
||||
Future<Null> pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]);
|
||||
Future<void> pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]);
|
||||
|
||||
/// Runs a `callback` that performs real asynchronous work.
|
||||
///
|
||||
@@ -227,12 +227,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
|
||||
/// Artificially calls dispatchLocaleChanged on the Widget binding,
|
||||
/// then flushes microtasks.
|
||||
Future<Null> setLocale(String languageCode, String countryCode) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> setLocale(String languageCode, String countryCode) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
assert(inTest);
|
||||
final Locale locale = Locale(languageCode, countryCode);
|
||||
dispatchLocaleChanged(locale);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -242,14 +241,13 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
/// then flushes microtasks.
|
||||
///
|
||||
/// Set to null to use the default surface size.
|
||||
Future<Null> setSurfaceSize(Size size) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> setSurfaceSize(Size size) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
assert(inTest);
|
||||
if (_surfaceSize == size)
|
||||
return null;
|
||||
return;
|
||||
_surfaceSize = size;
|
||||
handleMetricsChanged();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -272,11 +270,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
/// May result in an infinite loop or run out of memory if microtasks continue
|
||||
/// to recursively schedule new microtasks. Will not run any timers scheduled
|
||||
/// after this method was invoked, even if they are zero-time timers.
|
||||
Future<Null> idle() {
|
||||
return TestAsyncUtils.guard<Null>(() {
|
||||
final Completer<Null> completer = Completer<Null>();
|
||||
Future<void> idle() {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
final Completer<void> completer = Completer<void>();
|
||||
Timer.run(() {
|
||||
completer.complete(null);
|
||||
completer.complete();
|
||||
});
|
||||
return completer.future;
|
||||
});
|
||||
@@ -386,7 +384,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
/// The `description` is used by the [LiveTestWidgetsFlutterBinding] to
|
||||
/// show a label on the screen during the test. The description comes from
|
||||
/// the value passed to [testWidgets]. It must not be null.
|
||||
Future<Null> runTest(Future<Null> testBody(), VoidCallback invariantTester, { String description = '' });
|
||||
Future<void> runTest(Future<void> testBody(), VoidCallback invariantTester, { String description = '' });
|
||||
|
||||
/// This is called during test execution before and after the body has been
|
||||
/// executed.
|
||||
@@ -399,7 +397,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
|
||||
Zone _parentZone;
|
||||
|
||||
VoidCallback _createTestCompletionHandler(String testDescription, Completer<Null> completer) {
|
||||
VoidCallback _createTestCompletionHandler(String testDescription, Completer<void> completer) {
|
||||
return () {
|
||||
// This can get called twice, in the case of a Future without listeners failing, and then
|
||||
// our main future completing.
|
||||
@@ -410,7 +408,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
_pendingExceptionDetails = null;
|
||||
}
|
||||
if (!completer.isCompleted)
|
||||
completer.complete(null);
|
||||
completer.complete();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -426,8 +424,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
// The LiveTestWidgetsFlutterBinding overrides this to report the exception to the console.
|
||||
}
|
||||
|
||||
Future<Null> _runTest(Future<Null> testBody(), VoidCallback invariantTester, String description, {
|
||||
Future<Null> timeout,
|
||||
Future<void> _runTest(Future<void> testBody(), VoidCallback invariantTester, String description, {
|
||||
Future<void> timeout,
|
||||
}) {
|
||||
assert(description != null);
|
||||
assert(inTest);
|
||||
@@ -452,7 +450,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
_pendingExceptionDetails = details;
|
||||
}
|
||||
};
|
||||
final Completer<Null> testCompleter = Completer<Null>();
|
||||
final Completer<void> testCompleter = Completer<void>();
|
||||
final VoidCallback testCompletionHandler = _createTestCompletionHandler(description, testCompleter);
|
||||
void handleUncaughtError(dynamic exception, StackTrace stack) {
|
||||
if (testCompleter.isCompleted) {
|
||||
@@ -537,13 +535,13 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
);
|
||||
_parentZone = Zone.current;
|
||||
final Zone testZone = _parentZone.fork(specification: errorHandlingZoneSpecification);
|
||||
testZone.runBinary<Future<Null>, Future<Null> Function(), VoidCallback>(_runTestBody, testBody, invariantTester)
|
||||
testZone.runBinary<Future<void>, Future<void> Function(), VoidCallback>(_runTestBody, testBody, invariantTester)
|
||||
.whenComplete(testCompletionHandler);
|
||||
timeout?.catchError(handleUncaughtError);
|
||||
return testCompleter.future;
|
||||
}
|
||||
|
||||
Future<Null> _runTestBody(Future<Null> testBody(), VoidCallback invariantTester) async {
|
||||
Future<void> _runTestBody(Future<void> testBody(), VoidCallback invariantTester) async {
|
||||
assert(inTest);
|
||||
|
||||
runApp(Container(key: UniqueKey(), child: _preTestMessage)); // Reset the tree to a known state.
|
||||
@@ -688,8 +686,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
int get microtaskCount => _currentFakeAsync.microtaskCount;
|
||||
|
||||
@override
|
||||
Future<Null> pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) {
|
||||
return TestAsyncUtils.guard<Null>(() {
|
||||
Future<void> pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
assert(inTest);
|
||||
assert(_clock != null);
|
||||
if (duration != null)
|
||||
@@ -705,7 +703,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
handleDrawFrame();
|
||||
}
|
||||
_currentFakeAsync.flushMicrotasks();
|
||||
return Future<Null>.value();
|
||||
return Future<void>.value();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -774,8 +772,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> idle() {
|
||||
final Future<Null> result = super.idle();
|
||||
Future<void> idle() {
|
||||
final Future<void> result = super.idle();
|
||||
_currentFakeAsync.elapse(const Duration());
|
||||
return result;
|
||||
}
|
||||
@@ -816,7 +814,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
Duration _timeout;
|
||||
Stopwatch _timeoutStopwatch;
|
||||
Timer _timeoutTimer;
|
||||
Completer<Null> _timeoutCompleter;
|
||||
Completer<void> _timeoutCompleter;
|
||||
|
||||
void _checkTimeout(Timer timer) {
|
||||
assert(_timeoutTimer == timer);
|
||||
@@ -860,7 +858,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> runTest(Future<Null> testBody(), VoidCallback invariantTester, {
|
||||
Future<void> runTest(Future<void> testBody(), VoidCallback invariantTester, {
|
||||
String description = '',
|
||||
Duration timeout = const Duration(seconds: 2),
|
||||
}) {
|
||||
@@ -872,12 +870,12 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
_timeout = timeout;
|
||||
_timeoutStopwatch = Stopwatch()..start();
|
||||
_timeoutTimer = Timer.periodic(const Duration(seconds: 1), _checkTimeout);
|
||||
_timeoutCompleter = Completer<Null>();
|
||||
_timeoutCompleter = Completer<void>();
|
||||
|
||||
final FakeAsync fakeAsync = FakeAsync();
|
||||
_currentFakeAsync = fakeAsync; // reset in postTest
|
||||
_clock = fakeAsync.getClock(DateTime.utc(2015, 1, 1));
|
||||
Future<Null> testBodyResult;
|
||||
Future<void> testBodyResult;
|
||||
fakeAsync.run((FakeAsync localFakeAsync) {
|
||||
assert(fakeAsync == _currentFakeAsync);
|
||||
assert(fakeAsync == localFakeAsync);
|
||||
@@ -885,14 +883,14 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
assert(inTest);
|
||||
});
|
||||
|
||||
return Future<Null>.microtask(() async {
|
||||
return Future<void>.microtask(() async {
|
||||
// testBodyResult is a Future that was created in the Zone of the
|
||||
// fakeAsync. This means that if we await it here, it will register a
|
||||
// microtask to handle the future _in the fake async zone_. We avoid this
|
||||
// by calling '.then' in the current zone. While flushing the microtasks
|
||||
// of the fake-zone below, the new future will be completed and can then
|
||||
// be used without fakeAsync.
|
||||
final Future<Null> resultFuture = testBodyResult.then<Null>((_) {
|
||||
final Future<void> resultFuture = testBodyResult.then<void>((_) {
|
||||
// Do nothing.
|
||||
});
|
||||
|
||||
@@ -1038,7 +1036,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
@override
|
||||
test_package.Timeout get defaultTestTimeout => test_package.Timeout.none;
|
||||
|
||||
Completer<Null> _pendingFrame;
|
||||
Completer<void> _pendingFrame;
|
||||
bool _expectingFrame = false;
|
||||
bool _viewNeedsPaint = false;
|
||||
bool _runningAsyncTasks = false;
|
||||
@@ -1192,12 +1190,12 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) {
|
||||
Future<void> pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) {
|
||||
assert(newPhase == EnginePhase.sendSemanticsUpdate);
|
||||
assert(inTest);
|
||||
assert(!_expectingFrame);
|
||||
assert(_pendingFrame == null);
|
||||
return TestAsyncUtils.guard<Null>(() {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
if (duration != null) {
|
||||
Timer(duration, () {
|
||||
_expectingFrame = true;
|
||||
@@ -1207,7 +1205,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
_expectingFrame = true;
|
||||
scheduleFrame();
|
||||
}
|
||||
_pendingFrame = Completer<Null>();
|
||||
_pendingFrame = Completer<void>();
|
||||
return _pendingFrame.future;
|
||||
});
|
||||
}
|
||||
@@ -1244,7 +1242,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> runTest(Future<Null> testBody(), VoidCallback invariantTester, { String description = '' }) async {
|
||||
Future<void> runTest(Future<void> testBody(), VoidCallback invariantTester, { String description = '' }) async {
|
||||
assert(description != null);
|
||||
assert(!inTest);
|
||||
_inTest = true;
|
||||
@@ -1587,8 +1585,8 @@ class _MockHttpRequest extends HttpClientRequest {
|
||||
void addError(Object error, [StackTrace stackTrace]) {}
|
||||
|
||||
@override
|
||||
Future<Null> addStream(Stream<List<int>> stream) {
|
||||
return Future<Null>.value(null);
|
||||
Future<void> addStream(Stream<List<int>> stream) {
|
||||
return Future<void>.value();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1606,8 +1604,8 @@ class _MockHttpRequest extends HttpClientRequest {
|
||||
Future<HttpClientResponse> get done => null;
|
||||
|
||||
@override
|
||||
Future<Null> flush() {
|
||||
return Future<Null>.value(null);
|
||||
Future<void> flush() {
|
||||
return Future<void>.value();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -256,16 +256,15 @@ abstract class WidgetController {
|
||||
///
|
||||
/// If the center of the widget is not exposed, this might send events to
|
||||
/// another object.
|
||||
Future<Null> tap(Finder finder, { int pointer }) {
|
||||
Future<void> tap(Finder finder, { int pointer }) {
|
||||
return tapAt(getCenter(finder), pointer: pointer);
|
||||
}
|
||||
|
||||
/// Dispatch a pointer down / pointer up sequence at the given location.
|
||||
Future<Null> tapAt(Offset location, { int pointer }) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> tapAt(Offset location, { int pointer }) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
final TestGesture gesture = await startGesture(location, pointer: pointer);
|
||||
await gesture.up();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -286,18 +285,17 @@ abstract class WidgetController {
|
||||
///
|
||||
/// If the center of the widget is not exposed, this might send events to
|
||||
/// another object.
|
||||
Future<Null> longPress(Finder finder, { int pointer }) {
|
||||
Future<void> longPress(Finder finder, { int pointer }) {
|
||||
return longPressAt(getCenter(finder), pointer: pointer);
|
||||
}
|
||||
|
||||
/// Dispatch a pointer down / pointer up sequence at the given location with
|
||||
/// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events.
|
||||
Future<Null> longPressAt(Offset location, { int pointer }) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> longPressAt(Offset location, { int pointer }) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
final TestGesture gesture = await startGesture(location, pointer: pointer);
|
||||
await pump(kLongPressTimeout + kPressTimeout);
|
||||
await gesture.up();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -321,7 +319,7 @@ abstract class WidgetController {
|
||||
/// opposite direction of the fling (e.g. dragging 200 pixels to the right,
|
||||
/// then fling to the left over 200 pixels, ending at the exact point that the
|
||||
/// drag started).
|
||||
Future<Null> fling(Finder finder, Offset offset, double speed, {
|
||||
Future<void> fling(Finder finder, Offset offset, double speed, {
|
||||
int pointer,
|
||||
Duration frameInterval = const Duration(milliseconds: 16),
|
||||
Offset initialOffset = Offset.zero,
|
||||
@@ -363,7 +361,7 @@ abstract class WidgetController {
|
||||
/// opposite direction of the fling (e.g. dragging 200 pixels to the right,
|
||||
/// then fling to the left over 200 pixels, ending at the exact point that the
|
||||
/// drag started).
|
||||
Future<Null> flingFrom(Offset startLocation, Offset offset, double speed, {
|
||||
Future<void> flingFrom(Offset startLocation, Offset offset, double speed, {
|
||||
int pointer,
|
||||
Duration frameInterval = const Duration(milliseconds: 16),
|
||||
Offset initialOffset = Offset.zero,
|
||||
@@ -371,7 +369,7 @@ abstract class WidgetController {
|
||||
}) {
|
||||
assert(offset.distance > 0.0);
|
||||
assert(speed > 0.0); // speed is pixels/second
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
final TestPointer testPointer = TestPointer(pointer ?? _getNextPointer());
|
||||
final HitTestResult result = hitTestOnBinding(startLocation);
|
||||
const int kMoveCount = 50; // Needs to be >= kHistorySize, see _LeastSquaresVelocityTrackerStrategy
|
||||
@@ -394,7 +392,6 @@ abstract class WidgetController {
|
||||
}
|
||||
}
|
||||
await sendEventToBinding(testPointer.up(timeStamp: Duration(milliseconds: timeStamp.round())), result);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -407,7 +404,7 @@ abstract class WidgetController {
|
||||
///
|
||||
/// See also [SchedulerBinding.endOfFrame], which returns a future that could
|
||||
/// be appropriate to return in the implementation of this method.
|
||||
Future<Null> pump(Duration duration);
|
||||
Future<void> pump(Duration duration);
|
||||
|
||||
/// Attempts to drag the given widget by the given offset, by
|
||||
/// starting a drag in the middle of the widget.
|
||||
@@ -417,7 +414,7 @@ abstract class WidgetController {
|
||||
///
|
||||
/// If you want the drag to end with a speed so that the gesture recognition
|
||||
/// system identifies the gesture as a fling, consider using [fling] instead.
|
||||
Future<Null> drag(Finder finder, Offset offset, { int pointer }) {
|
||||
Future<void> drag(Finder finder, Offset offset, { int pointer }) {
|
||||
return dragFrom(getCenter(finder), offset, pointer: pointer);
|
||||
}
|
||||
|
||||
@@ -427,13 +424,12 @@ abstract class WidgetController {
|
||||
/// If you want the drag to end with a speed so that the gesture recognition
|
||||
/// system identifies the gesture as a fling, consider using [flingFrom]
|
||||
/// instead.
|
||||
Future<Null> dragFrom(Offset startLocation, Offset offset, { int pointer }) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> dragFrom(Offset startLocation, Offset offset, { int pointer }) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
final TestGesture gesture = await startGesture(startLocation, pointer: pointer);
|
||||
assert(gesture != null);
|
||||
await gesture.moveBy(offset);
|
||||
await gesture.up();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -468,10 +464,9 @@ abstract class WidgetController {
|
||||
}
|
||||
|
||||
/// Forwards the given pointer event to the binding.
|
||||
Future<Null> sendEventToBinding(PointerEvent event, HitTestResult result) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> sendEventToBinding(PointerEvent event, HitTestResult result) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
binding.dispatchEvent(event, result);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -538,7 +533,7 @@ class LiveWidgetController extends WidgetController {
|
||||
LiveWidgetController(WidgetsBinding binding) : super(binding);
|
||||
|
||||
@override
|
||||
Future<Null> pump(Duration duration) async {
|
||||
Future<void> pump(Duration duration) async {
|
||||
if (duration != null)
|
||||
await Future<void>.delayed(duration);
|
||||
binding.scheduleFrame();
|
||||
|
||||
@@ -1506,7 +1506,7 @@ class _RendersOnPhysicalModel extends _MatchRenderObject<RenderPhysicalShape, Re
|
||||
}
|
||||
}
|
||||
|
||||
class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, Null> {
|
||||
class _RendersOnPhysicalShape extends _MatchRenderObject<RenderPhysicalShape, RenderPhysicalModel> {
|
||||
const _RendersOnPhysicalShape({
|
||||
this.shape,
|
||||
this.elevation,
|
||||
@@ -1607,7 +1607,7 @@ class _ClipsWithBoundingRRect extends _MatchRenderObject<RenderClipPath, RenderC
|
||||
description.add('clips with bounding rounded rectangle with borderRadius: $borderRadius');
|
||||
}
|
||||
|
||||
class _ClipsWithShapeBorder extends _MatchRenderObject<RenderClipPath, Null> {
|
||||
class _ClipsWithShapeBorder extends _MatchRenderObject<RenderClipPath, RenderClipRRect> {
|
||||
const _ClipsWithShapeBorder({@required this.shape});
|
||||
|
||||
final ShapeBorder shape;
|
||||
|
||||
@@ -113,7 +113,7 @@ class TestPointer {
|
||||
|
||||
/// Signature for a callback that can dispatch events and returns a future that
|
||||
/// completes when the event dispatch is complete.
|
||||
typedef EventDispatcher = Future<Null> Function(PointerEvent event, HitTestResult result);
|
||||
typedef EventDispatcher = Future<void> Function(PointerEvent event, HitTestResult result);
|
||||
|
||||
/// Signature for callbacks that perform hit-testing at a given location.
|
||||
typedef HitTester = HitTestResult Function(Offset location);
|
||||
@@ -142,7 +142,7 @@ class TestGesture {
|
||||
assert(hitTester != null);
|
||||
assert(dispatcher != null);
|
||||
TestGesture result;
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
// dispatch down event
|
||||
final HitTestResult hitTestResult = hitTester(downLocation);
|
||||
final TestPointer testPointer = TestPointer(pointer);
|
||||
@@ -150,8 +150,7 @@ class TestGesture {
|
||||
|
||||
// create a TestGesture
|
||||
result = TestGesture._(dispatcher, hitTestResult, testPointer);
|
||||
return null;
|
||||
}).then<TestGesture>((Null value) {
|
||||
}).then<TestGesture>((void value) {
|
||||
return result;
|
||||
}, onError: (dynamic error, StackTrace stack) {
|
||||
return Future<TestGesture>.error(error, stack);
|
||||
@@ -163,14 +162,14 @@ class TestGesture {
|
||||
final TestPointer _pointer;
|
||||
|
||||
/// Send a move event moving the pointer by the given offset.
|
||||
Future<Null> moveBy(Offset offset, { Duration timeStamp = Duration.zero }) {
|
||||
Future<void> moveBy(Offset offset, { Duration timeStamp = Duration.zero }) {
|
||||
assert(_pointer._isDown);
|
||||
return moveTo(_pointer.location + offset, timeStamp: timeStamp);
|
||||
}
|
||||
|
||||
/// Send a move event moving the pointer to the given location.
|
||||
Future<Null> moveTo(Offset location, { Duration timeStamp = Duration.zero }) {
|
||||
return TestAsyncUtils.guard<Null>(() {
|
||||
Future<void> moveTo(Offset location, { Duration timeStamp = Duration.zero }) {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
assert(_pointer._isDown);
|
||||
return _dispatcher(_pointer.move(location, timeStamp: timeStamp), _result);
|
||||
});
|
||||
@@ -179,12 +178,11 @@ class TestGesture {
|
||||
/// End the gesture by releasing the pointer.
|
||||
///
|
||||
/// The object is no longer usable after this method has been called.
|
||||
Future<Null> up() {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> up() {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
assert(_pointer._isDown);
|
||||
await _dispatcher(_pointer.up(), _result);
|
||||
assert(!_pointer._isDown);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -193,12 +191,11 @@ class TestGesture {
|
||||
/// for instance).
|
||||
///
|
||||
/// The object is no longer usable after this method has been called.
|
||||
Future<Null> cancel() {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> cancel() {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
assert(_pointer._isDown);
|
||||
await _dispatcher(_pointer.cancel(), _result);
|
||||
assert(!_pointer._isDown);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class TestTextInput {
|
||||
/// Simulates the user pressing one of the [TextInputAction] buttons.
|
||||
/// Does not check that the [TextInputAction] performed is an acceptable one
|
||||
/// based on the `inputAction` [setClientArgs].
|
||||
Future<Null> receiveAction(TextInputAction action) async {
|
||||
Future<void> receiveAction(TextInputAction action) async {
|
||||
return TestAsyncUtils.guard(() {
|
||||
// Not using the `expect` function because in the case of a FlutterDriver
|
||||
// test this code does not run in a package:test test zone.
|
||||
@@ -135,7 +135,7 @@ class TestTextInput {
|
||||
throw TestFailure('Tried to use TestTextInput with no keyboard attached. You must use WidgetTester.showKeyboard() first.');
|
||||
}
|
||||
|
||||
final Completer<Null> completer = Completer<Null>();
|
||||
final Completer<void> completer = Completer<void>();
|
||||
|
||||
BinaryMessages.handlePlatformMessage(
|
||||
SystemChannels.textInput.name,
|
||||
|
||||
@@ -30,7 +30,7 @@ export 'package:test/test.dart' hide
|
||||
isInstanceOf; // we have our own wrapper in matchers.dart
|
||||
|
||||
/// Signature for callback to [testWidgets] and [benchmarkWidgets].
|
||||
typedef WidgetTesterCallback = Future<Null> Function(WidgetTester widgetTester);
|
||||
typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
|
||||
|
||||
/// Runs the [callback] inside the Flutter test environment.
|
||||
///
|
||||
@@ -114,7 +114,7 @@ void testWidgets(String description, WidgetTesterCallback callback, {
|
||||
/// });
|
||||
/// exit(0);
|
||||
/// }
|
||||
Future<Null> benchmarkWidgets(WidgetTesterCallback callback) {
|
||||
Future<void> benchmarkWidgets(WidgetTesterCallback callback) {
|
||||
assert(() {
|
||||
print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓');
|
||||
print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇');
|
||||
@@ -136,7 +136,7 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) {
|
||||
return binding.runTest(
|
||||
() => callback(tester),
|
||||
tester._endOfTestVerifications,
|
||||
) ?? Future<Null>.value();
|
||||
) ?? Future<void>.value();
|
||||
}
|
||||
|
||||
/// Assert that `actual` matches `matcher`.
|
||||
@@ -217,11 +217,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
///
|
||||
/// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how
|
||||
/// this method works when the test is run with `flutter run`.
|
||||
Future<Null> pumpWidget(Widget widget, [
|
||||
Future<void> pumpWidget(Widget widget, [
|
||||
Duration duration,
|
||||
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
|
||||
]) {
|
||||
return TestAsyncUtils.guard<Null>(() {
|
||||
return TestAsyncUtils.guard<void>(() {
|
||||
binding.attachRootWidget(widget);
|
||||
binding.scheduleFrame();
|
||||
return binding.pump(duration, phase);
|
||||
@@ -240,11 +240,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
/// See also [LiveTestWidgetsFlutterBindingFramePolicy], which affects how
|
||||
/// this method works when the test is run with `flutter run`.
|
||||
@override
|
||||
Future<Null> pump([
|
||||
Future<void> pump([
|
||||
Duration duration,
|
||||
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
|
||||
]) {
|
||||
return TestAsyncUtils.guard<Null>(() => binding.pump(duration, phase));
|
||||
return TestAsyncUtils.guard<void>(() => binding.pump(duration, phase));
|
||||
}
|
||||
|
||||
/// Repeatedly calls [pump] with the given `duration` until there are no
|
||||
@@ -292,7 +292,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
return true;
|
||||
}());
|
||||
int count = 0;
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
final DateTime endTime = binding.clock.fromNowBy(timeout);
|
||||
do {
|
||||
if (binding.clock.now().isAfter(endTime))
|
||||
@@ -300,7 +300,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
await binding.pump(duration, phase);
|
||||
count += 1;
|
||||
} while (binding.hasScheduledFrame);
|
||||
}).then<int>((Null _) => count);
|
||||
}).then<int>((void _) => count);
|
||||
}
|
||||
|
||||
/// Runs a [callback] that performs real asynchronous work.
|
||||
@@ -350,10 +350,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Null> sendEventToBinding(PointerEvent event, HitTestResult result) {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> sendEventToBinding(PointerEvent event, HitTestResult result) {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
binding.dispatchEvent(event, result, source: TestBindingEventSource.test);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -484,8 +483,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
///
|
||||
/// Does not run timers. May result in an infinite loop or run out of memory
|
||||
/// if microtasks continue to recursively schedule new microtasks.
|
||||
Future<Null> idle() {
|
||||
return TestAsyncUtils.guard<Null>(() => binding.idle());
|
||||
Future<void> idle() {
|
||||
return TestAsyncUtils.guard<void>(() => binding.idle());
|
||||
}
|
||||
|
||||
Set<Ticker> _tickers;
|
||||
@@ -569,8 +568,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
///
|
||||
/// Tests that just need to add text to widgets like [TextField]
|
||||
/// or [TextFormField] only need to call [enterText].
|
||||
Future<Null> showKeyboard(Finder finder) async {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> showKeyboard(Finder finder) async {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
final EditableTextState editable = state<EditableTextState>(
|
||||
find.descendant(
|
||||
of: finder,
|
||||
@@ -592,8 +591,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
///
|
||||
/// To just give [finder] the focus without entering any text,
|
||||
/// see [showKeyboard].
|
||||
Future<Null> enterText(Finder finder, String text) async {
|
||||
return TestAsyncUtils.guard<Null>(() async {
|
||||
Future<void> enterText(Finder finder, String text) async {
|
||||
return TestAsyncUtils.guard<void>(() async {
|
||||
await showKeyboard(finder);
|
||||
testTextInput.enterText(text);
|
||||
await idle();
|
||||
|
||||
@@ -13,22 +13,22 @@ import 'package:test/test.dart' as real_test show expect;
|
||||
// of this test is to see how we handle leaking APIs.
|
||||
|
||||
class TestAPI {
|
||||
Future<Null> testGuard1() {
|
||||
return TestAsyncUtils.guard(() async { return null; });
|
||||
Future<Object> testGuard1() {
|
||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
||||
}
|
||||
Future<Null> testGuard2() {
|
||||
return TestAsyncUtils.guard(() async { return null; });
|
||||
Future<Object> testGuard2() {
|
||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
||||
}
|
||||
}
|
||||
|
||||
class TestAPISubclass extends TestAPI {
|
||||
Future<Null> testGuard3() {
|
||||
return TestAsyncUtils.guard(() async { return null; });
|
||||
Future<Object> testGuard3() {
|
||||
return TestAsyncUtils.guard<Object>(() async { return null; });
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _guardedThrower() {
|
||||
return TestAsyncUtils.guard(() async {
|
||||
Future<Object> _guardedThrower() {
|
||||
return TestAsyncUtils.guard<Object>(() async {
|
||||
throw 'Hello';
|
||||
});
|
||||
}
|
||||
@@ -36,7 +36,7 @@ Future<Null> _guardedThrower() {
|
||||
void main() {
|
||||
test('TestAsyncUtils - one class', () async {
|
||||
final TestAPI testAPI = TestAPI();
|
||||
Future<Null> f1, f2;
|
||||
Future<Object> f1, f2;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
f2 = testAPI.testGuard2();
|
||||
@@ -57,7 +57,7 @@ void main() {
|
||||
|
||||
test('TestAsyncUtils - two classes, all callers in superclass', () async {
|
||||
final TestAPI testAPI = TestAPISubclass();
|
||||
Future<Null> f1, f2;
|
||||
Future<Object> f1, f2;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
f2 = testAPI.testGuard2();
|
||||
@@ -78,7 +78,7 @@ void main() {
|
||||
|
||||
test('TestAsyncUtils - two classes, mixed callers', () async {
|
||||
final TestAPISubclass testAPI = TestAPISubclass();
|
||||
Future<Null> f1, f2;
|
||||
Future<Object> f1, f2;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
f2 = testAPI.testGuard3();
|
||||
@@ -99,7 +99,7 @@ void main() {
|
||||
|
||||
test('TestAsyncUtils - expect() catches pending async work', () async {
|
||||
final TestAPI testAPI = TestAPISubclass();
|
||||
Future<Null> f1;
|
||||
Future<Object> f1;
|
||||
f1 = testAPI.testGuard1();
|
||||
try {
|
||||
flutter_test.expect(0, 0);
|
||||
@@ -119,7 +119,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||
Future<Null> f1, f2;
|
||||
Future<Object> f1, f2;
|
||||
try {
|
||||
f1 = tester.pump();
|
||||
f2 = tester.pump();
|
||||
@@ -139,7 +139,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||
Future<Null> f1;
|
||||
Future<Object> f1;
|
||||
try {
|
||||
f1 = tester.pump();
|
||||
TestAsyncUtils.verifyAllScopesClosed();
|
||||
@@ -155,7 +155,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async {
|
||||
Future<Null> f1;
|
||||
Future<Object> f1;
|
||||
try {
|
||||
f1 = tester.pump();
|
||||
TestAsyncUtils.verifyAllScopesClosed();
|
||||
|
||||
Reference in New Issue
Block a user