diff --git a/packages/flutter/test/painting/decoration_test.dart b/packages/flutter/test/painting/decoration_test.dart index e85fa68ac6d..2d580e923c6 100644 --- a/packages/flutter/test/painting/decoration_test.dart +++ b/packages/flutter/test/painting/decoration_test.dart @@ -58,6 +58,10 @@ class SynchronousErrorTestImageProvider extends ImageProvider { } class AsyncTestImageProvider extends ImageProvider { + AsyncTestImageProvider(this.image); + + final ui.Image image; + @override Future obtainKey(ImageConfiguration configuration) { return Future.value(2); @@ -66,7 +70,7 @@ class AsyncTestImageProvider extends ImageProvider { @override ImageStreamCompleter load(int key, DecoderCallback decode) { return OneFrameImageStreamCompleter( - Future.value(TestImageInfo(key)) + Future.value(TestImageInfo(key, image: image)) ); } } @@ -147,9 +151,10 @@ void main() { expect(onChangedCalled, equals(false)); }); - test('BoxDecorationImageListenerAsync', () { - FakeAsync().run((FakeAsync async) { - final ImageProvider imageProvider = AsyncTestImageProvider(); + test('BoxDecorationImageListenerAsync', () async { + final ui.Image image = await createTestImage(width: 10, height: 10); + FakeAsync().run((FakeAsync async) { + final ImageProvider imageProvider = AsyncTestImageProvider(image); final DecorationImage backgroundImage = DecorationImage(image: imageProvider); final BoxDecoration boxDecoration = BoxDecoration(image: backgroundImage); diff --git a/packages/flutter/test/painting/fake_codec.dart b/packages/flutter/test/painting/fake_codec.dart index bce09c26b6e..7b9553146fc 100644 --- a/packages/flutter/test/painting/fake_codec.dart +++ b/packages/flutter/test/painting/fake_codec.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:typed_data'; import 'dart:ui' as ui show Codec, FrameInfo, instantiateImageCodec; @@ -28,9 +26,9 @@ class FakeCodec implements ui.Codec { static Future fromData(Uint8List data) async { final ui.Codec codec = await ui.instantiateImageCodec(data); final int frameCount = codec.frameCount; - final List frameInfos = List(frameCount); + final List frameInfos = []; for (int i = 0; i < frameCount; i += 1) - frameInfos[i] = await codec.getNextFrame(); + frameInfos.add(await codec.getNextFrame()); return FakeCodec._(frameCount, codec.repetitionCount, frameInfos); } diff --git a/packages/flutter/test/painting/fake_image_provider.dart b/packages/flutter/test/painting/fake_image_provider.dart index 92dadf965aa..c352adaaab2 100644 --- a/packages/flutter/test/painting/fake_image_provider.dart +++ b/packages/flutter/test/painting/fake_image_provider.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:ui' as ui show Codec; import 'package:flutter/foundation.dart'; diff --git a/packages/flutter/test/painting/image_test_utils.dart b/packages/flutter/test/painting/image_test_utils.dart index 082e8ebbb81..4df2a48c44e 100644 --- a/packages/flutter/test/painting/image_test_utils.dart +++ b/packages/flutter/test/painting/image_test_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'dart:ui' as ui; @@ -19,7 +17,7 @@ class TestImageProvider extends ImageProvider { final ui.Image testImage; final Completer _completer = Completer.sync(); - ImageConfiguration configuration; + ImageConfiguration? configuration; int loadCallCount = 0; @override diff --git a/packages/flutter/test/painting/mocks_for_image_cache.dart b/packages/flutter/test/painting/mocks_for_image_cache.dart index 899254cf588..e868db32b75 100644 --- a/packages/flutter/test/painting/mocks_for_image_cache.dart +++ b/packages/flutter/test/painting/mocks_for_image_cache.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'dart:ui' as ui show Image; @@ -11,7 +9,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/painting.dart'; class TestImageInfo implements ImageInfo { - const TestImageInfo(this.value, { this.image, this.scale = 1.0, this.debugLabel }); + const TestImageInfo(this.value, { required this.image, this.scale = 1.0, this.debugLabel }); @override final ui.Image image; @@ -20,7 +18,7 @@ class TestImageInfo implements ImageInfo { final double scale; @override - final String debugLabel; + final String? debugLabel; final int value; @@ -29,7 +27,7 @@ class TestImageInfo implements ImageInfo { } class TestImageProvider extends ImageProvider { - const TestImageProvider(this.key, this.imageValue, { @required this.image }) + const TestImageProvider(this.key, this.imageValue, { required this.image }) : assert(image != null); final int key; @@ -53,7 +51,7 @@ class TestImageProvider extends ImageProvider { } class FailingTestImageProvider extends TestImageProvider { - const FailingTestImageProvider(int key, int imageValue, { ui.Image image }) : super(key, imageValue, image: image); + const FailingTestImageProvider(int key, int imageValue, { required ui.Image image }) : super(key, imageValue, image: image); @override ImageStreamCompleter load(int key, DecoderCallback decode) { @@ -63,7 +61,7 @@ class FailingTestImageProvider extends TestImageProvider { Future extractOneFrame(ImageStream stream) { final Completer completer = Completer(); - ImageStreamListener listener; + late ImageStreamListener listener; listener = ImageStreamListener((ImageInfo image, bool synchronousCall) { completer.complete(image); stream.removeListener(listener); diff --git a/packages/flutter/test/painting/painting_utils.dart b/packages/flutter/test/painting/painting_utils.dart index fcd1f4748ce..3f23b48fcf0 100644 --- a/packages/flutter/test/painting/painting_utils.dart +++ b/packages/flutter/test/painting/painting_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:typed_data'; import 'dart:ui' as ui; @@ -17,7 +15,7 @@ class PaintingBindingSpy extends BindingBase with SchedulerBinding, ServicesBind int get instantiateImageCodecCalledCount => counter; @override - Future instantiateImageCodec(Uint8List list, {int cacheWidth, int cacheHeight, bool allowUpscaling = false}) { + Future instantiateImageCodec(Uint8List list, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { counter++; return ui.instantiateImageCodec(list); } diff --git a/packages/flutter/test/rendering/mock_canvas.dart b/packages/flutter/test/rendering/mock_canvas.dart index 9aa9c590b68..45447760727 100644 --- a/packages/flutter/test/rendering/mock_canvas.dart +++ b/packages/flutter/test/rendering/mock_canvas.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:ui' as ui show Paragraph, Image; import 'package:flutter/foundation.dart'; @@ -102,14 +100,14 @@ abstract class PaintPattern { /// Calls are skipped until a call to [Canvas.translate] is found. The call's /// arguments are compared to those provided here. If any fail to match, or if /// no call to [Canvas.translate] is found, then the matcher fails. - void translate({ double x, double y }); + void translate({ double? x, double? y }); /// Indicates that a scale transform is expected next. /// /// Calls are skipped until a call to [Canvas.scale] is found. The call's /// arguments are compared to those provided here. If any fail to match, or if /// no call to [Canvas.scale] is found, then the matcher fails. - void scale({ double x, double y }); + void scale({ double? x, double? y }); /// Indicates that a rotate transform is expected next. /// @@ -117,7 +115,7 @@ abstract class PaintPattern { /// argument is provided here, the call's argument is compared to it. If that /// fails to match, or if no call to [Canvas.rotate] is found, then the /// matcher fails. - void rotate({ double angle }); + void rotate({ double? angle }); /// Indicates that a save is expected next. /// @@ -165,7 +163,7 @@ abstract class PaintPattern { /// /// Any calls made between the last matched call (if any) and the /// [Canvas.clipRect] call are ignored. - void clipRect({ Rect rect }); + void clipRect({ Rect? rect }); /// Indicates that a path clip is expected next. /// @@ -177,7 +175,7 @@ abstract class PaintPattern { /// /// Any calls made between the last matched call (if any) and the /// [Canvas.clipPath] call are ignored. - void clipPath({ Matcher pathMatcher }); + void clipPath({ Matcher? pathMatcher }); /// Indicates that a rectangle is expected next. /// @@ -195,7 +193,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void rect({ Rect rect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void rect({ Rect? rect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that a rounded rectangle clip is expected next. /// @@ -207,7 +205,7 @@ abstract class PaintPattern { /// /// Any calls made between the last matched call (if any) and the /// [Canvas.clipRRect] call are ignored. - void clipRRect({ RRect rrect }); + void clipRRect({ RRect? rrect }); /// Indicates that a rounded rectangle is expected next. /// @@ -225,7 +223,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void rrect({ RRect rrect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void rrect({ RRect? rrect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that a rounded rectangle outline is expected next. /// @@ -243,7 +241,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void drrect({ RRect outer, RRect inner, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void drrect({ RRect? outer, RRect? inner, Color? color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); /// Indicates that a circle is expected next. /// @@ -261,7 +259,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void circle({ double x, double y, double radius, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void circle({ double? x, double? y, double? radius, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that a path is expected next. /// @@ -284,7 +282,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void path({ Iterable includes, Iterable excludes, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void path({ Iterable? includes, Iterable? excludes, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that a line is expected next. /// @@ -302,7 +300,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void line({ Offset p1, Offset p2, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void line({ Offset? p1, Offset? p2, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that an arc is expected next. /// @@ -320,7 +318,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void arc({ Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void arc({ Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that a paragraph is expected next. /// @@ -336,7 +334,7 @@ abstract class PaintPattern { /// offset. /// /// If no call to [Canvas.drawParagraph] was made, then this results in failure. - void paragraph({ ui.Paragraph paragraph, dynamic offset }); + void paragraph({ ui.Paragraph? paragraph, dynamic offset }); /// Indicates that a shadow is expected next. /// @@ -357,7 +355,7 @@ abstract class PaintPattern { /// /// Any calls made between the last matched call (if any) and the /// [Canvas.drawShadow] call are ignored. - void shadow({ Iterable includes, Iterable excludes, Color color, double elevation, bool transparentOccluder }); + void shadow({ Iterable? includes, Iterable? excludes, Color? color, double? elevation, bool? transparentOccluder }); /// Indicates that an image is expected next. /// @@ -375,7 +373,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void image({ ui.Image image, double x, double y, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void image({ ui.Image? image, double? x, double? y, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Indicates that an image subsection is expected next. /// @@ -393,7 +391,7 @@ abstract class PaintPattern { /// painting has completed, not at the time of the call. If the same [Paint] /// object is reused multiple times, then this may not match the actual /// arguments as they were seen by the method. - void drawImageRect({ ui.Image image, Rect source, Rect destination, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }); + void drawImageRect({ ui.Image? image, Rect? source, Rect? destination, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }); /// Provides a custom matcher. /// @@ -451,12 +449,12 @@ class _PathMatcher extends Matcher { List excludes; @override - bool matches(Object object, Map matchState) { + bool matches(Object? object, Map matchState) { if (object is! Path) { matchState[this] = 'The given object ($object) was not a Path.'; return false; } - final Path path = object as Path; + final Path path = object; final List errors = [ for (final Offset offset in includes) if (!path.contains(offset)) @@ -500,7 +498,7 @@ class _MismatchedCall { final RecordedInvocation call; } -bool _evaluatePainter(Object object, Canvas canvas, PaintingContext context) { +bool _evaluatePainter(Object? object, Canvas canvas, PaintingContext context) { if (object is _ContextPainterFunction) { final _ContextPainterFunction function = object; function(context, Offset.zero); @@ -510,7 +508,7 @@ bool _evaluatePainter(Object object, Canvas canvas, PaintingContext context) { } else { if (object is Finder) { TestAsyncUtils.guardSync(); - final Finder finder = object as Finder; + final Finder finder = object; object = finder.evaluate().single.renderObject; } if (object is RenderObject) { @@ -525,7 +523,7 @@ bool _evaluatePainter(Object object, Canvas canvas, PaintingContext context) { abstract class _TestRecordingCanvasMatcher extends Matcher { @override - bool matches(Object object, Map matchState) { + bool matches(Object? object, Map matchState) { final TestRecordingCanvas canvas = TestRecordingCanvas(); final TestRecordingPaintingContext context = TestRecordingPaintingContext(canvas); final StringBuffer description = StringBuffer(); @@ -630,7 +628,7 @@ class _TestRecordingCanvasPaintsNothingMatcher extends _TestRecordingCanvasMatch class _TestRecordingCanvasPaintsAssertionMatcher extends Matcher { @override - bool matches(Object object, Map matchState) { + bool matches(Object? object, Map matchState) { final TestRecordingCanvas canvas = TestRecordingCanvas(); final TestRecordingPaintingContext context = TestRecordingPaintingContext(canvas); final StringBuffer description = StringBuffer(); @@ -686,17 +684,17 @@ class _TestRecordingCanvasPatternMatcher extends _TestRecordingCanvasMatcher imp } @override - void translate({ double x, double y }) { + void translate({ double? x, double? y }) { _predicates.add(_FunctionPaintPredicate(#translate, [x, y])); } @override - void scale({ double x, double y }) { + void scale({ double? x, double? y }) { _predicates.add(_FunctionPaintPredicate(#scale, [x, y])); } @override - void rotate({ double angle }) { + void rotate({ double? angle }) { _predicates.add(_FunctionPaintPredicate(#rotate, [angle])); } @@ -716,72 +714,72 @@ class _TestRecordingCanvasPatternMatcher extends _TestRecordingCanvasMatcher imp } @override - void clipRect({ Rect rect }) { + void clipRect({ Rect? rect }) { _predicates.add(_FunctionPaintPredicate(#clipRect, [rect])); } @override - void clipPath({ Matcher pathMatcher }) { + void clipPath({ Matcher? pathMatcher }) { _predicates.add(_FunctionPaintPredicate(#clipPath, [pathMatcher])); } @override - void rect({ Rect rect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void rect({ Rect? rect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_RectPaintPredicate(rect: rect, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void clipRRect({ RRect rrect }) { + void clipRRect({ RRect? rrect }) { _predicates.add(_FunctionPaintPredicate(#clipRRect, [rrect])); } @override - void rrect({ RRect rrect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void rrect({ RRect? rrect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_RRectPaintPredicate(rrect: rrect, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void drrect({ RRect outer, RRect inner, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void drrect({ RRect? outer, RRect? inner, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_DRRectPaintPredicate(outer: outer, inner: inner, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void circle({ double x, double y, double radius, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void circle({ double? x, double? y, double? radius, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_CirclePaintPredicate(x: x, y: y, radius: radius, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void path({ Iterable includes, Iterable excludes, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void path({ Iterable? includes, Iterable? excludes, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_PathPaintPredicate(includes: includes, excludes: excludes, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void line({ Offset p1, Offset p2, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void line({ Offset? p1, Offset? p2, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_LinePaintPredicate(p1: p1, p2: p2, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void arc({ Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void arc({ Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_ArcPaintPredicate(color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void paragraph({ ui.Paragraph paragraph, dynamic offset }) { + void paragraph({ ui.Paragraph? paragraph, dynamic offset }) { _predicates.add(_FunctionPaintPredicate(#drawParagraph, [paragraph, offset])); } @override - void shadow({ Iterable includes, Iterable excludes, Color color, double elevation, bool transparentOccluder }) { + void shadow({ Iterable? includes, Iterable? excludes, Color? color, double? elevation, bool? transparentOccluder }) { _predicates.add(_ShadowPredicate(includes: includes, excludes: excludes, color: color, elevation: elevation, transparentOccluder: transparentOccluder)); } @override - void image({ ui.Image image, double x, double y, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void image({ ui.Image? image, double? x, double? y, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_DrawImagePaintPredicate(image: image, x: x, y: y, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @override - void drawImageRect({ ui.Image image, Rect source, Rect destination, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) { + void drawImageRect({ ui.Image? image, Rect? source, Rect? destination, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) { _predicates.add(_DrawImageRectPaintPredicate(image: image, source: source, destination: destination, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style)); } @@ -892,10 +890,10 @@ abstract class _DrawCommandPaintPredicate extends _PaintPredicate { final String name; final int argumentCount; final int paintArgumentIndex; - final Color color; - final double strokeWidth; - final bool hasMaskFilter; - final PaintingStyle style; + final Color? color; + final double? strokeWidth; + final bool? hasMaskFilter; + final PaintingStyle? style; String get methodName => _symbolName(symbol); @@ -918,7 +916,7 @@ abstract class _DrawCommandPaintPredicate extends _PaintPredicate { if (strokeWidth != null && paintArgument.strokeWidth != strokeWidth) throw 'It called $methodName with a paint whose strokeWidth, ${paintArgument.strokeWidth}, was not exactly the expected strokeWidth ($strokeWidth).'; if (hasMaskFilter != null && (paintArgument.maskFilter != null) != hasMaskFilter) { - if (hasMaskFilter) + if (hasMaskFilter!) throw 'It called $methodName with a paint that did not have a mask filter, despite expecting one.'; else throw 'It called $methodName with a paint that did have a mask filter, despite not expecting one.'; @@ -945,7 +943,7 @@ abstract class _DrawCommandPaintPredicate extends _PaintPredicate { if (strokeWidth != null) description.add('strokeWidth: $strokeWidth'); if (hasMaskFilter != null) - description.add(hasMaskFilter ? 'a mask filter' : 'no mask filter'); + description.add(hasMaskFilter! ? 'a mask filter' : 'no mask filter'); if (style != null) description.add('$style'); } @@ -955,15 +953,15 @@ class _OneParameterPaintPredicate extends _DrawCommandPaintPredicate { _OneParameterPaintPredicate( Symbol symbol, String name, { - @required this.expected, - @required Color color, - @required double strokeWidth, - @required bool hasMaskFilter, - @required PaintingStyle style, + required this.expected, + required Color? color, + required double? strokeWidth, + required bool? hasMaskFilter, + required PaintingStyle? style, }) : super( symbol, name, 2, 1, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style); - final T expected; + final T? expected; @override void verifyArguments(List arguments) { @@ -990,18 +988,18 @@ class _TwoParameterPaintPredicate extends _DrawCommandPaintPredicate { _TwoParameterPaintPredicate( Symbol symbol, String name, { - @required this.expected1, - @required this.expected2, - @required Color color, - @required double strokeWidth, - @required bool hasMaskFilter, - @required PaintingStyle style, + required this.expected1, + required this.expected2, + required Color? color, + required double? strokeWidth, + required bool? hasMaskFilter, + required PaintingStyle? style, }) : super( symbol, name, 3, 2, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style); - final T1 expected1; + final T1? expected1; - final T2 expected2; + final T2? expected2; @override void verifyArguments(List arguments) { @@ -1035,7 +1033,7 @@ class _TwoParameterPaintPredicate extends _DrawCommandPaintPredicate { } class _RectPaintPredicate extends _OneParameterPaintPredicate { - _RectPaintPredicate({ Rect rect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _RectPaintPredicate({ Rect? rect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawRect, 'a rectangle', expected: rect, @@ -1047,7 +1045,7 @@ class _RectPaintPredicate extends _OneParameterPaintPredicate { } class _RRectPaintPredicate extends _DrawCommandPaintPredicate { - _RRectPaintPredicate({ this.rrect, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _RRectPaintPredicate({ this.rrect, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawRRect, 'a rounded rectangle', 2, @@ -1058,7 +1056,7 @@ class _RRectPaintPredicate extends _DrawCommandPaintPredicate { style: style, ); - final RRect rrect; + final RRect? rrect; @override void verifyArguments(List arguments) { @@ -1066,18 +1064,18 @@ class _RRectPaintPredicate extends _DrawCommandPaintPredicate { const double eps = .0001; final RRect actual = arguments[0] as RRect; if (rrect != null && - ((actual.left - rrect.left).abs() > eps || - (actual.right - rrect.right).abs() > eps || - (actual.top - rrect.top).abs() > eps || - (actual.bottom - rrect.bottom).abs() > eps || - (actual.blRadiusX - rrect.blRadiusX).abs() > eps || - (actual.blRadiusY - rrect.blRadiusY).abs() > eps || - (actual.brRadiusX - rrect.brRadiusX).abs() > eps || - (actual.brRadiusY - rrect.brRadiusY).abs() > eps || - (actual.tlRadiusX - rrect.tlRadiusX).abs() > eps || - (actual.tlRadiusY - rrect.tlRadiusY).abs() > eps || - (actual.trRadiusX - rrect.trRadiusX).abs() > eps || - (actual.trRadiusY - rrect.trRadiusY).abs() > eps)) { + ((actual.left - rrect!.left).abs() > eps || + (actual.right - rrect!.right).abs() > eps || + (actual.top - rrect!.top).abs() > eps || + (actual.bottom - rrect!.bottom).abs() > eps || + (actual.blRadiusX - rrect!.blRadiusX).abs() > eps || + (actual.blRadiusY - rrect!.blRadiusY).abs() > eps || + (actual.brRadiusX - rrect!.brRadiusX).abs() > eps || + (actual.brRadiusY - rrect!.brRadiusY).abs() > eps || + (actual.tlRadiusX - rrect!.tlRadiusX).abs() > eps || + (actual.tlRadiusY - rrect!.tlRadiusY).abs() > eps || + (actual.trRadiusX - rrect!.trRadiusX).abs() > eps || + (actual.trRadiusY - rrect!.trRadiusY).abs() > eps)) { throw 'It called $methodName with RRect, $actual, which was not exactly the expected RRect ($rrect).'; } } @@ -1092,7 +1090,7 @@ class _RRectPaintPredicate extends _DrawCommandPaintPredicate { } class _DRRectPaintPredicate extends _TwoParameterPaintPredicate { - _DRRectPaintPredicate({ RRect inner, RRect outer, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _DRRectPaintPredicate({ RRect? inner, RRect? outer, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawDRRect, 'a rounded rectangle outline', expected1: outer, @@ -1105,69 +1103,69 @@ class _DRRectPaintPredicate extends _TwoParameterPaintPredicate { } class _CirclePaintPredicate extends _DrawCommandPaintPredicate { - _CirclePaintPredicate({ this.x, this.y, this.radius, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _CirclePaintPredicate({ this.x, this.y, this.radius, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawCircle, 'a circle', 3, 2, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, ); - final double x; - final double y; - final double radius; + final double? x; + final double? y; + final double? radius; @override void verifyArguments(List arguments) { super.verifyArguments(arguments); final Offset pointArgument = arguments[0] as Offset; if (x != null && y != null) { - final Offset point = Offset(x, y); + final Offset point = Offset(x!, y!); if (point != pointArgument) throw 'It called $methodName with a center coordinate, $pointArgument, which was not exactly the expected coordinate ($point).'; } else { if (x != null && pointArgument.dx != x) - throw 'It called $methodName with a center coordinate, $pointArgument, whose x-coordinate not exactly the expected coordinate (${x.toStringAsFixed(1)}).'; + throw 'It called $methodName with a center coordinate, $pointArgument, whose x-coordinate not exactly the expected coordinate (${x!.toStringAsFixed(1)}).'; if (y != null && pointArgument.dy != y) - throw 'It called $methodName with a center coordinate, $pointArgument, whose y-coordinate not exactly the expected coordinate (${y.toStringAsFixed(1)}).'; + throw 'It called $methodName with a center coordinate, $pointArgument, whose y-coordinate not exactly the expected coordinate (${y!.toStringAsFixed(1)}).'; } final double radiusArgument = arguments[1] as double; if (radius != null && radiusArgument != radius) - throw 'It called $methodName with radius, ${radiusArgument.toStringAsFixed(1)}, which was not exactly the expected radius (${radius.toStringAsFixed(1)}).'; + throw 'It called $methodName with radius, ${radiusArgument.toStringAsFixed(1)}, which was not exactly the expected radius (${radius!.toStringAsFixed(1)}).'; } @override void debugFillDescription(List description) { super.debugFillDescription(description); if (x != null && y != null) { - description.add('point ${Offset(x, y)}'); + description.add('point ${Offset(x!, y!)}'); } else { if (x != null) - description.add('x-coordinate ${x.toStringAsFixed(1)}'); + description.add('x-coordinate ${x!.toStringAsFixed(1)}'); if (y != null) - description.add('y-coordinate ${y.toStringAsFixed(1)}'); + description.add('y-coordinate ${y!.toStringAsFixed(1)}'); } if (radius != null) - description.add('radius ${radius.toStringAsFixed(1)}'); + description.add('radius ${radius!.toStringAsFixed(1)}'); } } class _PathPaintPredicate extends _DrawCommandPaintPredicate { - _PathPaintPredicate({ this.includes, this.excludes, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _PathPaintPredicate({ this.includes, this.excludes, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawPath, 'a path', 2, 1, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, ); - final Iterable includes; - final Iterable excludes; + final Iterable? includes; + final Iterable? excludes; @override void verifyArguments(List arguments) { super.verifyArguments(arguments); final Path pathArgument = arguments[0] as Path; if (includes != null) { - for (final Offset offset in includes) { + for (final Offset offset in includes!) { if (!pathArgument.contains(offset)) throw 'It called $methodName with a path that unexpectedly did not contain $offset.'; } } if (excludes != null) { - for (final Offset offset in excludes) { + for (final Offset offset in excludes!) { if (pathArgument.contains(offset)) throw 'It called $methodName with a path that unexpectedly contained $offset.'; } @@ -1189,12 +1187,12 @@ class _PathPaintPredicate extends _DrawCommandPaintPredicate { // TODO(ianh): add arguments to test the length, angle, that kind of thing class _LinePaintPredicate extends _DrawCommandPaintPredicate { - _LinePaintPredicate({ this.p1, this.p2, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _LinePaintPredicate({ this.p1, this.p2, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawLine, 'a line', 3, 2, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, ); - final Offset p1; - final Offset p2; + final Offset? p1; + final Offset? p2; @override void verifyArguments(List arguments) { @@ -1222,7 +1220,7 @@ class _LinePaintPredicate extends _DrawCommandPaintPredicate { } class _ArcPaintPredicate extends _DrawCommandPaintPredicate { - _ArcPaintPredicate({ Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _ArcPaintPredicate({ Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawArc, 'an arc', 5, 4, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, ); } @@ -1230,11 +1228,11 @@ class _ArcPaintPredicate extends _DrawCommandPaintPredicate { class _ShadowPredicate extends _PaintPredicate { _ShadowPredicate({ this.includes, this.excludes, this.color, this.elevation, this.transparentOccluder }); - final Iterable includes; - final Iterable excludes; - final Color color; - final double elevation; - final bool transparentOccluder; + final Iterable? includes; + final Iterable? excludes; + final Color? color; + final double? elevation; + final bool? transparentOccluder; static const Symbol symbol = #drawShadow; String get methodName => _symbolName(symbol); @@ -1245,13 +1243,13 @@ class _ShadowPredicate extends _PaintPredicate { throw 'It called $methodName with ${arguments.length} arguments; expected 4.'; final Path pathArgument = arguments[0] as Path; if (includes != null) { - for (final Offset offset in includes) { + for (final Offset offset in includes!) { if (!pathArgument.contains(offset)) throw 'It called $methodName with a path that unexpectedly did not contain $offset.'; } } if (excludes != null) { - for (final Offset offset in excludes) { + for (final Offset offset in excludes!) { if (pathArgument.contains(offset)) throw 'It called $methodName with a path that unexpectedly contained $offset.'; } @@ -1303,13 +1301,13 @@ class _ShadowPredicate extends _PaintPredicate { } class _DrawImagePaintPredicate extends _DrawCommandPaintPredicate { - _DrawImagePaintPredicate({ this.image, this.x, this.y, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _DrawImagePaintPredicate({ this.image, this.x, this.y, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawImage, 'an image', 3, 2, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, ); - final ui.Image image; - final double x; - final double y; + final ui.Image? image; + final double? x; + final double? y; @override void verifyArguments(List arguments) { @@ -1319,14 +1317,14 @@ class _DrawImagePaintPredicate extends _DrawCommandPaintPredicate { throw 'It called $methodName with an image, $imageArgument, which was not exactly the expected image ($image).'; final Offset pointArgument = arguments[0] as Offset; if (x != null && y != null) { - final Offset point = Offset(x, y); + final Offset point = Offset(x!, y!); if (point != pointArgument) throw 'It called $methodName with an offset coordinate, $pointArgument, which was not exactly the expected coordinate ($point).'; } else { if (x != null && pointArgument.dx != x) - throw 'It called $methodName with an offset coordinate, $pointArgument, whose x-coordinate not exactly the expected coordinate (${x.toStringAsFixed(1)}).'; + throw 'It called $methodName with an offset coordinate, $pointArgument, whose x-coordinate not exactly the expected coordinate (${x!.toStringAsFixed(1)}).'; if (y != null && pointArgument.dy != y) - throw 'It called $methodName with an offset coordinate, $pointArgument, whose y-coordinate not exactly the expected coordinate (${y.toStringAsFixed(1)}).'; + throw 'It called $methodName with an offset coordinate, $pointArgument, whose y-coordinate not exactly the expected coordinate (${y!.toStringAsFixed(1)}).'; } } @@ -1336,24 +1334,24 @@ class _DrawImagePaintPredicate extends _DrawCommandPaintPredicate { if (image != null) description.add('image $image'); if (x != null && y != null) { - description.add('point ${Offset(x, y)}'); + description.add('point ${Offset(x!, y!)}'); } else { if (x != null) - description.add('x-coordinate ${x.toStringAsFixed(1)}'); + description.add('x-coordinate ${x!.toStringAsFixed(1)}'); if (y != null) - description.add('y-coordinate ${y.toStringAsFixed(1)}'); + description.add('y-coordinate ${y!.toStringAsFixed(1)}'); } } } class _DrawImageRectPaintPredicate extends _DrawCommandPaintPredicate { - _DrawImageRectPaintPredicate({ this.image, this.source, this.destination, Color color, double strokeWidth, bool hasMaskFilter, PaintingStyle style }) : super( + _DrawImageRectPaintPredicate({ this.image, this.source, this.destination, Color? color, double? strokeWidth, bool? hasMaskFilter, PaintingStyle? style }) : super( #drawImageRect, 'an image', 4, 3, color: color, strokeWidth: strokeWidth, hasMaskFilter: hasMaskFilter, style: style, ); - final ui.Image image; - final Rect source; - final Rect destination; + final ui.Image? image; + final Rect? source; + final Rect? destination; @override void verifyArguments(List arguments) { @@ -1500,7 +1498,7 @@ class _SaveRestorePairPaintPredicate extends _PaintPredicate { String toString() => 'a matching save/restore pair'; } -String _valueName(Object value) { +String _valueName(Object? value) { if (value is double) return value.toStringAsFixed(1); return value.toString(); diff --git a/packages/flutter/test/rendering/mouse_tracking_test_utils.dart b/packages/flutter/test/rendering/mouse_tracking_test_utils.dart index 423f36b2860..c122120926c 100644 --- a/packages/flutter/test/rendering/mouse_tracking_test_utils.dart +++ b/packages/flutter/test/rendering/mouse_tracking_test_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:ui' as ui; import 'package:flutter/cupertino.dart'; @@ -20,7 +18,7 @@ class _TestHitTester extends RenderBox { final BoxHitTest hitTestOverride; @override - bool hitTest(BoxHitTestResult result, {ui.Offset position}) { + bool hitTest(BoxHitTestResult result, {required ui.Offset position}) { return hitTestOverride(result, position); } } @@ -39,7 +37,7 @@ class TestMouseTrackerFlutterBinding extends BindingBase renderView.child = _TestHitTester(hitTest); } - SchedulerPhase _overridePhase; + SchedulerPhase? _overridePhase; @override SchedulerPhase get schedulerPhase => _overridePhase ?? super.schedulerPhase; @@ -48,7 +46,7 @@ class TestMouseTrackerFlutterBinding extends BindingBase // In real apps this is done by the renderer binding, but in tests we have to // bypass the phase assertion of [MouseTracker.schedulePostFrameCheck]. void scheduleMouseTrackerPostFrameCheck() { - final SchedulerPhase lastPhase = _overridePhase; + final SchedulerPhase? lastPhase = _overridePhase; _overridePhase = SchedulerPhase.persistentCallbacks; addPostFrameCallback((_) { mouseTracker.updateAllDevices(renderView.hitTestMouseTrackers); @@ -77,13 +75,13 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation const TestAnnotationTarget({this.onEnter, this.onHover, this.onExit, this.cursor = MouseCursor.defer}); @override - final PointerEnterEventListener onEnter; + final PointerEnterEventListener? onEnter; @override - final PointerHoverEventListener onHover; + final PointerHoverEventListener? onHover; @override - final PointerExitEventListener onExit; + final PointerExitEventListener? onExit; @override final MouseCursor cursor; @@ -92,14 +90,14 @@ class TestAnnotationTarget with Diagnosticable implements MouseTrackerAnnotation void handleEvent(PointerEvent event, HitTestEntry entry) { if (event is PointerHoverEvent) if (onHover != null) - onHover(event); + onHover!(event); } } // A hit test entry that can be assigned with a [TestAnnotationTarget] and an // optional transform matrix. class TestAnnotationEntry extends HitTestEntry { - TestAnnotationEntry(TestAnnotationTarget target, [Matrix4 transform]) + TestAnnotationEntry(TestAnnotationTarget target, [Matrix4? transform]) : transform = transform ?? Matrix4.identity(), super(target); @override diff --git a/packages/flutter/test/rendering/recording_canvas.dart b/packages/flutter/test/rendering/recording_canvas.dart index e4956c43dbb..aae6b32e1a8 100644 --- a/packages/flutter/test/rendering/recording_canvas.dart +++ b/packages/flutter/test/rendering/recording_canvas.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/src/rendering/layer.dart'; @@ -13,7 +11,7 @@ import 'package:flutter/src/rendering/layer.dart'; /// Used by [TestRecordingCanvas] to trace canvas calls. class RecordedInvocation { /// Create a record for an invocation list. - const RecordedInvocation(this.invocation, { this.stack }); + const RecordedInvocation(this.invocation, { required this.stack }); /// The method that was called and its arguments. /// @@ -74,7 +72,7 @@ class TestRecordingCanvas implements Canvas { } @override - void saveLayer(Rect bounds, Paint paint) { + void saveLayer(Rect? bounds, Paint paint) { _saveCount += 1; invocations.add(RecordedInvocation(_MethodCall(#saveLayer, [bounds, paint]), stack: StackTrace.current)); } @@ -106,27 +104,27 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex } @override - ClipRectLayer pushClipRect( + ClipRectLayer? pushClipRect( bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.hardEdge, - ClipRectLayer oldLayer, + ClipRectLayer? oldLayer, }) { clipRectAndPaint(clipRect.shift(offset), clipBehavior, clipRect.shift(offset), () => painter(this, offset)); return null; } @override - ClipRRectLayer pushClipRRect( + ClipRRectLayer? pushClipRRect( bool needsCompositing, Offset offset, Rect bounds, RRect clipRRect, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, - ClipRRectLayer oldLayer, + ClipRRectLayer? oldLayer, }) { assert(clipBehavior != null); clipRRectAndPaint(clipRRect.shift(offset), clipBehavior, bounds.shift(offset), () => painter(this, offset)); @@ -134,26 +132,26 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex } @override - ClipPathLayer pushClipPath( + ClipPathLayer? pushClipPath( bool needsCompositing, Offset offset, Rect bounds, Path clipPath, PaintingContextCallback painter, { Clip clipBehavior = Clip.antiAlias, - ClipPathLayer oldLayer, + ClipPathLayer? oldLayer, }) { clipPathAndPaint(clipPath.shift(offset), clipBehavior, bounds.shift(offset), () => painter(this, offset)); return null; } @override - TransformLayer pushTransform( + TransformLayer? pushTransform( bool needsCompositing, Offset offset, Matrix4 transform, PaintingContextCallback painter, { - TransformLayer oldLayer, + TransformLayer? oldLayer, }) { canvas.save(); canvas.transform(transform.storage); @@ -163,17 +161,25 @@ class TestRecordingPaintingContext extends ClipContext implements PaintingContex } @override - OpacityLayer pushOpacity(Offset offset, int alpha, PaintingContextCallback painter, - { OpacityLayer oldLayer }) { - canvas.saveLayer(null, null); // TODO(ianh): Expose the alpha somewhere. + OpacityLayer pushOpacity( + Offset offset, + int alpha, + PaintingContextCallback painter, { + OpacityLayer? oldLayer, + }) { + canvas.saveLayer(null, Paint()); // TODO(ianh): Expose the alpha somewhere. painter(this, offset); canvas.restore(); - return null; + return OpacityLayer(); } @override - void pushLayer(Layer childLayer, PaintingContextCallback painter, Offset offset, - { Rect childPaintBounds }) { + void pushLayer( + Layer childLayer, + PaintingContextCallback painter, + Offset offset, { + Rect? childPaintBounds, + }) { painter(this, offset); } @@ -204,7 +210,7 @@ class _MethodCall implements Invocation { List get typeArguments => _typeArguments; } -String _valueName(Object value) { +String _valueName(Object? value) { if (value is double) return value.toStringAsFixed(1); return value.toString(); @@ -228,7 +234,7 @@ String _describeInvocation(Invocation call) { buffer.write('('); buffer.writeAll(call.positionalArguments.map(_valueName), ', '); String separator = call.positionalArguments.isEmpty ? '' : ', '; - call.namedArguments.forEach((Symbol name, Object value) { + call.namedArguments.forEach((Symbol name, Object? value) { buffer.write(separator); buffer.write(_symbolName(name)); buffer.write(': '); diff --git a/packages/flutter/test/rendering/rendering_tester.dart b/packages/flutter/test/rendering/rendering_tester.dart index 59b2a828ab7..3f5a013da19 100644 --- a/packages/flutter/test/rendering/rendering_tester.dart +++ b/packages/flutter/test/rendering/rendering_tester.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'package:flutter/foundation.dart'; @@ -29,7 +27,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser TestRenderingFlutterBinding({ this.onErrors }) { FlutterError.onError = (FlutterErrorDetails details) { FlutterError.dumpErrorToConsole(details); - Zone.current.parent.handleUncaughtError(details.exception, details.stack); + Zone.current.parent!.handleUncaughtError(details.exception as Object, details.stack!); }; } @@ -40,14 +38,14 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser /// This function is expected to inspect these errors and decide whether they /// are expected or not. Use [takeFlutterErrorDetails] to take one error at a /// time, or [takeAllFlutterErrorDetails] to iterate over all errors. - VoidCallback onErrors; + VoidCallback? onErrors; /// Returns the error least recently caught by [FlutterError] and removes it /// from the list of captured errors. /// /// Returns null if no errors were captures, or if the list was exhausted by /// calling this method repeatedly. - FlutterErrorDetails takeFlutterErrorDetails() { + FlutterErrorDetails? takeFlutterErrorDetails() { if (_errors.isEmpty) { return null; } @@ -87,7 +85,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser @override void drawFrame() { assert(phase != EnginePhase.build, 'rendering_tester does not support testing the build phase; use flutter_test instead'); - final FlutterExceptionHandler oldErrorHandler = FlutterError.onError; + final FlutterExceptionHandler? oldErrorHandler = FlutterError.onError; FlutterError.onError = (FlutterErrorDetails details) { _errors.add(details); }; @@ -113,7 +111,7 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser FlutterError.onError = oldErrorHandler; if (_errors.isNotEmpty) { if (onErrors != null) { - onErrors(); + onErrors!(); if (_errors.isNotEmpty) { _errors.forEach(FlutterError.dumpErrorToConsole); fail('There are more errors than the test inspected using TestRenderingFlutterBinding.takeFlutterErrorDetails.'); @@ -127,11 +125,9 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser } } -TestRenderingFlutterBinding _renderer; -TestRenderingFlutterBinding get renderer { - _renderer ??= TestRenderingFlutterBinding(); - return _renderer; -} +late final TestRenderingFlutterBinding _renderer = TestRenderingFlutterBinding(); +TestRenderingFlutterBinding get renderer => _renderer; + /// Place the box in the render tree, at the given size and with the given /// alignment on the screen. @@ -149,10 +145,10 @@ TestRenderingFlutterBinding get renderer { /// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError]. void layout( RenderBox box, { - BoxConstraints constraints, + BoxConstraints? constraints, Alignment alignment = Alignment.center, EnginePhase phase = EnginePhase.layout, - VoidCallback onErrors, + VoidCallback? onErrors, }) { assert(box != null); // If you want to just repump the last box, call pumpFrame(). assert(box.parent == null); // We stick the box in another, so you can't reuse it easily, sorry. @@ -175,7 +171,7 @@ void layout( /// Pumps a single frame. /// /// If `onErrors` is not null, it is set as [TestRenderingFlutterBinding.onError]. -void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback onErrors }) { +void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback? onErrors }) { assert(renderer != null); assert(renderer.renderView != null); assert(renderer.renderView.child != null); // call layout() first! @@ -189,7 +185,7 @@ void pumpFrame({ EnginePhase phase = EnginePhase.layout, VoidCallback onErrors } } class TestCallbackPainter extends CustomPainter { - const TestCallbackPainter({ this.onPaint }); + const TestCallbackPainter({ required this.onPaint }); final VoidCallback onPaint; @@ -251,25 +247,25 @@ class FakeTickerProvider implements TickerProvider { class FakeTicker implements Ticker { @override - bool muted; + bool muted = false; @override void absorbTicker(Ticker originalTicker) { } @override - String get debugLabel => null; + String? get debugLabel => null; @override - bool get isActive => null; + bool get isActive => throw UnimplementedError(); @override - bool get isTicking => null; + bool get isTicking => throw UnimplementedError(); @override - bool get scheduled => null; + bool get scheduled => throw UnimplementedError(); @override - bool get shouldScheduleTick => null; + bool get shouldScheduleTick => throw UnimplementedError(); @override void dispose() { } @@ -279,7 +275,7 @@ class FakeTicker implements Ticker { @override TickerFuture start() { - return null; + throw UnimplementedError(); } @override @@ -301,7 +297,14 @@ class TestClipPaintingContext extends PaintingContext { TestClipPaintingContext() : super(ContainerLayer(), Rect.zero); @override - ClipRectLayer pushClipRect(bool needsCompositing, Offset offset, Rect clipRect, PaintingContextCallback painter, {Clip clipBehavior = Clip.hardEdge, ClipRectLayer oldLayer}) { + ClipRectLayer? pushClipRect( + bool needsCompositing, + Offset offset, + Rect clipRect, + PaintingContextCallback painter, { + Clip clipBehavior = Clip.hardEdge, + ClipRectLayer? oldLayer, + }) { this.clipBehavior = clipBehavior; return null; } @@ -310,7 +313,7 @@ class TestClipPaintingContext extends PaintingContext { } void expectOverflowedErrors() { - final FlutterErrorDetails errorDetails = renderer.takeFlutterErrorDetails(); + final FlutterErrorDetails errorDetails = renderer.takeFlutterErrorDetails()!; final bool overflowed = errorDetails.toString().contains('overflowed'); if (!overflowed) { FlutterError.reportError(errorDetails); diff --git a/packages/flutter/test/services/restoration.dart b/packages/flutter/test/services/restoration.dart index a12945b4b69..0ae914da4ae 100644 --- a/packages/flutter/test/services/restoration.dart +++ b/packages/flutter/test/services/restoration.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:typed_data'; import 'package:flutter/services.dart'; @@ -53,15 +51,15 @@ class MockRestorationManager extends TestRestorationManager { int rootBucketAccessed = 0; @override - Future get rootBucket { + Future get rootBucket { rootBucketAccessed++; return _rootBucket; } - Future _rootBucket; - set rootBucket(Future value) { + late Future _rootBucket; + set rootBucket(Future value) { _rootBucket = value; _isRestoring = true; - ServicesBinding.instance.addPostFrameCallback((Duration _) { + ServicesBinding.instance!.addPostFrameCallback((Duration _) { _isRestoring = false; }); notifyListeners(); @@ -69,7 +67,7 @@ class MockRestorationManager extends TestRestorationManager { @override bool get isReplacing => _isRestoring; - bool _isRestoring; + bool _isRestoring = false; @override Future sendToEngine(Uint8List encodedData) { diff --git a/packages/flutter/test/widgets/editable_text_utils.dart b/packages/flutter/test/widgets/editable_text_utils.dart index 0b5f0735b9a..e012fe1b835 100644 --- a/packages/flutter/test/widgets/editable_text_utils.dart +++ b/packages/flutter/test/widgets/editable_text_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; @@ -13,7 +11,7 @@ RenderEditable findRenderEditable(WidgetTester tester) { final RenderObject root = tester.renderObject(find.byType(EditableText)); expect(root, isNotNull); - RenderEditable renderEditable; + late RenderEditable renderEditable; void recursiveFinder(RenderObject child) { if (child is RenderEditable) { renderEditable = child; diff --git a/packages/flutter/test/widgets/gesture_utils.dart b/packages/flutter/test/widgets/gesture_utils.dart index 528181a1342..ceef32c8ca7 100644 --- a/packages/flutter/test/widgets/gesture_utils.dart +++ b/packages/flutter/test/widgets/gesture_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/gestures.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/widgets/observer_tester.dart b/packages/flutter/test/widgets/observer_tester.dart index 99a694ad338..f2ccbf872bd 100644 --- a/packages/flutter/test/widgets/observer_tester.dart +++ b/packages/flutter/test/widgets/observer_tester.dart @@ -2,49 +2,47 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/material.dart'; -typedef OnObservation = void Function(Route route, Route previousRoute); +typedef OnObservation = void Function(Route? route, Route? previousRoute); /// A trivial observer for testing the navigator. class TestObserver extends NavigatorObserver { - OnObservation onPushed; - OnObservation onPopped; - OnObservation onRemoved; - OnObservation onReplaced; - OnObservation onStartUserGesture; + OnObservation? onPushed; + OnObservation? onPopped; + OnObservation? onRemoved; + OnObservation? onReplaced; + OnObservation? onStartUserGesture; @override - void didPush(Route route, Route previousRoute) { + void didPush(Route route, Route? previousRoute) { if (onPushed != null) { - onPushed(route, previousRoute); + onPushed!(route, previousRoute); } } @override - void didPop(Route route, Route previousRoute) { + void didPop(Route route, Route? previousRoute) { if (onPopped != null) { - onPopped(route, previousRoute); + onPopped!(route, previousRoute); } } @override - void didRemove(Route route, Route previousRoute) { + void didRemove(Route route, Route? previousRoute) { if (onRemoved != null) - onRemoved(route, previousRoute); + onRemoved!(route, previousRoute); } @override - void didReplace({ Route oldRoute, Route newRoute }) { + void didReplace({ Route? oldRoute, Route? newRoute }) { if (onReplaced != null) - onReplaced(newRoute, oldRoute); + onReplaced!(newRoute, oldRoute); } @override - void didStartUserGesture(Route route, Route previousRoute) { + void didStartUserGesture(Route route, Route? previousRoute) { if (onStartUserGesture != null) - onStartUserGesture(route, previousRoute); + onStartUserGesture!(route, previousRoute); } } diff --git a/packages/flutter/test/widgets/restoration.dart b/packages/flutter/test/widgets/restoration.dart index 7b82d6a4cdc..cef79725fd0 100644 --- a/packages/flutter/test/widgets/restoration.dart +++ b/packages/flutter/test/widgets/restoration.dart @@ -2,24 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; export '../services/restoration.dart'; class BucketSpy extends StatefulWidget { - const BucketSpy({Key key, this.child}) : super(key: key); + const BucketSpy({Key? key, this.child}) : super(key: key); - final Widget child; + final Widget? child; @override State createState() => BucketSpyState(); } class BucketSpyState extends State { - RestorationBucket bucket; + RestorationBucket? bucket; @override void didChangeDependencies() { diff --git a/packages/flutter/test/widgets/semantics_tester.dart b/packages/flutter/test/widgets/semantics_tester.dart index 2a36463a0bc..dfeb6234564 100644 --- a/packages/flutter/test/widgets/semantics_tester.dart +++ b/packages/flutter/test/widgets/semantics_tester.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:ui' show SemanticsFlag; import 'package:flutter/foundation.dart'; @@ -54,7 +52,7 @@ class TestSemantics { this.children = const [], this.scrollIndex, this.scrollChildren, - Iterable tags, + Iterable? tags, }) : assert(flags is int || flags is List), assert(actions is int || actions is List), assert(label != null), @@ -81,7 +79,7 @@ class TestSemantics { this.children = const [], this.scrollIndex, this.scrollChildren, - Iterable tags, + Iterable? tags, }) : id = 0, assert(flags is int || flags is List), assert(actions is int || actions is List), @@ -116,14 +114,14 @@ class TestSemantics { this.decreasedValue = '', this.textDirection, this.rect, - Matrix4 transform, + Matrix4? transform, this.elevation, this.thickness, this.textSelection, this.children = const [], this.scrollIndex, this.scrollChildren, - Iterable tags, + Iterable? tags, }) : assert(flags is int || flags is List), assert(actions is int || actions is List), assert(label != null), @@ -139,7 +137,7 @@ class TestSemantics { /// /// The root node has an id of zero. Other nodes are given a unique id when /// they are created. - final int id; + final int? id; /// The [SemanticsFlag]s set on this node. /// @@ -183,7 +181,7 @@ class TestSemantics { /// Even if this is not set, the [hasSemantics] matcher will verify that if a /// label is present on the [SemanticsNode], a [SemanticsNode.textDirection] /// is also set. - final TextDirection textDirection; + final TextDirection? textDirection; /// The bounding box for this node in its coordinate system. /// @@ -194,7 +192,7 @@ class TestSemantics { /// /// * [TestSemantics.fullScreen] 800x600, the test screen's size in logical /// pixels, useful for other full-screen widgets. - final Rect rect; + final Rect? rect; /// The test screen's size in physical pixels, typically used as the [rect] /// for the node with id zero. @@ -214,7 +212,7 @@ class TestSemantics { /// By default, the transform is null, which represents the identity /// transformation (i.e., that this node has the same coordinate system as its /// parent). - final Matrix4 transform; + final Matrix4? transform; /// The elevation of this node relative to the parent node. /// @@ -222,24 +220,24 @@ class TestSemantics { /// /// * [SemanticsConfiguration.elevation] for a detailed discussion regarding /// elevation and semantics. - final double elevation; + final double? elevation; /// The extend that this node occupies in z-direction starting at [elevation]. /// /// See also: /// /// * [SemanticsConfiguration.thickness] for a more detailed definition. - final double thickness; + final double? thickness; /// The index of the first visible semantic node within a scrollable. - final int scrollIndex; + final int? scrollIndex; /// The total number of semantic nodes within a scrollable. - final int scrollChildren; + final int? scrollChildren; - final TextSelection textSelection; + final TextSelection? textSelection; - static Matrix4 _applyRootChildScale(Matrix4 transform) { + static Matrix4 _applyRootChildScale(Matrix4? transform) { final Matrix4 result = Matrix4.diagonal3Values(3.0, 3.0, 1.0); if (transform != null) result.multiply(transform); @@ -253,7 +251,7 @@ class TestSemantics { final Set tags; bool _matches( - SemanticsNode node, + SemanticsNode? node, Map matchState, { bool ignoreRect = false, bool ignoreTransform = false, @@ -370,7 +368,7 @@ class TestSemantics { if (textDirection != null) buf.writeln('$indent textDirection: $textDirection,'); if (textSelection?.isValid == true) - buf.writeln('$indent textSelection:\n[${textSelection.start}, ${textSelection.end}],'); + buf.writeln('$indent textSelection:\n[${textSelection!.start}, ${textSelection!.end}],'); if (scrollIndex != null) buf.writeln('$indent scrollIndex: $scrollIndex,'); if (rect != null) @@ -413,7 +411,7 @@ class SemanticsTester { /// The widget tester that this object is testing the semantics of. final WidgetTester tester; - SemanticsHandle _semanticsHandle; + SemanticsHandle? _semanticsHandle; /// Release resources held by this semantics tester. /// @@ -437,18 +435,18 @@ class SemanticsTester { /// /// If `ancestor` is not null, only the descendants of it are returned. Iterable nodesWith({ - String label, - String value, - String hint, - TextDirection textDirection, - List actions, - List flags, - double scrollPosition, - double scrollExtentMax, - double scrollExtentMin, - int currentValueLength, - int maxValueLength, - SemanticsNode ancestor, + String? label, + String? value, + String? hint, + TextDirection? textDirection, + List? actions, + List? flags, + double? scrollPosition, + double? scrollExtentMax, + double? scrollExtentMin, + int? currentValueLength, + int? maxValueLength, + SemanticsNode? ancestor, }) { bool checkNode(SemanticsNode node) { if (label != null && node.label != label) @@ -497,7 +495,7 @@ class SemanticsTester { if (ancestor != null) { visit(ancestor); } else { - visit(tester.binding.pipelineOwner.semanticsOwner.rootSemanticsNode); + visit(tester.binding.pipelineOwner.semanticsOwner!.rootSemanticsNode!); } return result; } @@ -551,7 +549,7 @@ class SemanticsTester { /// over-test. Prefer breaking your widgets into smaller widgets and test them /// individually. String generateTestSemanticsExpressionForCurrentSemanticsTree(DebugSemanticsDumpOrder childOrder) { - final SemanticsNode node = tester.binding.pipelineOwner.semanticsOwner?.rootSemanticsNode; + final SemanticsNode? node = tester.binding.pipelineOwner.semanticsOwner?.rootSemanticsNode; return _generateSemanticsTestForNode(node, 0, childOrder); } @@ -583,7 +581,7 @@ class SemanticsTester { /// Recursively generates [TestSemantics] code for [node] and its children, /// indenting the expression by `indentAmount`. - static String _generateSemanticsTestForNode(SemanticsNode node, int indentAmount, DebugSemanticsDumpOrder childOrder) { + static String _generateSemanticsTestForNode(SemanticsNode? node, int indentAmount, DebugSemanticsDumpOrder childOrder) { if (node == null) return 'null'; final String indent = ' ' * indentAmount; @@ -594,7 +592,7 @@ class SemanticsTester { if (!isRoot) buf.writeln(' id: ${node.id},'); if (nodeData.tags != null) - buf.writeln(' tags: ${_tagsToSemanticsTagExpression(nodeData.tags)},'); + buf.writeln(' tags: ${_tagsToSemanticsTagExpression(nodeData.tags!)},'); if (nodeData.flags != 0) buf.writeln(' flags: ${_flagsToSemanticsFlagExpression(nodeData.flags)},'); if (nodeData.actions != 0) @@ -635,10 +633,10 @@ class SemanticsTester { class _HasSemantics extends Matcher { const _HasSemantics( this._semantics, { - @required this.ignoreRect, - @required this.ignoreTransform, - @required this.ignoreId, - @required this.childOrder, + required this.ignoreRect, + required this.ignoreTransform, + required this.ignoreId, + required this.childOrder, }) : assert(_semantics != null), assert(ignoreRect != null), assert(ignoreId != null), @@ -675,7 +673,7 @@ class _HasSemantics extends Matcher { return description.add('semantics node matching:\n$_semantics'); } - String _indent(String text) { + String _indent(String? text) { return text.toString().trimRight().split('\n').map((String line) => ' $line').join('\n'); } @@ -684,7 +682,7 @@ class _HasSemantics extends Matcher { Description result = mismatchDescription .add('${matchState[TestSemantics]}\n') .add('Current SemanticsNode tree:\n') - .add(_indent(RendererBinding.instance?.renderView?.debugSemantics?.toStringDeep(childOrder: childOrder))) + .add(_indent(RendererBinding.instance?.renderView.debugSemantics?.toStringDeep(childOrder: childOrder))) .add('\n') .add('The semantics tree would have matched the following configuration:\n') .add(_indent(matchState['would-match'] as String)); @@ -739,17 +737,17 @@ class _IncludesNodeWith extends Matcher { currentValueLength != null ); - final String label; - final String value; - final String hint; - final TextDirection textDirection; - final List actions; - final List flags; - final double scrollPosition; - final double scrollExtentMax; - final double scrollExtentMin; - final int currentValueLength; - final int maxValueLength; + final String? label; + final String? value; + final String? hint; + final TextDirection? textDirection; + final List? actions; + final List? flags; + final double? scrollPosition; + final double? scrollExtentMax; + final double? scrollExtentMin; + final int? currentValueLength; + final int? maxValueLength; @override bool matches(covariant SemanticsTester item, Map matchState) { @@ -783,9 +781,9 @@ class _IncludesNodeWith extends Matcher { if (label != null) 'label "$label"', if (value != null) 'value "$value"', if (hint != null) 'hint "$hint"', - if (textDirection != null) ' (${describeEnum(textDirection)})', - if (actions != null) 'actions "${actions.join(', ')}"', - if (flags != null) 'flags "${flags.join(', ')}"', + if (textDirection != null) ' (${describeEnum(textDirection!)})', + if (actions != null) 'actions "${actions!.join(', ')}"', + if (flags != null) 'flags "${flags!.join(', ')}"', if (scrollPosition != null) 'scrollPosition "$scrollPosition"', if (scrollExtentMax != null) 'scrollExtentMax "$scrollExtentMax"', if (scrollExtentMin != null) 'scrollExtentMin "$scrollExtentMin"', @@ -801,17 +799,17 @@ class _IncludesNodeWith extends Matcher { /// /// If null is provided for an argument, it will match against any value. Matcher includesNodeWith({ - String label, - String value, - String hint, - TextDirection textDirection, - List actions, - List flags, - double scrollPosition, - double scrollExtentMax, - double scrollExtentMin, - int maxValueLength, - int currentValueLength, + String? label, + String? value, + String? hint, + TextDirection? textDirection, + List? actions, + List? flags, + double? scrollPosition, + double? scrollExtentMax, + double? scrollExtentMin, + int? maxValueLength, + int? currentValueLength, }) { return _IncludesNodeWith( label: label, diff --git a/packages/flutter/test/widgets/states.dart b/packages/flutter/test/widgets/states.dart index 76064a6cb98..02d38fea48a 100644 --- a/packages/flutter/test/widgets/states.dart +++ b/packages/flutter/test/widgets/states.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - const List kStates = [ 'Alabama', 'Alaska', diff --git a/packages/flutter/test/widgets/test_border.dart b/packages/flutter/test/widgets/test_border.dart index 26b9dac888f..51923eb1a92 100644 --- a/packages/flutter/test/widgets/test_border.dart +++ b/packages/flutter/test/widgets/test_border.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter/material.dart'; typedef Logger = void Function(String caller); @@ -20,19 +18,19 @@ class TestBorder extends ShapeBorder { ShapeBorder scale(double t) => TestBorder(onLog); @override - Path getInnerPath(Rect rect, { TextDirection textDirection }) { + Path getInnerPath(Rect rect, { TextDirection? textDirection }) { onLog('getInnerPath $rect $textDirection'); return Path(); } @override - Path getOuterPath(Rect rect, { TextDirection textDirection }) { + Path getOuterPath(Rect rect, { TextDirection? textDirection }) { onLog('getOuterPath $rect $textDirection'); return Path(); } @override - void paint(Canvas canvas, Rect rect, { TextDirection textDirection }) { + void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { onLog('paint $rect $textDirection'); } } diff --git a/packages/flutter/test/widgets/test_widgets.dart b/packages/flutter/test/widgets/test_widgets.dart index 3ec1db94969..518d43f9490 100644 --- a/packages/flutter/test/widgets/test_widgets.dart +++ b/packages/flutter/test/widgets/test_widgets.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -21,7 +19,7 @@ const BoxDecoration kBoxDecorationC = BoxDecoration( ); class TestBuildCounter extends StatelessWidget { - const TestBuildCounter({ Key key }) : super(key: key); + const TestBuildCounter({ Key? key }) : super(key: key); static int buildCount = 0; @@ -34,7 +32,7 @@ class TestBuildCounter extends StatelessWidget { class FlipWidget extends StatefulWidget { - const FlipWidget({ Key key, this.left, this.right }) : super(key: key); + const FlipWidget({ Key? key, required this.left, required this.right }) : super(key: key); final Widget left; final Widget right; diff --git a/packages/flutter/test/widgets/text.dart b/packages/flutter/test/widgets/text.dart index deb8bde7866..4ccca393ae5 100644 --- a/packages/flutter/test/widgets/text.dart +++ b/packages/flutter/test/widgets/text.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -14,7 +12,7 @@ RenderEditable findRenderEditable(WidgetTester tester) { final RenderObject root = tester.renderObject(find.byType(EditableText)); expect(root, isNotNull); - RenderEditable renderEditable; + late RenderEditable renderEditable; void recursiveFinder(RenderObject child) { if (child is RenderEditable) { renderEditable = child; diff --git a/packages/flutter/test/widgets/widget_inspector_test_utils.dart b/packages/flutter/test/widgets/widget_inspector_test_utils.dart index 3ce8dd4b921..be12aed1b99 100644 --- a/packages/flutter/test/widgets/widget_inspector_test_utils.dart +++ b/packages/flutter/test/widgets/widget_inspector_test_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'dart:convert'; @@ -12,48 +10,46 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; -typedef InspectorServiceExtensionCallback = FutureOr> Function(Map parameters); - class TestWidgetInspectorService extends Object with WidgetInspectorService { - final Map extensions = {}; + final Map extensions = {}; - final Map>> eventsDispatched = >>{}; + final Map>> eventsDispatched = >>{}; @override void registerServiceExtension({ - @required String name, - @required FutureOr> callback(Map parameters), + required String name, + required ServiceExtensionCallback callback, }) { assert(!extensions.containsKey(name)); extensions[name] = callback; } @override - void postEvent(String eventKind, Map eventData) { + void postEvent(String eventKind, Map eventData) { getEventsDispatched(eventKind).add(eventData); } - List> getEventsDispatched(String eventKind) { + List> getEventsDispatched(String eventKind) { return eventsDispatched.putIfAbsent(eventKind, () => >[]); } - Iterable> getServiceExtensionStateChangedEvents(String extensionName) { + Iterable> getServiceExtensionStateChangedEvents(String extensionName) { return getEventsDispatched('Flutter.ServiceExtensionStateChanged') - .where((Map event) => event['extension'] == extensionName); + .where((Map event) => event['extension'] == extensionName); } - Future testExtension(String name, Map arguments) async { + Future testExtension(String name, Map arguments) async { expect(extensions, contains(name)); // Encode and decode to JSON to match behavior using a real service // extension where only JSON is allowed. - return json.decode(json.encode(await extensions[name](arguments)))['result']; + return json.decode(json.encode(await extensions[name]!(arguments)))['result']; } Future testBoolExtension(String name, Map arguments) async { expect(extensions, contains(name)); // Encode and decode to JSON to match behavior using a real service // extension where only JSON is allowed. - return json.decode(json.encode(await extensions[name](arguments)))['enabled'] as String; + return json.decode(json.encode(await extensions[name]!(arguments)))['enabled'] as String; } int rebuildCount = 0; @@ -61,10 +57,10 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService { @override Future forceRebuild() async { rebuildCount++; - final WidgetsBinding binding = WidgetsBinding.instance; + final WidgetsBinding binding = WidgetsBinding.instance!; if (binding.renderViewElement != null) { - binding.buildOwner.reassemble(binding.renderViewElement); + binding.buildOwner!.reassemble(binding.renderViewElement!); } } }