diff --git a/packages/flutter/lib/src/painting/image_provider.dart b/packages/flutter/lib/src/painting/image_provider.dart index 48d6e2bd8e..110ca73540 100644 --- a/packages/flutter/lib/src/painting/image_provider.dart +++ b/packages/flutter/lib/src/painting/image_provider.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; diff --git a/packages/flutter/test/painting/flutter_logo_test.dart b/packages/flutter/test/painting/flutter_logo_test.dart index f9d64866c2..c7d0efde2c 100644 --- a/packages/flutter/test/painting/flutter_logo_test.dart +++ b/packages/flutter/test/painting/flutter_logo_test.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/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/painting.dart'; @@ -23,26 +21,26 @@ void main() { ); test('FlutterLogoDecoration lerp from null to null is null', () { - final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(null, null, 0.5); + final FlutterLogoDecoration? logo = FlutterLogoDecoration.lerp(null, null, 0.5); expect(logo, isNull); }); test('FlutterLogoDecoration lerp from non-null to null lerps margin', () { - final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, null, 0.4); + final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, null, 0.4)!; expect(logo.textColor, start.textColor); expect(logo.style, start.style); expect(logo.margin, start.margin * 0.4); }); test('FlutterLogoDecoration lerp from null to non-null lerps margin', () { - final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(null, end, 0.6); + final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(null, end, 0.6)!; expect(logo.textColor, end.textColor); expect(logo.style, end.style); expect(logo.margin, end.margin * 0.6); }); test('FlutterLogoDecoration lerps colors and margins', () { - final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.5); + final FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.5)!; expect(logo.textColor, Color.lerp(start.textColor, end.textColor, 0.5)); expect(logo.margin, EdgeInsets.lerp(start.margin, end.margin, 0.5)); }); @@ -55,10 +53,10 @@ void main() { }); test('FlutterLogoDecoration lerp changes styles at 0.5', () { - FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.4); + FlutterLogoDecoration logo = FlutterLogoDecoration.lerp(start, end, 0.4)!; expect(logo.style, start.style); - logo = FlutterLogoDecoration.lerp(start, end, 0.5); + logo = FlutterLogoDecoration.lerp(start, end, 0.5)!; expect(logo.style, end.style); }); diff --git a/packages/flutter/test/painting/fractional_offset_test.dart b/packages/flutter/test/painting/fractional_offset_test.dart index a7ba3ea4a1..12ddad539b 100644 --- a/packages/flutter/test/painting/fractional_offset_test.dart +++ b/packages/flutter/test/painting/fractional_offset_test.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/painting.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/painting/geometry_test.dart b/packages/flutter/test/painting/geometry_test.dart index 7f066b4a0f..9f20ccc3da 100644 --- a/packages/flutter/test/painting/geometry_test.dart +++ b/packages/flutter/test/painting/geometry_test.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/painting.dart'; import '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/painting/gradient_test.dart b/packages/flutter/test/painting/gradient_test.dart index 595d9db5be..4503825312 100644 --- a/packages/flutter/test/painting/gradient_test.dart +++ b/packages/flutter/test/painting/gradient_test.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:math' as math; import 'package:flutter/widgets.dart'; @@ -21,7 +19,7 @@ void main() { Color(0x44444444), ], ); - final LinearGradient actual = LinearGradient.lerp(null, testGradient, 0.25); + final LinearGradient? actual = LinearGradient.lerp(null, testGradient, 0.25); expect(actual, const LinearGradient( begin: Alignment.bottomRight, @@ -52,7 +50,7 @@ void main() { ], ); - final LinearGradient actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); + final LinearGradient? actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const LinearGradient( begin: Alignment(0.0, -1.0), end: Alignment(-1.0, 0.0), @@ -90,7 +88,7 @@ void main() { ], ); - final LinearGradient actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); + final LinearGradient? actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const LinearGradient( begin: Alignment(0.0, -1.0), end: Alignment(-1.0, 0.0), @@ -122,7 +120,7 @@ void main() { ], ); - final LinearGradient actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); + final LinearGradient? actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const LinearGradient( colors: [ Color(0x33333333), @@ -161,7 +159,7 @@ void main() { ], ); - final LinearGradient actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); + final LinearGradient? actual = LinearGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const LinearGradient( colors: [ Color(0x3B3B3B3B), @@ -291,7 +289,7 @@ void main() { ], ); - final RadialGradient actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); + final RadialGradient? actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const RadialGradient( center: Alignment(0.0, -1.0), radius: 15.0, @@ -332,9 +330,7 @@ void main() { ], ); - final RadialGradient actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); - - expect(actual.focal, isNull); + final RadialGradient? actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const RadialGradient( center: Alignment(0.0, -1.0), @@ -350,6 +346,8 @@ void main() { 1.0, ], )); + + expect(actual!.focal, isNull); }); test('RadialGradient lerp test with unequal number of colors', () { @@ -367,7 +365,7 @@ void main() { ], ); - final RadialGradient actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); + final RadialGradient? actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const RadialGradient( colors: [ Color(0x33333333), @@ -406,7 +404,7 @@ void main() { ], ); - final RadialGradient actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); + final RadialGradient? actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const RadialGradient( colors: [ Color(0x3B3B3B3B), @@ -453,7 +451,7 @@ void main() { ], ); - final RadialGradient actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); + final RadialGradient? actual = RadialGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const RadialGradient( center: Alignment(0.0, -1.0), focal: Alignment(0.0, 0.0), @@ -469,7 +467,7 @@ void main() { ], )); - final RadialGradient actual2 = RadialGradient.lerp(testGradient1, testGradient3, 0.5); + final RadialGradient? actual2 = RadialGradient.lerp(testGradient1, testGradient3, 0.5); expect(actual2, const RadialGradient( center: Alignment(0.0, -1.0), focal: Alignment(-0.5, 0.0), @@ -506,7 +504,7 @@ void main() { ], ); - final SweepGradient actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); + final SweepGradient? actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const SweepGradient( center: Alignment(0.0, -1.0), startAngle: math.pi / 4, @@ -550,7 +548,7 @@ void main() { ], ); - final SweepGradient actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); + final SweepGradient? actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const SweepGradient( center: Alignment(0.0, -1.0), startAngle: math.pi / 4, @@ -583,7 +581,7 @@ void main() { ], ); - final SweepGradient actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); + final SweepGradient? actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const SweepGradient( colors: [ Color(0x33333333), @@ -622,7 +620,7 @@ void main() { ], ); - final SweepGradient actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); + final SweepGradient? actual = SweepGradient.lerp(testGradient1, testGradient2, 0.5); expect(actual, const SweepGradient( colors: [ Color(0x3B3B3B3B), diff --git a/packages/flutter/test/painting/image_cache_binding_test.dart b/packages/flutter/test/painting/image_cache_binding_test.dart index bb0aefa46d..4ca25b0f38 100644 --- a/packages/flutter/test/painting/image_cache_binding_test.dart +++ b/packages/flutter/test/painting/image_cache_binding_test.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/foundation.dart'; @@ -13,7 +11,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; - void main() { test('PaintingBinding with memory pressure before initInstances', () { // Observed in devicelab: the device sends a memory pressure event to us @@ -25,7 +22,7 @@ void main() { expect(binding.imageCache, null); binding.initInstances(); expect(binding.imageCache, isNotNull); - expect(binding.imageCache.currentSize, 0); + expect(binding.imageCache!.currentSize, 0); }); } @@ -56,19 +53,19 @@ class TestBindingBase implements BindingBase { } @override - void registerBoolServiceExtension({String name, AsyncValueGetter getter, AsyncValueSetter setter}) {} + void registerBoolServiceExtension({required String name, required AsyncValueGetter getter, required AsyncValueSetter setter}) {} @override - void registerNumericServiceExtension({String name, AsyncValueGetter getter, AsyncValueSetter setter}) {} + void registerNumericServiceExtension({required String name, required AsyncValueGetter getter, required AsyncValueSetter setter}) {} @override - void registerServiceExtension({String name, ServiceExtensionCallback callback}) {} + void registerServiceExtension({required String name, required ServiceExtensionCallback callback}) {} @override - void registerSignalServiceExtension({String name, AsyncCallback callback}) {} + void registerSignalServiceExtension({required String name, required AsyncCallback callback}) {} @override - void registerStringServiceExtension({String name, AsyncValueGetter getter, AsyncValueSetter setter}) {} + void registerStringServiceExtension({required String name, required AsyncValueGetter getter, required AsyncValueSetter setter}) {} @override void unlocked() {} diff --git a/packages/flutter/test/painting/image_cache_clearing_test.dart b/packages/flutter/test/painting/image_cache_clearing_test.dart index 94acdf34fb..d640351a43 100644 --- a/packages/flutter/test/painting/image_cache_clearing_test.dart +++ b/packages/flutter/test/painting/image_cache_clearing_test.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:typed_data'; @@ -27,7 +25,7 @@ void main() { completer.complete(); } )); - imageCache.clearLiveImages(); + imageCache!.clearLiveImages(); await completer.future; }); } diff --git a/packages/flutter/test/painting/image_cache_resize_test.dart b/packages/flutter/test/painting/image_cache_resize_test.dart index 81b60dd72d..78ff7efe83 100644 --- a/packages/flutter/test/painting/image_cache_resize_test.dart +++ b/packages/flutter/test/painting/image_cache_resize_test.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/painting.dart'; @@ -16,13 +14,14 @@ void main() { TestRenderingFlutterBinding(); tearDown(() { - imageCache.clear(); - imageCache.maximumSize = 1000; - imageCache.maximumSizeBytes = 10485760; + imageCache! + ..clear() + ..maximumSize = 1000 + ..maximumSizeBytes = 10485760; }); test('Image cache resizing based on count', () async { - imageCache.maximumSize = 2; + imageCache!.maximumSize = 2; final TestImageInfo a = await extractOneFrame(TestImageProvider(1, 1, image: await createTestImage()).resolve(ImageConfiguration.empty)) as TestImageInfo; final TestImageInfo b = await extractOneFrame(TestImageProvider(2, 2, image: await createTestImage()).resolve(ImageConfiguration.empty)) as TestImageInfo; @@ -33,7 +32,7 @@ void main() { expect(c.value, equals(3)); expect(d.value, equals(4)); - imageCache.maximumSize = 0; + imageCache!.maximumSize = 0; final TestImageInfo e = await extractOneFrame(TestImageProvider(1, 5, image: await createTestImage()).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(e.value, equals(5)); @@ -41,7 +40,7 @@ void main() { final TestImageInfo f = await extractOneFrame(TestImageProvider(1, 6, image: await createTestImage()).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(f.value, equals(6)); - imageCache.maximumSize = 3; + imageCache!.maximumSize = 3; final TestImageInfo g = await extractOneFrame(TestImageProvider(1, 7, image: await createTestImage()).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(g.value, equals(7)); @@ -52,7 +51,7 @@ void main() { test('Image cache resizing based on size', () async { final ui.Image testImage = await createTestImage(width: 8, height: 8); // 256 B. - imageCache.maximumSizeBytes = 256 * 2; + imageCache!.maximumSizeBytes = 256 * 2; final TestImageInfo a = await extractOneFrame(TestImageProvider(1, 1, image: testImage).resolve(ImageConfiguration.empty)) as TestImageInfo; final TestImageInfo b = await extractOneFrame(TestImageProvider(2, 2, image: testImage).resolve(ImageConfiguration.empty)) as TestImageInfo; @@ -63,7 +62,7 @@ void main() { expect(c.value, equals(3)); expect(d.value, equals(4)); - imageCache.maximumSizeBytes = 0; + imageCache!.maximumSizeBytes = 0; final TestImageInfo e = await extractOneFrame(TestImageProvider(1, 5, image: testImage).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(e.value, equals(5)); @@ -71,7 +70,7 @@ void main() { final TestImageInfo f = await extractOneFrame(TestImageProvider(1, 6, image: testImage).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(f.value, equals(6)); - imageCache.maximumSizeBytes = 256 * 3; + imageCache!.maximumSizeBytes = 256 * 3; final TestImageInfo g = await extractOneFrame(TestImageProvider(1, 7, image: testImage).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(g.value, equals(7)); diff --git a/packages/flutter/test/painting/image_cache_test.dart b/packages/flutter/test/painting/image_cache_test.dart index 718642f8bf..44ae72ada3 100644 --- a/packages/flutter/test/painting/image_cache_test.dart +++ b/packages/flutter/test/painting/image_cache_test.dart @@ -2,8 +2,7 @@ // 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; import 'package:flutter/foundation.dart'; @@ -18,14 +17,15 @@ void main() { TestRenderingFlutterBinding(); tearDown(() { - imageCache.clear(); - imageCache.clearLiveImages(); - imageCache.maximumSize = 1000; - imageCache.maximumSizeBytes = 10485760; + imageCache! + ..clear() + ..clearLiveImages() + ..maximumSize = 1000 + ..maximumSizeBytes = 10485760; }); test('maintains cache size', () async { - imageCache.maximumSize = 3; + imageCache!.maximumSize = 3; final TestImageInfo a = await extractOneFrame(TestImageProvider(1, 1, image: await createTestImage()).resolve(ImageConfiguration.empty)) as TestImageInfo; expect(a.value, equals(1)); @@ -98,19 +98,19 @@ void main() { test('clear removes all images and resets cache size', () async { final ui.Image testImage = await createTestImage(width: 8, height: 8); - expect(imageCache.currentSize, 0); - expect(imageCache.currentSizeBytes, 0); + expect(imageCache!.currentSize, 0); + expect(imageCache!.currentSizeBytes, 0); await extractOneFrame(TestImageProvider(1, 1, image: testImage).resolve(ImageConfiguration.empty)); await extractOneFrame(TestImageProvider(2, 2, image: testImage).resolve(ImageConfiguration.empty)); - expect(imageCache.currentSize, 2); - expect(imageCache.currentSizeBytes, 256 * 2); + expect(imageCache!.currentSize, 2); + expect(imageCache!.currentSizeBytes, 256 * 2); - imageCache.clear(); + imageCache!.clear(); - expect(imageCache.currentSize, 0); - expect(imageCache.currentSizeBytes, 0); + expect(imageCache!.currentSize, 0); + expect(imageCache!.currentSizeBytes, 0); }); test('evicts individual images', () async { @@ -118,30 +118,37 @@ void main() { await extractOneFrame(TestImageProvider(1, 1, image: testImage).resolve(ImageConfiguration.empty)); await extractOneFrame(TestImageProvider(2, 2, image: testImage).resolve(ImageConfiguration.empty)); - expect(imageCache.currentSize, 2); - expect(imageCache.currentSizeBytes, 256 * 2); - expect(imageCache.evict(1), true); - expect(imageCache.currentSize, 1); - expect(imageCache.currentSizeBytes, 256); + expect(imageCache!.currentSize, 2); + expect(imageCache!.currentSizeBytes, 256 * 2); + expect(imageCache!.evict(1), true); + expect(imageCache!.currentSize, 1); + expect(imageCache!.currentSizeBytes, 256); }); test('Do not cache large images', () async { final ui.Image testImage = await createTestImage(width: 8, height: 8); - imageCache.maximumSizeBytes = 1; + imageCache!.maximumSizeBytes = 1; await extractOneFrame(TestImageProvider(1, 1, image: testImage).resolve(ImageConfiguration.empty)); - expect(imageCache.currentSize, 0); - expect(imageCache.currentSizeBytes, 0); - expect(imageCache.maximumSizeBytes, 1); + expect(imageCache!.currentSize, 0); + expect(imageCache!.currentSizeBytes, 0); + expect(imageCache!.maximumSizeBytes, 1); }); test('Returns null if an error is caught resolving an image', () { + final DecoderCallback _basicDecoder = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); + }; final ErrorImageProvider errorImage = ErrorImageProvider(); - expect(() => imageCache.putIfAbsent(errorImage, () => errorImage.load(errorImage, null)), throwsA(isA())); + expect(() => imageCache!.putIfAbsent(errorImage, () => errorImage.load(errorImage, _basicDecoder)), throwsA(isA())); bool caughtError = false; - final ImageStreamCompleter result = imageCache.putIfAbsent(errorImage, () => errorImage.load(errorImage, null), onError: (dynamic error, StackTrace stackTrace) { - caughtError = true; - }); + final ImageStreamCompleter? result = imageCache!.putIfAbsent( + errorImage, + () => errorImage.load(errorImage, _basicDecoder), + onError: (dynamic error, StackTrace? stackTrace) { + caughtError = true; + }, + ); expect(result, null); expect(caughtError, true); }); @@ -152,10 +159,10 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); final TestImageStreamCompleter completer2 = TestImageStreamCompleter(); - final TestImageStreamCompleter resultingCompleter1 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter1 = imageCache!.putIfAbsent(testImage, () { return completer1; }) as TestImageStreamCompleter; - final TestImageStreamCompleter resultingCompleter2 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter2 = imageCache!.putIfAbsent(testImage, () { return completer2; }) as TestImageStreamCompleter; @@ -169,20 +176,20 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); final TestImageStreamCompleter completer2 = TestImageStreamCompleter(); - final TestImageStreamCompleter resultingCompleter1 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter1 = imageCache!.putIfAbsent(testImage, () { return completer1; }) as TestImageStreamCompleter; - expect(imageCache.statusForKey(testImage).pending, true); - expect(imageCache.statusForKey(testImage).live, true); - imageCache.clear(); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - imageCache.clearLiveImages(); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, false); + expect(imageCache!.statusForKey(testImage).pending, true); + expect(imageCache!.statusForKey(testImage).live, true); + imageCache!.clear(); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + imageCache!.clearLiveImages(); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, false); - final TestImageStreamCompleter resultingCompleter2 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter2 = imageCache!.putIfAbsent(testImage, () { return completer2; }) as TestImageStreamCompleter; @@ -196,13 +203,13 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); final TestImageStreamCompleter completer2 = TestImageStreamCompleter(); - final TestImageStreamCompleter resultingCompleter1 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter1 = imageCache!.putIfAbsent(testImage, () { return completer1; }) as TestImageStreamCompleter; - imageCache.evict(testImage); + imageCache!.evict(testImage); - final TestImageStreamCompleter resultingCompleter2 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter2 = imageCache!.putIfAbsent(testImage, () { return completer2; }) as TestImageStreamCompleter; @@ -219,8 +226,8 @@ void main() { (ImageInfo image, bool synchronousCall) { fail('Image should not complete successfully'); }, - onError: (dynamic exception, StackTrace stackTrace) { - final bool evictionResult = imageCache.evict(1); + onError: (dynamic exception, StackTrace? stackTrace) { + final bool evictionResult = imageCache!.evict(1); expect(evictionResult, isTrue); }, )); @@ -233,12 +240,12 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); - final TestImageStreamCompleter resultingCompleter1 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter1 = imageCache!.putIfAbsent(testImage, () { return completer1; }) as TestImageStreamCompleter; expect(resultingCompleter1, completer1); - expect(imageCache.containsKey(testImage), true); + expect(imageCache!.containsKey(testImage), true); }); test('containsKey - completed', () async { @@ -246,7 +253,7 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); - final TestImageStreamCompleter resultingCompleter1 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter1 = imageCache!.putIfAbsent(testImage, () { return completer1; }) as TestImageStreamCompleter; @@ -254,11 +261,11 @@ void main() { completer1.testSetImage(testImage); expect(resultingCompleter1, completer1); - expect(imageCache.containsKey(testImage), true); + expect(imageCache!.containsKey(testImage), true); }); test('putIfAbsent updates LRU properties of a live image', () async { - imageCache.maximumSize = 1; + imageCache!.maximumSize = 1; final ui.Image testImage = await createTestImage(width: 8, height: 8); final ui.Image testImage2 = await createTestImage(width: 10, height: 10); @@ -267,32 +274,32 @@ void main() { completer1.addListener(ImageStreamListener((ImageInfo info, bool syncCall) {})); - final TestImageStreamCompleter resultingCompleter1 = imageCache.putIfAbsent(testImage, () { + final TestImageStreamCompleter resultingCompleter1 = imageCache!.putIfAbsent(testImage, () { return completer1; }) as TestImageStreamCompleter; - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).keepAlive, true); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage2).untracked, true); - final TestImageStreamCompleter resultingCompleter2 = imageCache.putIfAbsent(testImage2, () { + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).keepAlive, true); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage2).untracked, true); + final TestImageStreamCompleter resultingCompleter2 = imageCache!.putIfAbsent(testImage2, () { return completer2; }) as TestImageStreamCompleter; - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).keepAlive, false); // evicted - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage2).pending, false); - expect(imageCache.statusForKey(testImage2).keepAlive, true); // took the LRU spot. - expect(imageCache.statusForKey(testImage2).live, false); // no listeners + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).keepAlive, false); // evicted + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage2).pending, false); + expect(imageCache!.statusForKey(testImage2).keepAlive, true); // took the LRU spot. + expect(imageCache!.statusForKey(testImage2).live, false); // no listeners expect(resultingCompleter1, completer1); expect(resultingCompleter2, completer2); }); test('Live image cache avoids leaks of unlistened streams', () async { - imageCache.maximumSize = 3; + imageCache!.maximumSize = 3; TestImageProvider(1, 1, image: await createTestImage()).resolve(ImageConfiguration.empty); TestImageProvider(2, 2, image: await createTestImage()).resolve(ImageConfiguration.empty); @@ -304,12 +311,12 @@ void main() { // wait an event loop to let image resolution process. await null; - expect(imageCache.currentSize, 3); - expect(imageCache.liveImageCount, 0); + expect(imageCache!.currentSize, 3); + expect(imageCache!.liveImageCount, 0); }); test('Disabled image cache does not leak live images', () async { - imageCache.maximumSize = 0; + imageCache!.maximumSize = 0; TestImageProvider(1, 1, image: await createTestImage()).resolve(ImageConfiguration.empty); TestImageProvider(2, 2, image: await createTestImage()).resolve(ImageConfiguration.empty); @@ -321,8 +328,8 @@ void main() { // wait an event loop to let image resolution process. await null; - expect(imageCache.currentSize, 0); - expect(imageCache.liveImageCount, 0); + expect(imageCache!.currentSize, 0); + expect(imageCache!.liveImageCount, 0); }); test('Evicting a pending image clears the live image by default', () async { @@ -330,13 +337,13 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, true); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, true); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); - imageCache.evict(testImage); - expect(imageCache.statusForKey(testImage).untracked, true); + imageCache!.evict(testImage); + expect(imageCache!.statusForKey(testImage).untracked, true); }); test('Evicting a pending image does clear the live image when includeLive is false and only cache listening', () async { @@ -344,15 +351,15 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, true); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, true); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); - imageCache.evict(testImage, includeLive: false); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, false); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.evict(testImage, includeLive: false); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, false); + expect(imageCache!.statusForKey(testImage).keepAlive, false); }); test('Evicting a pending image does clear the live image when includeLive is false and some other listener', () async { @@ -360,16 +367,16 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter(); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, true); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, true); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); completer1.addListener(ImageStreamListener((_, __) {})); - imageCache.evict(testImage, includeLive: false); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.evict(testImage, includeLive: false); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); }); test('Evicting a completed image does clear the live image by default', () async { @@ -379,13 +386,13 @@ void main() { ..testSetImage(testImage) ..addListener(ImageStreamListener((ImageInfo info, bool syncCall) {})); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); - imageCache.evict(testImage); - expect(imageCache.statusForKey(testImage).untracked, true); + imageCache!.evict(testImage); + expect(imageCache!.statusForKey(testImage).untracked, true); }); test('Evicting a completed image does not clear the live image when includeLive is set to false', () async { @@ -395,15 +402,15 @@ void main() { ..testSetImage(testImage) ..addListener(ImageStreamListener((ImageInfo info, bool syncCall) {})); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); - imageCache.evict(testImage, includeLive: false); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.evict(testImage, includeLive: false); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); }); test('Clearing liveImages removes callbacks', () async { @@ -419,27 +426,27 @@ void main() { ..testSetImage(testImage) ..addListener(listener); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); - imageCache.clear(); - imageCache.clearLiveImages(); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, false); - expect(imageCache.statusForKey(testImage).keepAlive, false); + imageCache!.clear(); + imageCache!.clearLiveImages(); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, false); + expect(imageCache!.statusForKey(testImage).keepAlive, false); - imageCache.putIfAbsent(testImage, () => completer2); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); + imageCache!.putIfAbsent(testImage, () => completer2); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); completer1.removeListener(listener); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); }); test('Live image gets size updated', () async { @@ -458,40 +465,40 @@ void main() { final TestImageStreamCompleter completer1 = TestImageStreamCompleter() ..addListener(listener); - imageCache.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, true); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); - expect(imageCache.currentSizeBytes, 0); + imageCache!.putIfAbsent(testImage, () => completer1); + expect(imageCache!.statusForKey(testImage).pending, true); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); + expect(imageCache!.currentSizeBytes, 0); completer1.testSetImage(testImage); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); - expect(imageCache.currentSizeBytes, testImageSize); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); + expect(imageCache!.currentSizeBytes, testImageSize); - imageCache.evict(testImage, includeLive: false); + imageCache!.evict(testImage, includeLive: false); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, false); - expect(imageCache.currentSizeBytes, 0); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, false); + expect(imageCache!.currentSizeBytes, 0); - imageCache.putIfAbsent(testImage, () => completer1); + imageCache!.putIfAbsent(testImage, () => completer1); - expect(imageCache.statusForKey(testImage).pending, false); - expect(imageCache.statusForKey(testImage).live, true); - expect(imageCache.statusForKey(testImage).keepAlive, true); - expect(imageCache.currentSizeBytes, testImageSize); + expect(imageCache!.statusForKey(testImage).pending, false); + expect(imageCache!.statusForKey(testImage).live, true); + expect(imageCache!.statusForKey(testImage).keepAlive, true); + expect(imageCache!.currentSizeBytes, testImageSize); }); test('Image is obtained and disposed of properly for cache', () async { const int key = 1; final ui.Image testImage = await createTestImage(width: 8, height: 8, cache: false); - expect(testImage.debugGetOpenHandleStackTraces().length, 1); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 1); - ImageInfo imageInfo; + late ImageInfo imageInfo; final ImageStreamListener listener = ImageStreamListener((ImageInfo info, bool syncCall) { imageInfo = info; }); @@ -499,44 +506,44 @@ void main() { final TestImageStreamCompleter completer = TestImageStreamCompleter(); completer.addListener(listener); - imageCache.putIfAbsent(key, () => completer); + imageCache!.putIfAbsent(key, () => completer); - expect(testImage.debugGetOpenHandleStackTraces().length, 1); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 1); // This should cause keepAlive to be set to true. completer.testSetImage(testImage); expect(imageInfo, isNotNull); // +1 ImageStreamCompleter - expect(testImage.debugGetOpenHandleStackTraces().length, 2); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 2); completer.removeListener(listener); // Force us to the end of the frame. - SchedulerBinding.instance.scheduleFrame(); - await SchedulerBinding.instance.endOfFrame; + SchedulerBinding.instance!.scheduleFrame(); + await SchedulerBinding.instance!.endOfFrame; - expect(testImage.debugGetOpenHandleStackTraces().length, 2); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 2); - expect(imageCache.evict(key), true); + expect(imageCache!.evict(key), true); // Force us to the end of the frame. - SchedulerBinding.instance.scheduleFrame(); - await SchedulerBinding.instance.endOfFrame; + SchedulerBinding.instance!.scheduleFrame(); + await SchedulerBinding.instance!.endOfFrame; // -1 _CachedImage // -1 ImageStreamCompleter - expect(testImage.debugGetOpenHandleStackTraces().length, 1); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 1); imageInfo.dispose(); - expect(testImage.debugGetOpenHandleStackTraces().length, 0); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 0); }, skip: kIsWeb); // Web does not care about image handles. test('Image is obtained and disposed of properly for cache when listener is still active', () async { const int key = 1; final ui.Image testImage = await createTestImage(width: 8, height: 8, cache: false); - expect(testImage.debugGetOpenHandleStackTraces().length, 1); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 1); - ImageInfo imageInfo; + late ImageInfo imageInfo; final ImageStreamListener listener = ImageStreamListener((ImageInfo info, bool syncCall) { imageInfo = info; }); @@ -544,29 +551,29 @@ void main() { final TestImageStreamCompleter completer = TestImageStreamCompleter(); completer.addListener(listener); - imageCache.putIfAbsent(key, () => completer); + imageCache!.putIfAbsent(key, () => completer); - expect(testImage.debugGetOpenHandleStackTraces().length, 1); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 1); // This should cause keepAlive to be set to true. completer.testSetImage(testImage); expect(imageInfo, isNotNull); // Just our imageInfo and the completer. - expect(testImage.debugGetOpenHandleStackTraces().length, 2); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 2); - expect(imageCache.evict(key), true); + expect(imageCache!.evict(key), true); // Force us to the end of the frame. - SchedulerBinding.instance.scheduleFrame(); - await SchedulerBinding.instance.endOfFrame; + SchedulerBinding.instance!.scheduleFrame(); + await SchedulerBinding.instance!.endOfFrame; // Live image still around since there's still a listener, and the listener // should be holding a handle. - expect(testImage.debugGetOpenHandleStackTraces().length, 2); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 2); completer.removeListener(listener); - expect(testImage.debugGetOpenHandleStackTraces().length, 1); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 1); imageInfo.dispose(); - expect(testImage.debugGetOpenHandleStackTraces().length, 0); + expect(testImage.debugGetOpenHandleStackTraces()!.length, 0); }, skip: kIsWeb); // Web does not care about open image handles. } diff --git a/packages/flutter/test/painting/image_decoder_test.dart b/packages/flutter/test/painting/image_decoder_test.dart index aea7103403..9d3a2893d6 100644 --- a/packages/flutter/test/painting/image_decoder_test.dart +++ b/packages/flutter/test/painting/image_decoder_test.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; diff --git a/packages/flutter/test/painting/image_provider_and_image_cache_test.dart b/packages/flutter/test/painting/image_provider_and_image_cache_test.dart index 7e9a3e1896..0920e7a0a7 100644 --- a/packages/flutter/test/painting/image_provider_and_image_cache_test.dart +++ b/packages/flutter/test/painting/image_provider_and_image_cache_test.dart @@ -2,14 +2,11 @@ // 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:typed_data'; import 'package:flutter/foundation.dart'; import 'package:flutter/painting.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import '../image_data.dart'; @@ -19,23 +16,23 @@ import 'mocks_for_image_cache.dart'; void main() { TestRenderingFlutterBinding(); - final DecoderCallback _basicDecoder = (Uint8List bytes, {int cacheWidth, int cacheHeight, bool allowUpscaling}) { - return PaintingBinding.instance.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); + final DecoderCallback _basicDecoder = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); }; - FlutterExceptionHandler oldError; + FlutterExceptionHandler? oldError; setUp(() { oldError = FlutterError.onError; }); tearDown(() { FlutterError.onError = oldError; - PaintingBinding.instance.imageCache.clear(); - PaintingBinding.instance.imageCache.clearLiveImages(); + PaintingBinding.instance!.imageCache!.clear(); + PaintingBinding.instance!.imageCache!.clearLiveImages(); }); tearDown(() { - imageCache.clear(); + imageCache!.clear(); }); test('AssetImageProvider - evicts on failure to load', () async { @@ -46,42 +43,20 @@ void main() { const ImageProvider provider = ExactAssetImage('does-not-exist'); final Object key = await provider.obtainKey(ImageConfiguration.empty); - expect(imageCache.statusForKey(provider).untracked, true); - expect(imageCache.pendingImageCount, 0); + expect(imageCache!.statusForKey(provider).untracked, true); + expect(imageCache!.pendingImageCount, 0); provider.resolve(ImageConfiguration.empty); - expect(imageCache.statusForKey(key).pending, true); - expect(imageCache.pendingImageCount, 1); + expect(imageCache!.statusForKey(key).pending, true); + expect(imageCache!.pendingImageCount, 1); await error.future; - expect(imageCache.statusForKey(provider).untracked, true); - expect(imageCache.pendingImageCount, 0); + expect(imageCache!.statusForKey(provider).untracked, true); + expect(imageCache!.pendingImageCount, 0); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/56314 - test('AssetImageProvider - evicts on null load', () async { - final Completer error = Completer(); - FlutterError.onError = (FlutterErrorDetails details) { - error.complete(details.exception as StateError); - }; - - final ImageProvider provider = ExactAssetImage('does-not-exist', bundle: _TestAssetBundle()); - final Object key = await provider.obtainKey(ImageConfiguration.empty); - expect(imageCache.statusForKey(provider).untracked, true); - expect(imageCache.pendingImageCount, 0); - - provider.resolve(ImageConfiguration.empty); - - expect(imageCache.statusForKey(key).pending, true); - expect(imageCache.pendingImageCount, 1); - - await error.future; - - expect(imageCache.statusForKey(provider).untracked, true); - expect(imageCache.pendingImageCount, 0); - }); - test('ImageProvider can evict images', () async { final Uint8List bytes = Uint8List.fromList(kTransparentImage); final MemoryImage imageProvider = MemoryImage(bytes); @@ -90,9 +65,9 @@ void main() { stream.addListener(ImageStreamListener((ImageInfo info, bool syncCall) => completer.complete())); await completer.future; - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); expect(await MemoryImage(bytes).evict(), true); - expect(imageCache.currentSize, 0); + expect(imageCache!.currentSize, 0); }); test('ImageProvider.evict respects the provided ImageCache', () async { @@ -101,7 +76,7 @@ void main() { final MemoryImage imageProvider = MemoryImage(bytes); final ImageStreamCompleter cacheStream = otherCache.putIfAbsent( imageProvider, () => imageProvider.load(imageProvider, _basicDecoder), - ); + )!; final ImageStream stream = imageProvider.resolve(ImageConfiguration.empty); final Completer completer = Completer(); final Completer cacheCompleter = Completer(); @@ -114,10 +89,10 @@ void main() { await Future.wait(>[completer.future, cacheCompleter.future]); expect(otherCache.currentSize, 1); - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); expect(await imageProvider.evict(cache: otherCache), true); expect(otherCache.currentSize, 0); - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); }); test('ImageProvider errors can always be caught', () async { @@ -129,16 +104,9 @@ void main() { final ImageStream stream = imageProvider.resolve(ImageConfiguration.empty); stream.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { caughtError.complete(false); - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(true); })); expect(await caughtError.future, true); }); } - -class _TestAssetBundle extends CachingAssetBundle { - @override - Future load(String key) async { - return null; - } -} diff --git a/packages/flutter/test/painting/image_provider_network_image_test.dart b/packages/flutter/test/painting/image_provider_network_image_test.dart index ee9fb00d58..2bcacc5b91 100644 --- a/packages/flutter/test/painting/image_provider_network_image_test.dart +++ b/packages/flutter/test/painting/image_provider_network_image_test.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:io'; import 'dart:math' as math; @@ -21,11 +19,11 @@ import '../rendering/rendering_tester.dart'; void main() { TestRenderingFlutterBinding(); - final DecoderCallback _basicDecoder = (Uint8List bytes, {int cacheWidth, int cacheHeight, bool allowUpscaling}) { - return PaintingBinding.instance.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling); + final DecoderCallback _basicDecoder = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) { + return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling ?? false); }; - _FakeHttpClient httpClient; + late _FakeHttpClient httpClient; setUp(() { httpClient = _FakeHttpClient(); @@ -34,8 +32,8 @@ void main() { tearDown(() { debugNetworkImageHttpClientProvider = null; - PaintingBinding.instance.imageCache.clear(); - PaintingBinding.instance.imageCache.clearLiveImages(); + PaintingBinding.instance!.imageCache!.clear(); + PaintingBinding.instance!.imageCache!.clearLiveImages(); }); test('Expect thrown exception with statusCode - evicts from cache', () async { @@ -47,23 +45,23 @@ void main() { final Completer caughtError = Completer(); final ImageProvider imageProvider = NetworkImage(nonconst(requestUrl)); - expect(imageCache.pendingImageCount, 0); - expect(imageCache.statusForKey(imageProvider).untracked, true); + expect(imageCache!.pendingImageCount, 0); + expect(imageCache!.statusForKey(imageProvider).untracked, true); final ImageStream result = imageProvider.resolve(ImageConfiguration.empty); - expect(imageCache.pendingImageCount, 1); - expect(imageCache.statusForKey(imageProvider).pending, true); + expect(imageCache!.pendingImageCount, 1); + expect(imageCache!.statusForKey(imageProvider).pending, true); result.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(error); })); final dynamic err = await caughtError.future; - expect(imageCache.pendingImageCount, 0); - expect(imageCache.statusForKey(imageProvider).untracked, true); + expect(imageCache!.pendingImageCount, 0); + expect(imageCache!.statusForKey(imageProvider).untracked, true); expect( err, @@ -73,12 +71,6 @@ void main() { ); }, skip: isBrowser); // Browser implementation does not use HTTP client but an tag. - test('Disallows null urls', () { - expect(() { - NetworkImage(nonconst(null)); - }, throwsAssertionError); - }); - test('Uses the HttpClient provided by debugNetworkImageHttpClientProvider if set', () async { httpClient.thrownError = 'client1'; final List capturedErrors = []; @@ -88,7 +80,7 @@ void main() { final ImageStreamCompleter completer = networkImage.load(networkImage, _basicDecoder); completer.addListener(ImageStreamListener( (ImageInfo image, bool synchronousCall) { }, - onError: (dynamic error, StackTrace stackTrace) { + onError: (dynamic error, StackTrace? stackTrace) { capturedErrors.add(error); }, )); @@ -108,7 +100,7 @@ void main() { httpClient.thrownError = Error(); bool uncaught = false; - final FlutterExceptionHandler oldError = FlutterError.onError; + final FlutterExceptionHandler? oldError = FlutterError.onError; await runZoned(() async { const ImageProvider imageProvider = NetworkImage('asdasdasdas'); final Completer caughtError = Completer(); @@ -117,7 +109,7 @@ void main() { }; final ImageStream result = imageProvider.resolve(ImageConfiguration.empty); result.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(true); })); expect(await caughtError.future, true); @@ -153,8 +145,8 @@ void main() { onChunk: (ImageChunkEvent event) { events.add(event); }, - onError: (dynamic error, StackTrace stackTrace) { - imageAvailable.completeError(error, stackTrace); + onError: (dynamic error, StackTrace? stackTrace) { + imageAvailable.completeError(error as Object, stackTrace); }, )); await imageAvailable.future; @@ -171,17 +163,17 @@ void main() { debugNetworkImageHttpClientProvider = () => mockHttpClient; final ImageProvider imageProvider = NetworkImage(nonconst('testing.url')); - expect(imageCache.pendingImageCount, 0); - expect(imageCache.statusForKey(imageProvider).untracked, true); + expect(imageCache!.pendingImageCount, 0); + expect(imageCache!.statusForKey(imageProvider).untracked, true); final ImageStream result = imageProvider.resolve(ImageConfiguration.empty); - expect(imageCache.pendingImageCount, 1); - expect(imageCache.statusForKey(imageProvider).pending, true); + expect(imageCache!.pendingImageCount, 1); + expect(imageCache!.statusForKey(imageProvider).pending, true); final Completer caughtError = Completer(); result.addListener(ImageStreamListener( (ImageInfo info, bool syncCall) {}, - onError: (dynamic error, StackTrace stackTrace) { + onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(error); }, )); @@ -190,14 +182,14 @@ void main() { expect(err, isA()); - expect(imageCache.pendingImageCount, 0); - expect(imageCache.statusForKey(imageProvider).untracked, true); - expect(imageCache.containsKey(result), isFalse); + expect(imageCache!.pendingImageCount, 0); + expect(imageCache!.statusForKey(imageProvider).untracked, true); + expect(imageCache!.containsKey(result), isFalse); debugNetworkImageHttpClientProvider = null; }, skip: isBrowser); // Browser does not resolve images this way. - Future _decoder(Uint8List bytes, {int cacheWidth, int cacheHeight, bool allowUpscaling}) async { + Future _decoder(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) async { return FakeCodec(); } @@ -223,12 +215,12 @@ void main() { class _FakeHttpClient extends Fake implements HttpClient { final _FakeHttpClientRequest request = _FakeHttpClientRequest(); - dynamic thrownError; + Object? thrownError; @override Future getUrl(Uri url) async { if (thrownError != null) { - throw thrownError; + throw thrownError!; } return request; } @@ -252,10 +244,10 @@ class _FakeHttpClientResponse extends Fake implements HttpClientResponse { @override HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed; - List> content; + late List> content; @override - StreamSubscription> listen(void Function(List event) onData, {Function onError, void Function() onDone, bool cancelOnError}) { + StreamSubscription> listen(void Function(List event)? onData, {Function? onError, void Function()? onDone, bool? cancelOnError}) { return Stream>.fromIterable(content).listen( onData, onDone: onDone, diff --git a/packages/flutter/test/painting/image_provider_resize_image_test.dart b/packages/flutter/test/painting/image_provider_resize_image_test.dart index 21948fb32c..44788024d2 100644 --- a/packages/flutter/test/painting/image_provider_resize_image_test.dart +++ b/packages/flutter/test/painting/image_provider_resize_image_test.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:typed_data'; @@ -17,8 +15,8 @@ void main() { TestRenderingFlutterBinding(); tearDown(() { - PaintingBinding.instance.imageCache.clear(); - PaintingBinding.instance.imageCache.clearLiveImages(); + PaintingBinding.instance!.imageCache!.clear(); + PaintingBinding.instance!.imageCache!.clearLiveImages(); }); test('ResizeImage resizes to the correct dimensions (up)', () async { @@ -100,11 +98,11 @@ void main() { final MemoryImage memoryImage = MemoryImage(bytes); final ResizeImage resizeImage = ResizeImage(memoryImage, width: 123, height: 321); - final DecoderCallback decode = (Uint8List bytes, {int cacheWidth, int cacheHeight, bool allowUpscaling}) { + final DecoderCallback decode = (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { expect(cacheWidth, 123); expect(cacheHeight, 321); expect(allowUpscaling, false); - return PaintingBinding.instance.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling); + return PaintingBinding.instance!.instantiateImageCodec(bytes, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling); }; resizeImage.load(await resizeImage.obtainKey(ImageConfiguration.empty), decode); diff --git a/packages/flutter/test/painting/image_provider_test.dart b/packages/flutter/test/painting/image_provider_test.dart index 3b2895f58a..3249a03ced 100644 --- a/packages/flutter/test/painting/image_provider_test.dart +++ b/packages/flutter/test/painting/image_provider_test.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:io'; import 'dart:typed_data'; @@ -22,15 +20,15 @@ import 'mocks_for_image_cache.dart'; void main() { TestRenderingFlutterBinding(); - FlutterExceptionHandler oldError; + FlutterExceptionHandler? oldError; setUp(() { oldError = FlutterError.onError; }); tearDown(() { FlutterError.onError = oldError; - PaintingBinding.instance.imageCache.clear(); - PaintingBinding.instance.imageCache.clearLiveImages(); + PaintingBinding.instance!.imageCache!.clear(); + PaintingBinding.instance!.imageCache!.clearLiveImages(); }); test('obtainKey errors will be caught', () async { @@ -42,7 +40,7 @@ void main() { final ImageStream stream = imageProvider.resolve(ImageConfiguration.empty); stream.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { caughtError.complete(false); - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(true); })); expect(await caughtError.future, true); @@ -74,7 +72,7 @@ void main() { }; final ImageStream result = imageProvider.resolve(ImageConfiguration.empty); result.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(true); })); expect(await caughtError.future, true); @@ -97,7 +95,7 @@ void main() { }; final ImageStream result = imageProvider.resolve(ImageConfiguration.empty); result.addListener(ImageStreamListener((ImageInfo info, bool syncCall) { - }, onError: (dynamic error, StackTrace stackTrace) { + }, onError: (dynamic error, StackTrace? stackTrace) { caughtError.complete(true); })); expect(await caughtError.future, true); @@ -114,17 +112,17 @@ void main() { final File file = fs.file('/empty.png')..createSync(recursive: true); final FileImage provider = FileImage(file); - expect(imageCache.statusForKey(provider).untracked, true); - expect(imageCache.pendingImageCount, 0); + expect(imageCache!.statusForKey(provider).untracked, true); + expect(imageCache!.pendingImageCount, 0); provider.resolve(ImageConfiguration.empty); - expect(imageCache.statusForKey(provider).pending, true); - expect(imageCache.pendingImageCount, 1); + expect(imageCache!.statusForKey(provider).pending, true); + expect(imageCache!.pendingImageCount, 1); expect(await error.future, isStateError); - expect(imageCache.statusForKey(provider).untracked, true); - expect(imageCache.pendingImageCount, 0); + expect(imageCache!.statusForKey(provider).untracked, true); + expect(imageCache!.pendingImageCount, 0); }); test('File image with empty file throws expected error (load)', () async { @@ -136,14 +134,14 @@ void main() { final File file = fs.file('/empty.png')..createSync(recursive: true); final FileImage provider = FileImage(file); - expect(provider.load(provider, (Uint8List bytes, {int cacheWidth, int cacheHeight, bool allowUpscaling}) async { + expect(provider.load(provider, (Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) async { return Future.value(FakeCodec()); }), isA()); expect(await error.future, isStateError); }); - Future _decoder(Uint8List bytes, {int cacheWidth, int cacheHeight, bool allowUpscaling}) async { + Future _decoder(Uint8List bytes, {int? cacheWidth, int? cacheHeight, bool? allowUpscaling}) async { return FakeCodec(); } diff --git a/packages/flutter/test/painting/image_resolution_test.dart b/packages/flutter/test/painting/image_resolution_test.dart index a69b1b5f83..394ef6edef 100644 --- a/packages/flutter/test/painting/image_resolution_test.dart +++ b/packages/flutter/test/painting/image_resolution_test.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:convert'; import 'dart:typed_data'; diff --git a/packages/flutter/test/painting/image_stream_test.dart b/packages/flutter/test/painting/image_stream_test.dart index 3f156d9973..491b115cf8 100644 --- a/packages/flutter/test/painting/image_stream_test.dart +++ b/packages/flutter/test/painting/image_stream_test.dart @@ -2,15 +2,12 @@ // 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'; import 'package:flutter/painting.dart'; import 'package:flutter/scheduler.dart' show timeDilation, SchedulerBinding; import 'package:flutter_test/flutter_test.dart'; -import 'package:meta/meta.dart'; class FakeFrameInfo implements FrameInfo { const FakeFrameInfo(this._duration, this._image); @@ -24,7 +21,7 @@ class FakeFrameInfo implements FrameInfo { @override Image get image => _image; - int get imageHandleCount => image.debugGetOpenHandleStackTraces().length; + int get imageHandleCount => image.debugGetOpenHandleStackTraces()!.length; FakeFrameInfo clone() { return FakeFrameInfo( @@ -35,12 +32,11 @@ class FakeFrameInfo implements FrameInfo { } class MockCodec implements Codec { + @override + late int frameCount; @override - int frameCount; - - @override - int repetitionCount; + late int repetitionCount; int numFramesAsked = 0; @@ -67,7 +63,7 @@ class MockCodec implements Codec { } class FakeEventReportingImageStreamCompleter extends ImageStreamCompleter { - FakeEventReportingImageStreamCompleter({Stream chunkEvents,}) { + FakeEventReportingImageStreamCompleter({Stream? chunkEvents}) { if (chunkEvents != null) { chunkEvents.listen((ImageChunkEvent event) { reportImageChunkEvent(event); @@ -78,8 +74,8 @@ class FakeEventReportingImageStreamCompleter extends ImageStreamCompleter { } void main() { - Image image20x10; - Image image200x100; + late Image image20x10; + late Image image200x100; setUp(() async { image20x10 = await createTestImage(width: 20, height: 10); image200x100 = await createTestImage(width: 200, height: 100); @@ -602,7 +598,7 @@ void main() { ); dynamic capturedException; - final ImageErrorListener errorListener = (dynamic exception, StackTrace stackTrace) { + final ImageErrorListener errorListener = (dynamic exception, StackTrace? stackTrace) { capturedException = exception; }; @@ -660,16 +656,16 @@ void main() { testWidgets('ImageStreamListener hashCode and equals', (WidgetTester tester) async { void handleImage(ImageInfo image, bool synchronousCall) { } void handleImageDifferently(ImageInfo image, bool synchronousCall) { } - void handleError(dynamic error, StackTrace stackTrace) { } + void handleError(dynamic error, StackTrace? stackTrace) { } void handleChunk(ImageChunkEvent event) { } void compare({ - @required ImageListener onImage1, - @required ImageListener onImage2, - ImageChunkListener onChunk1, - ImageChunkListener onChunk2, - ImageErrorListener onError1, - ImageErrorListener onError2, + required ImageListener onImage1, + required ImageListener onImage2, + ImageChunkListener? onChunk1, + ImageChunkListener? onChunk2, + ImageErrorListener? onError1, + ImageErrorListener? onError2, bool areEqual = true, }) { final ImageStreamListener l1 = ImageStreamListener(onImage1, onChunk: onChunk1, onError: onError1); @@ -690,7 +686,7 @@ void main() { }); testWidgets('Keep alive handles do not drive frames or prevent last listener callbacks', (WidgetTester tester) async { - final Image image10x10 = await tester.runAsync(() => createTestImage(width: 10, height: 10)); + final Image image10x10 = (await tester.runAsync(() => createTestImage(width: 10, height: 10)))!; final MockCodec mockCodec = MockCodec(); mockCodec.frameCount = 2; mockCodec.repetitionCount = -1; @@ -713,7 +709,7 @@ void main() { expect(lastListenerDropped, false); final ImageStreamCompleterHandle handle = imageStream.keepAlive(); expect(lastListenerDropped, false); - SchedulerBinding.instance.debugAssertNoTransientCallbacks('Only passive listeners'); + SchedulerBinding.instance!.debugAssertNoTransientCallbacks('Only passive listeners'); codecCompleter.complete(mockCodec); await tester.idle(); @@ -723,7 +719,7 @@ void main() { final FakeFrameInfo frame1 = FakeFrameInfo(Duration.zero, image20x10); mockCodec.completeNextFrame(frame1); await tester.idle(); - SchedulerBinding.instance.debugAssertNoTransientCallbacks('Only passive listeners'); + SchedulerBinding.instance!.debugAssertNoTransientCallbacks('Only passive listeners'); await tester.pump(); expect(onImageCount, 0); @@ -732,7 +728,7 @@ void main() { final FakeFrameInfo frame2 = FakeFrameInfo(Duration.zero, image10x10); mockCodec.completeNextFrame(frame2); await tester.idle(); - expect(SchedulerBinding.instance.transientCallbackCount, 1); + expect(SchedulerBinding.instance!.transientCallbackCount, 1); await tester.pump(); expect(onImageCount, 1); @@ -742,16 +738,16 @@ void main() { mockCodec.completeNextFrame(frame1); await tester.idle(); - expect(SchedulerBinding.instance.transientCallbackCount, 1); + expect(SchedulerBinding.instance!.transientCallbackCount, 1); await tester.pump(); expect(onImageCount, 1); - SchedulerBinding.instance.debugAssertNoTransientCallbacks('Only passive listeners'); + SchedulerBinding.instance!.debugAssertNoTransientCallbacks('Only passive listeners'); mockCodec.completeNextFrame(frame2); await tester.idle(); - SchedulerBinding.instance.debugAssertNoTransientCallbacks('Only passive listeners'); + SchedulerBinding.instance!.debugAssertNoTransientCallbacks('Only passive listeners'); await tester.pump(); expect(onImageCount, 1); diff --git a/packages/flutter/test/painting/matrix_utils_test.dart b/packages/flutter/test/painting/matrix_utils_test.dart index af69c50bb3..a749b73b3e 100644 --- a/packages/flutter/test/painting/matrix_utils_test.dart +++ b/packages/flutter/test/painting/matrix_utils_test.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:math'; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/painting/notched_shapes_test.dart b/packages/flutter/test/painting/notched_shapes_test.dart index 25e668de77..3a350d61b9 100644 --- a/packages/flutter/test/painting/notched_shapes_test.dart +++ b/packages/flutter/test/painting/notched_shapes_test.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:math' as math; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/painting/paint_image_test.dart b/packages/flutter/test/painting/paint_image_test.dart index c046cfdb7d..d2c37fedac 100644 --- a/packages/flutter/test/painting/paint_image_test.dart +++ b/packages/flutter/test/painting/paint_image_test.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/foundation.dart'; @@ -20,8 +18,8 @@ class TestCanvas implements Canvas { } void main() { - ui.Image image300x300; - ui.Image image300x200; + late ui.Image image300x300; + late ui.Image image300x200; setUpAll(() async { image300x300 = await createTestImage(width: 300, height: 300, cache: false); image300x200 = await createTestImage(width: 300, height: 200, cache: false); @@ -53,7 +51,7 @@ void main() { test('debugInvertOversizedImages', () async { debugInvertOversizedImages = true; - final FlutterExceptionHandler oldFlutterError = FlutterError.onError; + final FlutterExceptionHandler? oldFlutterError = FlutterError.onError; final List messages = []; FlutterError.onError = (FlutterErrorDetails details) { @@ -111,7 +109,7 @@ void main() { }); testWidgets('Reports Image painting', (WidgetTester tester) async { - ImageSizeInfo imageSizeInfo; + late ImageSizeInfo imageSizeInfo; int count = 0; debugOnPaintImage = (ImageSizeInfo info) { count += 1; @@ -150,7 +148,7 @@ void main() { }); testWidgets('Reports Image painting - change per frame', (WidgetTester tester) async { - ImageSizeInfo imageSizeInfo; + late ImageSizeInfo imageSizeInfo; int count = 0; debugOnPaintImage = (ImageSizeInfo info) { count += 1; @@ -193,7 +191,7 @@ void main() { }); testWidgets('Reports Image painting - no debug label', (WidgetTester tester) async { - ImageSizeInfo imageSizeInfo; + late ImageSizeInfo imageSizeInfo; int count = 0; debugOnPaintImage = (ImageSizeInfo info) { count += 1; diff --git a/packages/flutter/test/painting/rounded_rectangle_border_test.dart b/packages/flutter/test/painting/rounded_rectangle_border_test.dart index 6262d64eac..252923a999 100644 --- a/packages/flutter/test/painting/rounded_rectangle_border_test.dart +++ b/packages/flutter/test/painting/rounded_rectangle_border_test.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/painting.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -75,18 +73,18 @@ void main() { ); expect(r.getOuterPath(rect), looksLikeR); expect(c.getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(r, c, 0.1).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(r, c, 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.9), r, 0.1).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.9), r, 0.9).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), c, 0.1).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), c, 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), ShapeBorder.lerp(r, c, 0.9), 0.1).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), ShapeBorder.lerp(r, c, 0.9), 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(r, ShapeBorder.lerp(r, c, 0.9), 0.1).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(r, ShapeBorder.lerp(r, c, 0.9), 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(c, ShapeBorder.lerp(r, c, 0.1), 0.1).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(c, ShapeBorder.lerp(r, c, 0.1), 0.9).getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(r, c, 0.1)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(r, c, 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.9), r, 0.1)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.9), r, 0.9)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), c, 0.1)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), c, 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), ShapeBorder.lerp(r, c, 0.9), 0.1)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(ShapeBorder.lerp(r, c, 0.1), ShapeBorder.lerp(r, c, 0.9), 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(r, ShapeBorder.lerp(r, c, 0.9), 0.1)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(r, ShapeBorder.lerp(r, c, 0.9), 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(c, ShapeBorder.lerp(r, c, 0.1), 0.1)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(c, ShapeBorder.lerp(r, c, 0.1), 0.9)!.getOuterPath(rect), looksLikeR); expect(ShapeBorder.lerp(r, c, 0.1).toString(), 'RoundedRectangleBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none), BorderRadius.circular(10.0), 10.0% of the way to being a CircleBorder)'); @@ -105,8 +103,8 @@ void main() { expect(ShapeBorder.lerp(r, c, 0.1), ShapeBorder.lerp(r, c, 0.1)); expect(ShapeBorder.lerp(r, c, 0.1).hashCode, ShapeBorder.lerp(r, c, 0.1).hashCode); - final ShapeBorder direct50 = ShapeBorder.lerp(r, c, 0.5); - final ShapeBorder indirect50 = ShapeBorder.lerp(ShapeBorder.lerp(c, r, 0.1), ShapeBorder.lerp(c, r, 0.9), 0.5); + final ShapeBorder direct50 = ShapeBorder.lerp(r, c, 0.5)!; + final ShapeBorder indirect50 = ShapeBorder.lerp(ShapeBorder.lerp(c, r, 0.1), ShapeBorder.lerp(c, r, 0.9), 0.5)!; expect(direct50, indirect50); expect(direct50.hashCode, indirect50.hashCode); expect(direct50.toString(), indirect50.toString()); diff --git a/packages/flutter/test/painting/shader_warm_up_test.dart b/packages/flutter/test/painting/shader_warm_up_test.dart index 7c8adb350c..849f67292f 100644 --- a/packages/flutter/test/painting/shader_warm_up_test.dart +++ b/packages/flutter/test/painting/shader_warm_up_test.dart @@ -2,32 +2,29 @@ // 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/painting.dart'; import 'package:flutter_test/flutter_test.dart'; class TestCanvas implements Canvas { - TestCanvas([this.invocations]); + TestCanvas(); - final List invocations; + final List invocations = []; @override void noSuchMethod(Invocation invocation) { - invocations?.add(invocation); + invocations.add(invocation); } } void main() { test('DefaultShaderWarmUp has expected canvas invocations', () { - final List invocations = []; - final TestCanvas canvas = TestCanvas(invocations); + final TestCanvas canvas = TestCanvas(); const DefaultShaderWarmUp s = DefaultShaderWarmUp(); s.warmUpOnCanvas(canvas); bool hasDrawRectAfterClipRRect = false; - for (int i = 0; i < invocations.length - 1; i += 1) { - if (invocations[i].memberName == #clipRRect && invocations[i + 1].memberName == #drawRect) { + for (int i = 0; i < canvas.invocations.length - 1; i += 1) { + if (canvas.invocations[i].memberName == #clipRRect && canvas.invocations[i + 1].memberName == #drawRect) { hasDrawRectAfterClipRRect = true; break; } diff --git a/packages/flutter/test/painting/shape_border_test.dart b/packages/flutter/test/painting/shape_border_test.dart index eead69f480..632db92717 100644 --- a/packages/flutter/test/painting/shape_border_test.dart +++ b/packages/flutter/test/painting/shape_border_test.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/painting.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/packages/flutter/test/painting/shape_decoration_test.dart b/packages/flutter/test/painting/shape_decoration_test.dart index d472b9e63f..5a79d3b925 100644 --- a/packages/flutter/test/painting/shape_decoration_test.dart +++ b/packages/flutter/test/painting/shape_decoration_test.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/foundation.dart'; @@ -22,7 +20,6 @@ void main() { const Gradient gradient = LinearGradient(colors: [colorR, colorG]); expect(const ShapeDecoration(shape: Border()), const ShapeDecoration(shape: Border())); expect(() => ShapeDecoration(color: colorR, gradient: nonconst(gradient), shape: const Border()), throwsAssertionError); - expect(() => ShapeDecoration(gradient: nonconst(gradient), shape: null), throwsAssertionError); expect( ShapeDecoration.fromBoxDecoration(const BoxDecoration(shape: BoxShape.circle)), const ShapeDecoration(shape: CircleBorder(side: BorderSide.none)), @@ -52,9 +49,9 @@ void main() { expect(Decoration.lerp(a, b, 1.0), b); const Size size = Size(200.0, 100.0); // at t=0.5, width will be 150 (x=25 to x=175). expect(a.hitTest(size, const Offset(20.0, 50.0)), isFalse); - expect(Decoration.lerp(a, b, 0.1).hitTest(size, const Offset(20.0, 50.0)), isFalse); - expect(Decoration.lerp(a, b, 0.5).hitTest(size, const Offset(20.0, 50.0)), isFalse); - expect(Decoration.lerp(a, b, 0.9).hitTest(size, const Offset(20.0, 50.0)), isTrue); + expect(Decoration.lerp(a, b, 0.1)!.hitTest(size, const Offset(20.0, 50.0)), isFalse); + expect(Decoration.lerp(a, b, 0.5)!.hitTest(size, const Offset(20.0, 50.0)), isFalse); + expect(Decoration.lerp(a, b, 0.9)!.hitTest(size, const Offset(20.0, 50.0)), isTrue); expect(b.hitTest(size, const Offset(20.0, 50.0)), isTrue); }); diff --git a/packages/flutter/test/painting/stadium_border_test.dart b/packages/flutter/test/painting/stadium_border_test.dart index 2960651fea..276d48e4d4 100644 --- a/packages/flutter/test/painting/stadium_border_test.dart +++ b/packages/flutter/test/painting/stadium_border_test.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/painting.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -63,18 +61,18 @@ void main() { ); expect(stadium.getOuterPath(rect), looksLikeS); expect(circle.getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(stadium, circle, 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(stadium, circle, 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.9), stadium, 0.1).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.9), stadium, 0.9).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), circle, 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), circle, 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), ShapeBorder.lerp(stadium, circle, 0.9), 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), ShapeBorder.lerp(stadium, circle, 0.9), 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, circle, 0.9), 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, circle, 0.9), 0.9).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(circle, ShapeBorder.lerp(stadium, circle, 0.1), 0.1).getOuterPath(rect), looksLikeC); - expect(ShapeBorder.lerp(circle, ShapeBorder.lerp(stadium, circle, 0.1), 0.9).getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(stadium, circle, 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(stadium, circle, 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.9), stadium, 0.1)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.9), stadium, 0.9)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), circle, 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), circle, 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), ShapeBorder.lerp(stadium, circle, 0.9), 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, circle, 0.1), ShapeBorder.lerp(stadium, circle, 0.9), 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, circle, 0.9), 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, circle, 0.9), 0.9)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(circle, ShapeBorder.lerp(stadium, circle, 0.1), 0.1)!.getOuterPath(rect), looksLikeC); + expect(ShapeBorder.lerp(circle, ShapeBorder.lerp(stadium, circle, 0.1), 0.9)!.getOuterPath(rect), looksLikeS); expect(ShapeBorder.lerp(stadium, circle, 0.1).toString(), 'StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none), 10.0% of the way to being a CircleBorder)'); @@ -93,8 +91,8 @@ void main() { expect(ShapeBorder.lerp(stadium, circle, 0.1), ShapeBorder.lerp(stadium, circle, 0.1)); expect(ShapeBorder.lerp(stadium, circle, 0.1).hashCode, ShapeBorder.lerp(stadium, circle, 0.1).hashCode); - final ShapeBorder direct50 = ShapeBorder.lerp(stadium, circle, 0.5); - final ShapeBorder indirect50 = ShapeBorder.lerp(ShapeBorder.lerp(circle, stadium, 0.1), ShapeBorder.lerp(circle, stadium, 0.9), 0.5); + final ShapeBorder direct50 = ShapeBorder.lerp(stadium, circle, 0.5)!; + final ShapeBorder indirect50 = ShapeBorder.lerp(ShapeBorder.lerp(circle, stadium, 0.1), ShapeBorder.lerp(circle, stadium, 0.9), 0.5)!; expect(direct50, indirect50); expect(direct50.hashCode, indirect50.hashCode); expect(direct50.toString(), indirect50.toString()); @@ -130,18 +128,18 @@ void main() { ); expect(stadium.getOuterPath(rect), looksLikeS); expect(rrect.getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(stadium, rrect, 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(stadium, rrect, 0.9).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.9), stadium, 0.1).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.9), stadium, 0.9).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), rrect, 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), rrect, 0.9).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), ShapeBorder.lerp(stadium, rrect, 0.9), 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), ShapeBorder.lerp(stadium, rrect, 0.9), 0.9).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, rrect, 0.9), 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, rrect, 0.9), 0.9).getOuterPath(rect), looksLikeR); - expect(ShapeBorder.lerp(rrect, ShapeBorder.lerp(stadium, rrect, 0.1), 0.1).getOuterPath(rect), looksLikeS); - expect(ShapeBorder.lerp(rrect, ShapeBorder.lerp(stadium, rrect, 0.1), 0.9).getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(stadium, rrect, 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(stadium, rrect, 0.9)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.9), stadium, 0.1)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.9), stadium, 0.9)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), rrect, 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), rrect, 0.9)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), ShapeBorder.lerp(stadium, rrect, 0.9), 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(ShapeBorder.lerp(stadium, rrect, 0.1), ShapeBorder.lerp(stadium, rrect, 0.9), 0.9)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, rrect, 0.9), 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(stadium, ShapeBorder.lerp(stadium, rrect, 0.9), 0.9)!.getOuterPath(rect), looksLikeR); + expect(ShapeBorder.lerp(rrect, ShapeBorder.lerp(stadium, rrect, 0.1), 0.1)!.getOuterPath(rect), looksLikeS); + expect(ShapeBorder.lerp(rrect, ShapeBorder.lerp(stadium, rrect, 0.1), 0.9)!.getOuterPath(rect), looksLikeS); expect(ShapeBorder.lerp(stadium, rrect, 0.1).toString(), 'StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none), ' @@ -166,8 +164,8 @@ void main() { expect(ShapeBorder.lerp(stadium, rrect, 0.1), ShapeBorder.lerp(stadium, rrect, 0.1)); expect(ShapeBorder.lerp(stadium, rrect, 0.1).hashCode, ShapeBorder.lerp(stadium, rrect, 0.1).hashCode); - final ShapeBorder direct50 = ShapeBorder.lerp(stadium, rrect, 0.5); - final ShapeBorder indirect50 = ShapeBorder.lerp(ShapeBorder.lerp(rrect, stadium, 0.1), ShapeBorder.lerp(rrect, stadium, 0.9), 0.5); + final ShapeBorder direct50 = ShapeBorder.lerp(stadium, rrect, 0.5)!; + final ShapeBorder indirect50 = ShapeBorder.lerp(ShapeBorder.lerp(rrect, stadium, 0.1), ShapeBorder.lerp(rrect, stadium, 0.9), 0.5)!; expect(direct50, indirect50); expect(direct50.hashCode, indirect50.hashCode); expect(direct50.toString(), indirect50.toString()); diff --git a/packages/flutter/test/painting/strut_style_test.dart b/packages/flutter/test/painting/strut_style_test.dart index bab63dc8ac..7f0ac7260a 100644 --- a/packages/flutter/test/painting/strut_style_test.dart +++ b/packages/flutter/test/painting/strut_style_test.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/painting.dart'; import '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/painting/system_fonts_test.dart b/packages/flutter/test/painting/system_fonts_test.dart index fd48e6b2c0..8b5b31882f 100644 --- a/packages/flutter/test/painting/system_fonts_test.dart +++ b/packages/flutter/test/painting/system_fonts_test.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/material.dart'; @@ -22,10 +20,10 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); final RenderObject renderObject = tester.renderObject(find.text('text widget')); expect(renderObject.debugNeedsLayout, isTrue); @@ -40,10 +38,10 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); final EditableTextState state = tester.state(find.byType(EditableText)); expect(state.renderEditable.debugNeedsLayout, isTrue); @@ -61,10 +59,10 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); final RenderObject renderObject = tester.renderObject(find.byType(Banner)); expect(renderObject.debugNeedsPaint, isTrue); @@ -78,16 +76,16 @@ void main() { ), ), ); - final dynamic state = tester.state(find.byType(CupertinoDatePicker)); + final dynamic state = tester.state(find.byType(CupertinoDatePicker)); // ignore: unnecessary_nullable_for_final_variable_declarations final Map cache = state.estimatedColumnWidths as Map; expect(cache.isNotEmpty, isTrue); const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); // Cache should be cleaned. expect(cache.isEmpty, isTrue); @@ -104,17 +102,17 @@ void main() { ), ), ); - final dynamic state = tester.state(find.byType(CupertinoDatePicker)); + final dynamic state = tester.state(find.byType(CupertinoDatePicker)); // ignore: unnecessary_nullable_for_final_variable_declarations final Map cache = state.estimatedColumnWidths as Map; // Simulates font missing. cache.clear(); const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); // Cache should be replenished expect(cache.isNotEmpty, isTrue); @@ -130,7 +128,7 @@ void main() { ), ), ); - final dynamic state = tester.state(find.byType(CupertinoTimerPicker)); + final dynamic state = tester.state(find.byType(CupertinoTimerPicker)); // ignore: unnecessary_nullable_for_final_variable_declarations // Simulates wrong metrics due to font missing. state.numberLabelWidth = 0.0; state.numberLabelHeight = 0.0; @@ -138,10 +136,10 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); // Metrics should be refreshed expect(state.numberLabelWidth - 46.0 < precisionErrorTolerance, isTrue); @@ -165,14 +163,14 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); final RenderObject renderObject = tester.renderObject(find.byType(RangeSlider)); - bool sliderBoxNeedsLayout; + late bool sliderBoxNeedsLayout; renderObject.visitChildren((RenderObject child) {sliderBoxNeedsLayout = child.debugNeedsLayout;}); expect(sliderBoxNeedsLayout, isTrue); }); @@ -191,10 +189,10 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); // _RenderSlider is the last render object in the tree. final RenderObject renderObject = tester.allRenderObjects.last; @@ -214,11 +212,11 @@ void main() { showTimePicker( context: context, initialTime: const TimeOfDay(hour: 7, minute: 0), - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return Directionality( key: const Key('parent'), textDirection: TextDirection.ltr, - child: child, + child: child!, ); }, ); @@ -235,10 +233,10 @@ void main() { const Map data = { 'type': 'fontsChange', }; - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage( + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage( 'flutter/system', SystemChannels.system.codec.encodeMessage(data), - (ByteData data) { }, + (ByteData? data) { }, ); final RenderObject renderObject = tester.renderObject( find.descendant( diff --git a/packages/flutter/test/painting/text_painter_rtl_test.dart b/packages/flutter/test/painting/text_painter_rtl_test.dart index 77f999d26a..9610d7c746 100644 --- a/packages/flutter/test/painting/text_painter_rtl_test.dart +++ b/packages/flutter/test/painting/text_painter_rtl_test.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/painting.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -46,7 +44,7 @@ void main() { style: TextStyle(fontFamily: 'Ahem', fontSize: 10.0), ); TextSpan textSpan = painter.text as TextSpan; - expect(textSpan.text.length, 28); + expect(textSpan.text!.length, 28); painter.layout(); // The skips here are because the old rendering code considers the bidi formatting characters @@ -131,7 +129,7 @@ void main() { textSpan = painter.text as TextSpan; final List> list = >[ - for (int index = 0; index < textSpan.text.length; index += 1) + for (int index = 0; index < textSpan.text!.length; index += 1) painter.getBoxesForSelection(TextSelection(baseOffset: index, extentOffset: index + 1)), ]; expect(list, const >[ @@ -178,7 +176,7 @@ void main() { style: TextStyle(fontFamily: 'Ahem', fontSize: 10.0), ); final TextSpan textSpan = painter.text as TextSpan; - expect(textSpan.text.length, 28); + expect(textSpan.text!.length, 28); painter.layout(); final TextRange hebrew1 = painter.getWordBoundary(const TextPosition(offset: 4, affinity: TextAffinity.downstream)); @@ -268,7 +266,7 @@ void main() { style: TextStyle(fontFamily: 'Ahem', fontSize: 10.0), ); final TextSpan textSpan = painter.text as TextSpan; - expect(textSpan.text.length, 2); + expect(textSpan.text!.length, 2); painter.layout(maxWidth: 10.0); for (int index = 0; index <= 2; index += 1) { diff --git a/packages/flutter/test/painting/text_painter_test.dart b/packages/flutter/test/painting/text_painter_test.dart index 9245a36fb1..6ab3f89f15 100644 --- a/packages/flutter/test/painting/text_painter_test.dart +++ b/packages/flutter/test/painting/text_painter_test.dart @@ -2,14 +2,14 @@ // 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/painting.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../flutter_test_alternative.dart' show Fake; + void main() { test('TextPainter caret test', () { final TextPainter painter = TextPainter() @@ -149,7 +149,7 @@ void main() { test('TextPainter error test', () { final TextPainter painter = TextPainter(textDirection: TextDirection.ltr); - expect(() { painter.paint(null, Offset.zero); }, anyOf(throwsFlutterError, throwsAssertionError)); + expect(() { painter.paint(MockCanvas(), Offset.zero); }, anyOf(throwsFlutterError, throwsAssertionError)); }); test('TextPainter requires textDirection', () { @@ -730,19 +730,19 @@ void main() { caretOffset = painter.getOffsetForCaret(const ui.TextPosition(offset: 23), ui.Rect.zero); expect(caretOffset.dx, 250); - expect(painter.inlinePlaceholderBoxes.length, 14); - expect(painter.inlinePlaceholderBoxes[0], const TextBox.fromLTRBD(56, 0, 106, 30, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[2], const TextBox.fromLTRBD(212, 0, 262, 30, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[3], const TextBox.fromLTRBD(318, 0, 368, 30, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[4], const TextBox.fromLTRBD(368, 0, 418, 30, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[5], const TextBox.fromLTRBD(418, 0, 468, 30, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes!.length, 14); + expect(painter.inlinePlaceholderBoxes![0], const TextBox.fromLTRBD(56, 0, 106, 30, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![2], const TextBox.fromLTRBD(212, 0, 262, 30, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![3], const TextBox.fromLTRBD(318, 0, 368, 30, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![4], const TextBox.fromLTRBD(368, 0, 418, 30, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![5], const TextBox.fromLTRBD(418, 0, 468, 30, TextDirection.ltr)); // line should break here - expect(painter.inlinePlaceholderBoxes[6], const TextBox.fromLTRBD(0, 30, 50, 60, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[7], const TextBox.fromLTRBD(50, 30, 100, 60, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[10], const TextBox.fromLTRBD(200, 30, 250, 60, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[11], const TextBox.fromLTRBD(250, 30, 300, 60, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[12], const TextBox.fromLTRBD(300, 30, 351, 60, TextDirection.ltr)); - expect(painter.inlinePlaceholderBoxes[13], const TextBox.fromLTRBD(351, 30, 401, 60, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![6], const TextBox.fromLTRBD(0, 30, 50, 60, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![7], const TextBox.fromLTRBD(50, 30, 100, 60, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![10], const TextBox.fromLTRBD(200, 30, 250, 60, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![11], const TextBox.fromLTRBD(250, 30, 300, 60, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![12], const TextBox.fromLTRBD(300, 30, 351, 60, TextDirection.ltr)); + expect(painter.inlinePlaceholderBoxes![13], const TextBox.fromLTRBD(351, 30, 401, 60, TextDirection.ltr)); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/42086 // Null values are valid. See https://github.com/flutter/flutter/pull/48346#issuecomment-584839221 @@ -830,7 +830,11 @@ void main() { final double caretHeight = painter.getFullHeightForCaret( const ui.TextPosition(offset: 0), ui.Rect.zero, - ); + )!; expect(caretHeight, 50.0); }, skip: isBrowser); // https://github.com/flutter/flutter/issues/56308 } + +class MockCanvas extends Fake implements Canvas { + +} diff --git a/packages/flutter/test/painting/text_span_test.dart b/packages/flutter/test/painting/text_span_test.dart index 66bd8e092b..8b91aa5176 100644 --- a/packages/flutter/test/painting/text_span_test.dart +++ b/packages/flutter/test/painting/text_span_test.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/painting.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -234,15 +232,4 @@ void main() { expect(textSpan.getSpanForPosition(const TextPosition(offset: 2)).runtimeType, WidgetSpan); expect(textSpan.getSpanForPosition(const TextPosition(offset: 3)).runtimeType, TextSpan); }); - - test('TextSpan with a null child should throw FlutterError', () { - const TextSpan text = TextSpan( - text: 'foo bar', - children: [ - null, - ], - ); - expect(() => text.computeToPlainText(StringBuffer()), anyOf(throwsFlutterError, throwsAssertionError)); - }); - } diff --git a/packages/flutter/test/painting/text_style_test.dart b/packages/flutter/test/painting/text_style_test.dart index d97d4180cf..910e87ec5a 100644 --- a/packages/flutter/test/painting/text_style_test.dart +++ b/packages/flutter/test/painting/text_style_test.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 TextStyle, ParagraphStyle, FontFeature, Shadow; import 'package:flutter/painting.dart'; @@ -96,7 +94,7 @@ void main() { expect(s4.height, 123.0); expect(s4.color, const Color(0xFF00FF00)); - final TextStyle s5 = TextStyle.lerp(s1, s3, 0.25); + final TextStyle s5 = TextStyle.lerp(s1, s3, 0.25)!; expect(s1.fontFamily, isNull); expect(s1.fontSize, 10.0); expect(s1.fontWeight, FontWeight.w800); @@ -117,7 +115,7 @@ void main() { expect(TextStyle.lerp(null, null, 0.5), isNull); - final TextStyle s6 = TextStyle.lerp(null, s3, 0.25); + final TextStyle s6 = TextStyle.lerp(null, s3, 0.25)!; expect(s3.fontFamily, isNull); expect(s3.fontSize, 18.0); expect(s3.fontWeight, FontWeight.w400); @@ -130,7 +128,7 @@ void main() { expect(s6.height, isNull); expect(s6.color, isNull); - final TextStyle s7 = TextStyle.lerp(null, s3, 0.75); + final TextStyle s7 = TextStyle.lerp(null, s3, 0.75)!; expect(s3.fontFamily, isNull); expect(s3.fontSize, 18.0); expect(s3.fontWeight, FontWeight.w400); @@ -143,7 +141,7 @@ void main() { expect(s7.height, 123.0); expect(s7.color, isNull); - final TextStyle s8 = TextStyle.lerp(s3, null, 0.25); + final TextStyle s8 = TextStyle.lerp(s3, null, 0.25)!; expect(s3.fontFamily, isNull); expect(s3.fontSize, 18.0); expect(s3.fontWeight, FontWeight.w400); @@ -156,7 +154,7 @@ void main() { expect(s8.height, 123.0); expect(s8.color, isNull); - final TextStyle s9 = TextStyle.lerp(s3, null, 0.75); + final TextStyle s9 = TextStyle.lerp(s3, null, 0.75)!; expect(s3.fontFamily, isNull); expect(s3.fontSize, 18.0); expect(s3.fontWeight, FontWeight.w400); @@ -201,9 +199,9 @@ void main() { expect(s7.getTextStyle().toString(), 'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: packages/p/test, fontFamilyFallback: unspecified, fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'); const TextStyle s8 = TextStyle(fontFamilyFallback: ['test', 'test2'], package: 'p'); - expect(s8.fontFamilyFallback[0], 'packages/p/test'); - expect(s8.fontFamilyFallback[1], 'packages/p/test2'); - expect(s8.fontFamilyFallback.length, 2); + expect(s8.fontFamilyFallback![0], 'packages/p/test'); + expect(s8.fontFamilyFallback![1], 'packages/p/test2'); + expect(s8.fontFamilyFallback!.length, 2); const TextStyle s9 = TextStyle(package: 'p'); expect(s9.fontFamilyFallback, null); @@ -214,15 +212,15 @@ void main() { test('TextStyle font family fallback', () { const TextStyle s1 = TextStyle(fontFamilyFallback: ['Roboto', 'test']); - expect(s1.fontFamilyFallback[0], 'Roboto'); - expect(s1.fontFamilyFallback[1], 'test'); - expect(s1.fontFamilyFallback.length, 2); + expect(s1.fontFamilyFallback![0], 'Roboto'); + expect(s1.fontFamilyFallback![1], 'test'); + expect(s1.fontFamilyFallback!.length, 2); const TextStyle s2 = TextStyle(fontFamily: 'foo', fontFamilyFallback: ['Roboto', 'test']); - expect(s2.fontFamilyFallback[0], 'Roboto'); - expect(s2.fontFamilyFallback[1], 'test'); + expect(s2.fontFamilyFallback![0], 'Roboto'); + expect(s2.fontFamilyFallback![1], 'test'); expect(s2.fontFamily, 'foo'); - expect(s2.fontFamilyFallback.length, 2); + expect(s2.fontFamilyFallback!.length, 2); const TextStyle s3 = TextStyle(fontFamily: 'foo'); expect(s3.fontFamily, 'foo'); @@ -231,7 +229,7 @@ void main() { const TextStyle s4 = TextStyle(fontFamily: 'foo', fontFamilyFallback: []); expect(s4.fontFamily, 'foo'); expect(s4.fontFamilyFallback, []); - expect(s4.fontFamilyFallback.isEmpty, true); + expect(s4.fontFamilyFallback!.isEmpty, true); final ui.TextStyle uis1 = s2.getTextStyle(); expect(uis1.toString(), 'TextStyle(color: unspecified, decoration: unspecified, decorationColor: unspecified, decorationStyle: unspecified, decorationThickness: unspecified, fontWeight: unspecified, fontStyle: unspecified, textBaseline: unspecified, fontFamily: foo, fontFamilyFallback: [Roboto, test], fontSize: unspecified, letterSpacing: unspecified, wordSpacing: unspecified, height: unspecified, locale: unspecified, background: unspecified, foreground: unspecified, shadows: unspecified, fontFeatures: unspecified)'); @@ -259,8 +257,8 @@ void main() { expect(foo.merge(bar).merge(baz).debugLabel, '((foo).merge(bar)).merge(baz)'); expect(foo.copyWith().debugLabel, '(foo).copyWith'); expect(foo.apply().debugLabel, '(foo).apply'); - expect(TextStyle.lerp(foo, bar, 0.5).debugLabel, 'lerp(foo ⎯0.5→ bar)'); - expect(TextStyle.lerp(foo.merge(bar), baz, 0.51).copyWith().debugLabel, '(lerp((foo).merge(bar) ⎯0.5→ baz)).copyWith'); + expect(TextStyle.lerp(foo, bar, 0.5)!.debugLabel, 'lerp(foo ⎯0.5→ bar)'); + expect(TextStyle.lerp(foo.merge(bar), baz, 0.51)!.copyWith().debugLabel, '(lerp((foo).merge(bar) ⎯0.5→ baz)).copyWith'); }); test('TextStyle.hashCode', () { @@ -297,18 +295,18 @@ void main() { // apply expect(redPaintTextStyle.apply(color: blue).color, isNull); - expect(redPaintTextStyle.apply(color: blue).foreground.color, red); + expect(redPaintTextStyle.apply(color: blue).foreground!.color, red); expect(redTextStyle.apply(color: blue).color, blue); // lerp - expect(TextStyle.lerp(redTextStyle, blueTextStyle, .25).color, Color.lerp(red, blue, .25)); - expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).color, isNull); - expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).foreground.color, red); - expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .75).foreground.color, blue); + expect(TextStyle.lerp(redTextStyle, blueTextStyle, .25)!.color, Color.lerp(red, blue, .25)); + expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25)!.color, isNull); + expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25)!.foreground!.color, red); + expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .75)!.foreground!.color, blue); - expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).color, isNull); - expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).foreground.color, red); - expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75).foreground.color, blue); + expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25)!.color, isNull); + expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25)!.foreground!.color, red); + expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75)!.foreground!.color, blue); }); test('backgroundColor', () { @@ -351,18 +349,18 @@ void main() { // apply expect(redPaintTextStyle.apply(backgroundColor: blue).backgroundColor, isNull); - expect(redPaintTextStyle.apply(backgroundColor: blue).background.color, red); + expect(redPaintTextStyle.apply(backgroundColor: blue).background!.color, red); expect(redTextStyle.apply(backgroundColor: blue).backgroundColor, blue); // lerp - expect(TextStyle.lerp(redTextStyle, blueTextStyle, .25).backgroundColor, Color.lerp(red, blue, .25)); - expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).backgroundColor, isNull); - expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25).background.color, red); - expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .75).background.color, blue); + expect(TextStyle.lerp(redTextStyle, blueTextStyle, .25)!.backgroundColor, Color.lerp(red, blue, .25)); + expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25)!.backgroundColor, isNull); + expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .25)!.background!.color, red); + expect(TextStyle.lerp(redTextStyle, bluePaintTextStyle, .75)!.background!.color, blue); - expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).backgroundColor, isNull); - expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25).background.color, red); - expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75).background.color, blue); + expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25)!.backgroundColor, isNull); + expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .25)!.background!.color, red); + expect(TextStyle.lerp(redPaintTextStyle, bluePaintTextStyle, .75)!.background!.color, blue); }); test('TextStyle strut textScaleFactor', () { diff --git a/packages/flutter/test/rendering/annotated_region_test.dart b/packages/flutter/test/rendering/annotated_region_test.dart index 3aad4ce5c5..fb5d65cd4d 100644 --- a/packages/flutter/test/rendering/annotated_region_test.dart +++ b/packages/flutter/test/rendering/annotated_region_test.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/widgets.dart'; import '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/rendering/aspect_ratio_test.dart b/packages/flutter/test/rendering/aspect_ratio_test.dart index abbfaf6079..25e25876ae 100644 --- a/packages/flutter/test/rendering/aspect_ratio_test.dart +++ b/packages/flutter/test/rendering/aspect_ratio_test.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_test/flutter_test.dart'; diff --git a/packages/flutter/test/rendering/baseline_test.dart b/packages/flutter/test/rendering/baseline_test.dart index 5467764431..51a9c5c7b0 100644 --- a/packages/flutter/test/rendering/baseline_test.dart +++ b/packages/flutter/test/rendering/baseline_test.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'; import 'package:flutter/rendering.dart'; import '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/rendering/box_constraints_test.dart b/packages/flutter/test/rendering/box_constraints_test.dart index 809b00b5bb..f4e3c26aed 100644 --- a/packages/flutter/test/rendering/box_constraints_test.dart +++ b/packages/flutter/test/rendering/box_constraints_test.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'; @@ -70,12 +68,12 @@ void main() { minHeight: 11.0, maxHeight: 17.0, ); - BoxConstraints copy = BoxConstraints.lerp(null, constraints, 0.5); + BoxConstraints copy = BoxConstraints.lerp(null, constraints, 0.5)!; expect(copy.minWidth, moreOrLessEquals(1.5)); expect(copy.maxWidth, moreOrLessEquals(3.5)); expect(copy.minHeight, moreOrLessEquals(5.5)); expect(copy.maxHeight, moreOrLessEquals(8.5)); - copy = BoxConstraints.lerp(constraints, null, 0.5); + copy = BoxConstraints.lerp(constraints, null, 0.5)!; expect(copy.minWidth, moreOrLessEquals(1.5)); expect(copy.maxWidth, moreOrLessEquals(3.5)); expect(copy.minHeight, moreOrLessEquals(5.5)); @@ -85,7 +83,7 @@ void main() { maxWidth: 17.0, minHeight: 111.0, maxHeight: 117.0, - ), constraints, 0.2); + ), constraints, 0.2)!; expect(copy.minWidth, moreOrLessEquals(11.0)); expect(copy.maxWidth, moreOrLessEquals(15.0)); expect(copy.minHeight, moreOrLessEquals(91.0)); diff --git a/packages/flutter/test/rendering/box_test.dart b/packages/flutter/test/rendering/box_test.dart index aeb83c0c9c..a292e4eee3 100644 --- a/packages/flutter/test/rendering/box_test.dart +++ b/packages/flutter/test/rendering/box_test.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/gestures.dart'; import 'package:flutter/material.dart'; @@ -46,7 +44,7 @@ void main() { gradient: RadialGradient( center: Alignment.topLeft, radius: 1.8, - colors: [Colors.yellow[500], Colors.blue[500]], + colors: [Colors.yellow[500]!, Colors.blue[500]!], ), boxShadow: kElevationToShadow[3], ), @@ -57,7 +55,7 @@ void main() { }); test('performLayout error message', () { - FlutterError result; + late FlutterError result; try { MissingPerformLayoutRenderBox().performLayout(); } on FlutterError catch (e) { @@ -95,7 +93,7 @@ void main() { // BoxParentData. paddingBox.parentData = ParentData(); - FlutterError result; + late FlutterError result; try { root.applyPaintTransform(paddingBox, Matrix4.identity()); } on FlutterError catch (e) { @@ -151,7 +149,7 @@ void main() { final MissingPerformLayoutRenderBox testBox = MissingPerformLayoutRenderBox(); { - FlutterError result; + late FlutterError result; try { testBox.triggerExceptionSettingSizeOutsideOfLayout(); } on FlutterError catch (e) { @@ -173,7 +171,7 @@ void main() { expect(result.diagnostics.where((DiagnosticsNode node) => node.level == DiagnosticLevel.hint), isEmpty); } { - FlutterError result; + late FlutterError result; try { testBox.debugAdoptSize(root.size); } on FlutterError catch (e) { @@ -392,7 +390,7 @@ void main() { layout(unconstrained, constraints: viewport); { - FlutterError result; + late FlutterError result; try { unconstrained.getMinIntrinsicWidth(-1); } on FlutterError catch (e) { @@ -420,7 +418,7 @@ void main() { } { - FlutterError result; + late FlutterError result; try { unconstrained.getMinIntrinsicHeight(-1); } on FlutterError catch (e) { @@ -448,7 +446,7 @@ void main() { } { - FlutterError result; + late FlutterError result; try { unconstrained.getMaxIntrinsicWidth(-1); } on FlutterError catch (e) { @@ -476,7 +474,7 @@ void main() { } { - FlutterError result; + late FlutterError result; try { unconstrained.getMaxIntrinsicHeight(-1); } on FlutterError catch (e) { @@ -934,7 +932,7 @@ void main() { final RenderBox renderObject = RenderConstrainedBox( additionalConstraints: const BoxConstraints().tighten(height: 100.0), ); - FlutterError result; + late FlutterError result; try { final BoxHitTestResult result = BoxHitTestResult(); renderObject.hitTest(result, position: Offset.zero); @@ -971,7 +969,7 @@ void main() { } { - FlutterError result; + late FlutterError result; final FakeMissingSizeRenderBox renderObject = FakeMissingSizeRenderBox(); layout(renderObject); renderObject.fakeMissingSize = true; @@ -1019,16 +1017,9 @@ void main() { }); }); - test('BoxConstraints parameters should be non-null', () { - expect(() => BoxConstraints(minWidth: null), throwsAssertionError); - expect(() => BoxConstraints(maxWidth: null), throwsAssertionError); - expect(() => BoxConstraints(minHeight: null), throwsAssertionError); - expect(() => BoxConstraints(maxHeight: null), throwsAssertionError); - }); - test('Error message when size has not been set in RenderBox performLayout should be well versed', () { - FlutterErrorDetails errorDetails; - final FlutterExceptionHandler oldHandler = FlutterError.onError; + late FlutterErrorDetails errorDetails; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; FlutterError.onError = (FlutterErrorDetails details) { errorDetails = details; }; diff --git a/packages/flutter/test/rendering/cached_intrinsics_test.dart b/packages/flutter/test/rendering/cached_intrinsics_test.dart index fcba20cda0..87ecf30dc0 100644 --- a/packages/flutter/test/rendering/cached_intrinsics_test.dart +++ b/packages/flutter/test/rendering/cached_intrinsics_test.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 '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/rendering/constraints_test.dart b/packages/flutter/test/rendering/constraints_test.dart index 398a43d1e1..747333a0e8 100644 --- a/packages/flutter/test/rendering/constraints_test.dart +++ b/packages/flutter/test/rendering/constraints_test.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 '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/rendering/debug_overflow_indicator_test.dart b/packages/flutter/test/rendering/debug_overflow_indicator_test.dart index 5929fda362..ef63120ec0 100644 --- a/packages/flutter/test/rendering/debug_overflow_indicator_test.dart +++ b/packages/flutter/test/rendering/debug_overflow_indicator_test.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/widgets.dart'; diff --git a/packages/flutter/test/rendering/debug_test.dart b/packages/flutter/test/rendering/debug_test.dart index b58d327c88..1b9b047ee5 100644 --- a/packages/flutter/test/rendering/debug_test.dart +++ b/packages/flutter/test/rendering/debug_test.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:vector_math/vector_math_64.dart'; diff --git a/packages/flutter/test/rendering/dynamic_intrinsics_test.dart b/packages/flutter/test/rendering/dynamic_intrinsics_test.dart index d797314ca0..dc7205de85 100644 --- a/packages/flutter/test/rendering/dynamic_intrinsics_test.dart +++ b/packages/flutter/test/rendering/dynamic_intrinsics_test.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 '../flutter_test_alternative.dart'; @@ -33,7 +31,7 @@ class RenderFixedSize extends RenderBox { } class RenderParentSize extends RenderProxyBox { - RenderParentSize({ RenderBox child }) : super(child); + RenderParentSize({ required RenderBox child }) : super(child); @override bool get sizedByParent => true; @@ -45,19 +43,19 @@ class RenderParentSize extends RenderProxyBox { @override void performLayout() { - child.layout(constraints); + child!.layout(constraints); } } class RenderIntrinsicSize extends RenderProxyBox { - RenderIntrinsicSize({ RenderBox child }) : super(child); + RenderIntrinsicSize({ required RenderBox child }) : super(child); @override void performLayout() { - child.layout(constraints); + child!.layout(constraints); size = Size( - child.getMinIntrinsicWidth(double.infinity), - child.getMinIntrinsicHeight(double.infinity), + child!.getMinIntrinsicWidth(double.infinity), + child!.getMinIntrinsicHeight(double.infinity), ); } } diff --git a/packages/flutter/test/rendering/editable_gesture_test.dart b/packages/flutter/test/rendering/editable_gesture_test.dart index cba06e513e..5a54b8ea1c 100644 --- a/packages/flutter/test/rendering/editable_gesture_test.dart +++ b/packages/flutter/test/rendering/editable_gesture_test.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/material.dart'; import 'package:flutter/rendering.dart'; @@ -42,7 +40,7 @@ void main() { editable.layout(BoxConstraints.loose(const Size(1000.0, 1000.0))); final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () { }); - final _PointerRouterSpy spy = GestureBinding.instance.pointerRouter as _PointerRouterSpy; + final _PointerRouterSpy spy = GestureBinding.instance!.pointerRouter as _PointerRouterSpy; editable.attach(owner); // This should register pointer into GestureBinding.instance.pointerRouter. editable.handleEvent(const PointerDownEvent(), BoxHitTestEntry(editable, const Offset(10,10))); @@ -64,7 +62,7 @@ class FakeEditableTextState extends TextSelectionDelegate with Fake { } class _PointerRouterSpy extends PointerRouter { int routeCount = 0; @override - void addRoute(int pointer, PointerRoute route, [Matrix4 transform]) { + void addRoute(int pointer, PointerRoute route, [Matrix4? transform]) { super.addRoute(pointer, route, transform); routeCount++; }