diff --git a/packages/flutter/test/cupertino/slider_test.dart b/packages/flutter/test/cupertino/slider_test.dart index eae21e7353..89593246cc 100644 --- a/packages/flutter/test/cupertino/slider_test.dart +++ b/packages/flutter/test/cupertino/slider_test.dart @@ -12,7 +12,7 @@ import '../widgets/semantics_tester.dart'; void main() { - Future _dragSlider(WidgetTester tester, Key sliderKey) { + Future _dragSlider(WidgetTester tester, Key sliderKey) { final Offset topLeft = tester.getTopLeft(find.byKey(sliderKey)); const double unit = CupertinoThumbPainter.radius; const double delta = 3.0 * unit; diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index fa906fcb8e..8870443e08 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -545,7 +545,7 @@ void main() { testWidgets('Avatar drawer works as expected on RawChip', (WidgetTester tester) async { final GlobalKey labelKey = GlobalKey(); - Future pushChip({Widget avatar}) async { + Future 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 pushChip({bool deletable = false}) async { + Future 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 pushChip({Widget avatar, bool selectable = false}) async { + Future 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 pushChip({bool selectable = false}) async { + Future 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 pushChip({Widget avatar, bool selectable = false}) async { + Future pushChip({Widget avatar, bool selectable = false}) async { return tester.pumpWidget( _wrapForChip( child: Wrap( diff --git a/packages/flutter/test/rendering/viewport_test.dart b/packages/flutter/test/rendering/viewport_test.dart index c97bbe8d57..a181101a6d 100644 --- a/packages/flutter/test/rendering/viewport_test.dart +++ b/packages/flutter/test/rendering/viewport_test.dart @@ -353,7 +353,7 @@ void main() { group('Nested viewports (same orientation) showOnScreen', () { List children; - Future buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) { + Future buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) { return tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/widgets/animated_switcher_test.dart b/packages/flutter/test/widgets/animated_switcher_test.dart index ae5a8063c3..78c2a456c3 100644 --- a/packages/flutter/test/widgets/animated_switcher_test.dart +++ b/packages/flutter/test/widgets/animated_switcher_test.dart @@ -346,7 +346,7 @@ void main() { }); testWidgets('AnimatedSwitcher updates widgets without animating if they are isomorphic.', (WidgetTester tester) async { - Future pumpChild(Widget child) async { + Future pumpChild(Widget child) async { return tester.pumpWidget( Directionality( textDirection: TextDirection.rtl, diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index 2dba2fe4d4..31f7d7d0ab 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -1444,7 +1444,7 @@ void main() { }); group('a11y copy/cut/paste', () { - Future _buildApp( + Future _buildApp( MockTextSelectionControls controls, WidgetTester tester) { return tester.pumpWidget(MaterialApp( home: EditableText( diff --git a/packages/flutter/test/widgets/gesture_detector_test.dart b/packages/flutter/test/widgets/gesture_detector_test.dart index a0b78209e8..67a0652a15 100644 --- a/packages/flutter/test/widgets/gesture_detector_test.dart +++ b/packages/flutter/test/widgets/gesture_detector_test.dart @@ -126,7 +126,7 @@ void main() { bool didReceivePointerDown; bool didTap; - Future pumpWidgetTree(HitTestBehavior behavior) { + Future pumpWidgetTree(HitTestBehavior behavior) { return tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/widgets/image_resolution_test.dart b/packages/flutter/test/widgets/image_resolution_test.dart index 84f1950fd4..40ee82f812 100644 --- a/packages/flutter/test/widgets/image_resolution_test.dart +++ b/packages/flutter/test/widgets/image_resolution_test.dart @@ -156,7 +156,7 @@ TestImage getTestImage(WidgetTester tester, Key key) { return tester.renderObject(find.byKey(key)).image; } -Future pumpTreeToLayout(WidgetTester tester, Widget widget) { +Future pumpTreeToLayout(WidgetTester tester, Widget widget) { const Duration pumpDuration = Duration(milliseconds: 0); const EnginePhase pumpPhase = EnginePhase.layout; return tester.pumpWidget(widget, pumpDuration, pumpPhase); diff --git a/packages/flutter/test/widgets/single_child_scroll_view_test.dart b/packages/flutter/test/widgets/single_child_scroll_view_test.dart index d974141bf9..4026b6ae75 100644 --- a/packages/flutter/test/widgets/single_child_scroll_view_test.dart +++ b/packages/flutter/test/widgets/single_child_scroll_view_test.dart @@ -697,7 +697,7 @@ void main() { group('Nested SingleChildScrollView (same orientation) showOnScreen', () { List children; - Future buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) { + Future buildNestedScroller({WidgetTester tester, ScrollController inner, ScrollController outer}) { return tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/widgets/slivers_block_global_key_test.dart b/packages/flutter/test/widgets/slivers_block_global_key_test.dart index 2aa787d84e..ebfc53444d 100644 --- a/packages/flutter/test/widgets/slivers_block_global_key_test.dart +++ b/packages/flutter/test/widgets/slivers_block_global_key_test.dart @@ -24,7 +24,7 @@ class _GenerationTextState extends State { // 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 test(WidgetTester tester, double offset, List keys) { +Future test(WidgetTester tester, double offset, List keys) { globalGeneration += 1; return tester.pumpWidget( Directionality( diff --git a/packages/flutter/test/widgets/slivers_block_test.dart b/packages/flutter/test/widgets/slivers_block_test.dart index d433be9acb..147b25ba98 100644 --- a/packages/flutter/test/widgets/slivers_block_test.dart +++ b/packages/flutter/test/widgets/slivers_block_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/widgets.dart'; import '../rendering/mock_canvas.dart'; -Future test(WidgetTester tester, double offset) { +Future test(WidgetTester tester, double offset) { return tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter/test/widgets/slivers_padding_test.dart b/packages/flutter/test/widgets/slivers_padding_test.dart index 231611148f..89ad9508e7 100644 --- a/packages/flutter/test/widgets/slivers_padding_test.dart +++ b/packages/flutter/test/widgets/slivers_padding_test.dart @@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; -Future test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) { +Future test(WidgetTester tester, double offset, EdgeInsetsGeometry padding, AxisDirection axisDirection, TextDirection textDirection) { return tester.pumpWidget( Directionality( textDirection: textDirection, diff --git a/packages/flutter/test/widgets/slivers_test.dart b/packages/flutter/test/widgets/slivers_test.dart index 9b39ac791f..c25ee665b1 100644 --- a/packages/flutter/test/widgets/slivers_test.dart +++ b/packages/flutter/test/widgets/slivers_test.dart @@ -6,7 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter/rendering.dart'; -Future test(WidgetTester tester, double offset, { double anchor = 0.0 }) { +Future test(WidgetTester tester, double offset, { double anchor = 0.0 }) { return tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 80c3fb8435..b865b0bd72 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -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 pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]); + Future 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 setLocale(String languageCode, String countryCode) { - return TestAsyncUtils.guard(() async { + Future setLocale(String languageCode, String countryCode) { + return TestAsyncUtils.guard(() 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 setSurfaceSize(Size size) { - return TestAsyncUtils.guard(() async { + Future setSurfaceSize(Size size) { + return TestAsyncUtils.guard(() 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 idle() { - return TestAsyncUtils.guard(() { - final Completer completer = Completer(); + Future idle() { + return TestAsyncUtils.guard(() { + final Completer completer = Completer(); 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 runTest(Future testBody(), VoidCallback invariantTester, { String description = '' }); + Future runTest(Future 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 completer) { + VoidCallback _createTestCompletionHandler(String testDescription, Completer 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 _runTest(Future testBody(), VoidCallback invariantTester, String description, { - Future timeout, + Future _runTest(Future testBody(), VoidCallback invariantTester, String description, { + Future timeout, }) { assert(description != null); assert(inTest); @@ -452,7 +450,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase _pendingExceptionDetails = details; } }; - final Completer testCompleter = Completer(); + final Completer testCompleter = Completer(); 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 Function(), VoidCallback>(_runTestBody, testBody, invariantTester) + testZone.runBinary, Future Function(), VoidCallback>(_runTestBody, testBody, invariantTester) .whenComplete(testCompletionHandler); timeout?.catchError(handleUncaughtError); return testCompleter.future; } - Future _runTestBody(Future testBody(), VoidCallback invariantTester) async { + Future _runTestBody(Future 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 pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) { - return TestAsyncUtils.guard(() { + Future pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) { + return TestAsyncUtils.guard(() { assert(inTest); assert(_clock != null); if (duration != null) @@ -705,7 +703,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { handleDrawFrame(); } _currentFakeAsync.flushMicrotasks(); - return Future.value(); + return Future.value(); }); } @@ -774,8 +772,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { } @override - Future idle() { - final Future result = super.idle(); + Future idle() { + final Future result = super.idle(); _currentFakeAsync.elapse(const Duration()); return result; } @@ -816,7 +814,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { Duration _timeout; Stopwatch _timeoutStopwatch; Timer _timeoutTimer; - Completer _timeoutCompleter; + Completer _timeoutCompleter; void _checkTimeout(Timer timer) { assert(_timeoutTimer == timer); @@ -860,7 +858,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { } @override - Future runTest(Future testBody(), VoidCallback invariantTester, { + Future runTest(Future 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(); + _timeoutCompleter = Completer(); final FakeAsync fakeAsync = FakeAsync(); _currentFakeAsync = fakeAsync; // reset in postTest _clock = fakeAsync.getClock(DateTime.utc(2015, 1, 1)); - Future testBodyResult; + Future testBodyResult; fakeAsync.run((FakeAsync localFakeAsync) { assert(fakeAsync == _currentFakeAsync); assert(fakeAsync == localFakeAsync); @@ -885,14 +883,14 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { assert(inTest); }); - return Future.microtask(() async { + return Future.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 resultFuture = testBodyResult.then((_) { + final Future resultFuture = testBodyResult.then((_) { // Do nothing. }); @@ -1038,7 +1036,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { @override test_package.Timeout get defaultTestTimeout => test_package.Timeout.none; - Completer _pendingFrame; + Completer _pendingFrame; bool _expectingFrame = false; bool _viewNeedsPaint = false; bool _runningAsyncTasks = false; @@ -1192,12 +1190,12 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { } @override - Future pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) { + Future pump([ Duration duration, EnginePhase newPhase = EnginePhase.sendSemanticsUpdate ]) { assert(newPhase == EnginePhase.sendSemanticsUpdate); assert(inTest); assert(!_expectingFrame); assert(_pendingFrame == null); - return TestAsyncUtils.guard(() { + return TestAsyncUtils.guard(() { if (duration != null) { Timer(duration, () { _expectingFrame = true; @@ -1207,7 +1205,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { _expectingFrame = true; scheduleFrame(); } - _pendingFrame = Completer(); + _pendingFrame = Completer(); return _pendingFrame.future; }); } @@ -1244,7 +1242,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { } @override - Future runTest(Future testBody(), VoidCallback invariantTester, { String description = '' }) async { + Future runTest(Future 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 addStream(Stream> stream) { - return Future.value(null); + Future addStream(Stream> stream) { + return Future.value(); } @override @@ -1606,8 +1604,8 @@ class _MockHttpRequest extends HttpClientRequest { Future get done => null; @override - Future flush() { - return Future.value(null); + Future flush() { + return Future.value(); } @override diff --git a/packages/flutter_test/lib/src/controller.dart b/packages/flutter_test/lib/src/controller.dart index 0d70e84439..7f7defc70d 100644 --- a/packages/flutter_test/lib/src/controller.dart +++ b/packages/flutter_test/lib/src/controller.dart @@ -256,16 +256,15 @@ abstract class WidgetController { /// /// If the center of the widget is not exposed, this might send events to /// another object. - Future tap(Finder finder, { int pointer }) { + Future tap(Finder finder, { int pointer }) { return tapAt(getCenter(finder), pointer: pointer); } /// Dispatch a pointer down / pointer up sequence at the given location. - Future tapAt(Offset location, { int pointer }) { - return TestAsyncUtils.guard(() async { + Future tapAt(Offset location, { int pointer }) { + return TestAsyncUtils.guard(() 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 longPress(Finder finder, { int pointer }) { + Future 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 longPressAt(Offset location, { int pointer }) { - return TestAsyncUtils.guard(() async { + Future longPressAt(Offset location, { int pointer }) { + return TestAsyncUtils.guard(() 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 fling(Finder finder, Offset offset, double speed, { + Future 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 flingFrom(Offset startLocation, Offset offset, double speed, { + Future 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(() async { + return TestAsyncUtils.guard(() 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 pump(Duration duration); + Future 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 drag(Finder finder, Offset offset, { int pointer }) { + Future 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 dragFrom(Offset startLocation, Offset offset, { int pointer }) { - return TestAsyncUtils.guard(() async { + Future dragFrom(Offset startLocation, Offset offset, { int pointer }) { + return TestAsyncUtils.guard(() 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 sendEventToBinding(PointerEvent event, HitTestResult result) { - return TestAsyncUtils.guard(() async { + Future sendEventToBinding(PointerEvent event, HitTestResult result) { + return TestAsyncUtils.guard(() async { binding.dispatchEvent(event, result); - return null; }); } @@ -538,7 +533,7 @@ class LiveWidgetController extends WidgetController { LiveWidgetController(WidgetsBinding binding) : super(binding); @override - Future pump(Duration duration) async { + Future pump(Duration duration) async { if (duration != null) await Future.delayed(duration); binding.scheduleFrame(); diff --git a/packages/flutter_test/lib/src/matchers.dart b/packages/flutter_test/lib/src/matchers.dart index dda83770fa..15428dad6e 100644 --- a/packages/flutter_test/lib/src/matchers.dart +++ b/packages/flutter_test/lib/src/matchers.dart @@ -1506,7 +1506,7 @@ class _RendersOnPhysicalModel extends _MatchRenderObject { +class _RendersOnPhysicalShape extends _MatchRenderObject { const _RendersOnPhysicalShape({ this.shape, this.elevation, @@ -1607,7 +1607,7 @@ class _ClipsWithBoundingRRect extends _MatchRenderObject { +class _ClipsWithShapeBorder extends _MatchRenderObject { const _ClipsWithShapeBorder({@required this.shape}); final ShapeBorder shape; diff --git a/packages/flutter_test/lib/src/test_pointer.dart b/packages/flutter_test/lib/src/test_pointer.dart index 56f20968e2..dea176dd9d 100644 --- a/packages/flutter_test/lib/src/test_pointer.dart +++ b/packages/flutter_test/lib/src/test_pointer.dart @@ -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 Function(PointerEvent event, HitTestResult result); +typedef EventDispatcher = Future 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(() async { + return TestAsyncUtils.guard(() 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((Null value) { + }).then((void value) { return result; }, onError: (dynamic error, StackTrace stack) { return Future.error(error, stack); @@ -163,14 +162,14 @@ class TestGesture { final TestPointer _pointer; /// Send a move event moving the pointer by the given offset. - Future moveBy(Offset offset, { Duration timeStamp = Duration.zero }) { + Future 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 moveTo(Offset location, { Duration timeStamp = Duration.zero }) { - return TestAsyncUtils.guard(() { + Future moveTo(Offset location, { Duration timeStamp = Duration.zero }) { + return TestAsyncUtils.guard(() { 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 up() { - return TestAsyncUtils.guard(() async { + Future up() { + return TestAsyncUtils.guard(() 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 cancel() { - return TestAsyncUtils.guard(() async { + Future cancel() { + return TestAsyncUtils.guard(() async { assert(_pointer._isDown); await _dispatcher(_pointer.cancel(), _result); assert(!_pointer._isDown); - return null; }); } } diff --git a/packages/flutter_test/lib/src/test_text_input.dart b/packages/flutter_test/lib/src/test_text_input.dart index 851ea9ad44..c6c1dbc7b4 100644 --- a/packages/flutter_test/lib/src/test_text_input.dart +++ b/packages/flutter_test/lib/src/test_text_input.dart @@ -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 receiveAction(TextInputAction action) async { + Future 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 completer = Completer(); + final Completer completer = Completer(); BinaryMessages.handlePlatformMessage( SystemChannels.textInput.name, diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index bac856f5fc..eff3f82da9 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -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 Function(WidgetTester widgetTester); +typedef WidgetTesterCallback = Future Function(WidgetTester widgetTester); /// Runs the [callback] inside the Flutter test environment. /// @@ -114,7 +114,7 @@ void testWidgets(String description, WidgetTesterCallback callback, { /// }); /// exit(0); /// } -Future benchmarkWidgets(WidgetTesterCallback callback) { +Future benchmarkWidgets(WidgetTesterCallback callback) { assert(() { print('┏╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍┓'); print('┇ ⚠ THIS BENCHMARK IS BEING RUN WITH ASSERTS ENABLED ⚠ ┇'); @@ -136,7 +136,7 @@ Future benchmarkWidgets(WidgetTesterCallback callback) { return binding.runTest( () => callback(tester), tester._endOfTestVerifications, - ) ?? Future.value(); + ) ?? Future.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 pumpWidget(Widget widget, [ + Future pumpWidget(Widget widget, [ Duration duration, EnginePhase phase = EnginePhase.sendSemanticsUpdate, ]) { - return TestAsyncUtils.guard(() { + return TestAsyncUtils.guard(() { 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 pump([ + Future pump([ Duration duration, EnginePhase phase = EnginePhase.sendSemanticsUpdate, ]) { - return TestAsyncUtils.guard(() => binding.pump(duration, phase)); + return TestAsyncUtils.guard(() => 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(() async { + return TestAsyncUtils.guard(() 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((Null _) => count); + }).then((void _) => count); } /// Runs a [callback] that performs real asynchronous work. @@ -350,10 +350,9 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker } @override - Future sendEventToBinding(PointerEvent event, HitTestResult result) { - return TestAsyncUtils.guard(() async { + Future sendEventToBinding(PointerEvent event, HitTestResult result) { + return TestAsyncUtils.guard(() 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 idle() { - return TestAsyncUtils.guard(() => binding.idle()); + Future idle() { + return TestAsyncUtils.guard(() => binding.idle()); } Set _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 showKeyboard(Finder finder) async { - return TestAsyncUtils.guard(() async { + Future showKeyboard(Finder finder) async { + return TestAsyncUtils.guard(() async { final EditableTextState editable = state( 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 enterText(Finder finder, String text) async { - return TestAsyncUtils.guard(() async { + Future enterText(Finder finder, String text) async { + return TestAsyncUtils.guard(() async { await showKeyboard(finder); testTextInput.enterText(text); await idle(); diff --git a/packages/flutter_test/test/test_async_utils_test.dart b/packages/flutter_test/test/test_async_utils_test.dart index 3c4f230f21..deffb3b714 100644 --- a/packages/flutter_test/test/test_async_utils_test.dart +++ b/packages/flutter_test/test/test_async_utils_test.dart @@ -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 testGuard1() { - return TestAsyncUtils.guard(() async { return null; }); + Future testGuard1() { + return TestAsyncUtils.guard(() async { return null; }); } - Future testGuard2() { - return TestAsyncUtils.guard(() async { return null; }); + Future testGuard2() { + return TestAsyncUtils.guard(() async { return null; }); } } class TestAPISubclass extends TestAPI { - Future testGuard3() { - return TestAsyncUtils.guard(() async { return null; }); + Future testGuard3() { + return TestAsyncUtils.guard(() async { return null; }); } } -Future _guardedThrower() { - return TestAsyncUtils.guard(() async { +Future _guardedThrower() { + return TestAsyncUtils.guard(() async { throw 'Hello'; }); } @@ -36,7 +36,7 @@ Future _guardedThrower() { void main() { test('TestAsyncUtils - one class', () async { final TestAPI testAPI = TestAPI(); - Future f1, f2; + Future 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 f1, f2; + Future 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 f1, f2; + Future 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 f1; + Future 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 f1, f2; + Future 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 f1; + Future f1; try { f1 = tester.pump(); TestAsyncUtils.verifyAllScopesClosed(); @@ -155,7 +155,7 @@ void main() { }); testWidgets('TestAsyncUtils - expect() catches pending async work', (WidgetTester tester) async { - Future f1; + Future f1; try { f1 = tester.pump(); TestAsyncUtils.verifyAllScopesClosed();