diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index b4a90c0c58..c5c31736d0 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -1897,7 +1897,7 @@ abstract class _NumProperty extends DiagnosticsProperty { _NumProperty.lazy( String name, - ComputePropertyValueCallback computeValue, { + ComputePropertyValueCallback computeValue, { String? ifNull, this.unit, bool showName = true, @@ -1984,7 +1984,7 @@ class DoubleProperty extends _NumProperty { /// The [showName] and [level] arguments must not be null. DoubleProperty.lazy( String name, - ComputePropertyValueCallback computeValue, { + ComputePropertyValueCallback computeValue, { String? ifNull, bool showName = true, String? unit, @@ -2480,7 +2480,7 @@ class ObjectFlagProperty extends DiagnosticsProperty { /// only one flag, and is preferred if there is only one entry. /// * [IterableProperty], which provides similar functionality describing /// the values a collection of objects. -class FlagsSummary extends DiagnosticsProperty> { +class FlagsSummary extends DiagnosticsProperty> { /// Create a summary for multiple properties, indicating whether each of them /// is present (non-null) or absent (null). /// @@ -2488,7 +2488,7 @@ class FlagsSummary extends DiagnosticsProperty> { /// null. FlagsSummary( String name, - Map value, { + Map value, { String? ifEmpty, bool showName = true, bool showSeparator = true, @@ -2507,7 +2507,7 @@ class FlagsSummary extends DiagnosticsProperty> { ); @override - Map get value => super.value!; + Map get value => super.value!; @override String valueToString({TextTreeConfiguration? parentConfiguration}) { @@ -2545,7 +2545,7 @@ class FlagsSummary extends DiagnosticsProperty> { return json; } - bool _hasNonNullEntry() => value.values.any((T o) => o != null); + bool _hasNonNullEntry() => value.values.any((T? o) => o != null); // An iterable of each entry's description in [value]. // @@ -2554,7 +2554,7 @@ class FlagsSummary extends DiagnosticsProperty> { // For a null value, it is omitted unless `includeEmtpy` is true and // [ifEntryNull] contains a corresponding description. Iterable _formattedValues() sync* { - for (final MapEntry entry in value.entries) { + for (final MapEntry entry in value.entries) { if (entry.value != null) { yield entry.key; } @@ -2567,7 +2567,7 @@ class FlagsSummary extends DiagnosticsProperty> { /// May throw exception if accessing the property would throw an exception /// and callers must handle that case gracefully. For example, accessing a /// property may trigger an assert that layout constraints were violated. -typedef ComputePropertyValueCallback = T Function(); +typedef ComputePropertyValueCallback = T? Function(); /// Property with a [value] of type [T]. /// @@ -2651,7 +2651,7 @@ class DiagnosticsProperty extends DiagnosticsNode { DiagnosticLevel level = DiagnosticLevel.info, }) : assert(showName != null), assert(showSeparator != null), - assert(defaultValue == kNoDefaultValue || defaultValue is T), + assert(defaultValue == kNoDefaultValue || defaultValue is T?), assert(missingIfNull != null), assert(style != null), assert(level != null), @@ -2848,7 +2848,8 @@ class DiagnosticsProperty extends DiagnosticsNode { /// of the property is downgraded to [DiagnosticLevel.fine] as the property /// value is uninteresting. /// - /// [defaultValue] has type [T] or is [kNoDefaultValue]. + /// The [defaultValue] is [kNoDefaultValue] by default. Otherwise it must be of + /// type `T?`. final Object? defaultValue; final DiagnosticLevel _defaultLevel; diff --git a/packages/flutter/lib/src/semantics/binding.dart b/packages/flutter/lib/src/semantics/binding.dart index 37f7fbc54c..4a6ed1f2d1 100644 --- a/packages/flutter/lib/src/semantics/binding.dart +++ b/packages/flutter/lib/src/semantics/binding.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:ui' as ui show AccessibilityFeatures, SemanticsUpdateBuilder; import 'package:flutter/foundation.dart'; diff --git a/packages/flutter/test/animation/animation_controller_test.dart b/packages/flutter/test/animation/animation_controller_test.dart index 1bf0c97a3c..e634487b57 100644 --- a/packages/flutter/test/animation/animation_controller_test.dart +++ b/packages/flutter/test/animation/animation_controller_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'; @@ -19,7 +17,7 @@ import '../scheduler/scheduler_tester.dart'; void main() { setUp(() { WidgetsFlutterBinding.ensureInitialized(); - WidgetsBinding.instance.resetEpoch(); + WidgetsBinding.instance!.resetEpoch(); ui.window.onBeginFrame = null; ui.window.onDrawFrame = null; }); @@ -350,7 +348,7 @@ void main() { expect(controller.repeat, throwsFlutterError); controller.dispose(); - FlutterError result; + FlutterError? result; try { controller.dispose(); } on FlutterError catch (e) { @@ -358,7 +356,7 @@ void main() { } expect(result, isNotNull); expect( - result.toStringDeep(), + result!.toStringDeep(), equalsIgnoringHashCodes( 'FlutterError\n' ' AnimationController.dispose() called more than once.\n' @@ -482,7 +480,7 @@ void main() { controller.forward(from: 0.2); expect(controller.value, 0.2); controller.animateTo(1.0, duration: Duration.zero); - expect(SchedulerBinding.instance.transientCallbackCount, equals(0), reason: 'Expected no animation.'); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0), reason: 'Expected no animation.'); expect(controller.value, 1.0); }); diff --git a/packages/flutter/test/animation/animation_sheet_test.dart b/packages/flutter/test/animation/animation_sheet_test.dart index 15102ec06c..de09d57c2d 100644 --- a/packages/flutter/test/animation/animation_sheet_test.dart +++ b/packages/flutter/test/animation/animation_sheet_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'; import 'package:flutter/cupertino.dart'; @@ -84,8 +82,8 @@ class _DecuplePixels extends StatefulWidget { State createState() => _DecuplePixelsState(); } -class _DecuplePixelsState extends State<_DecuplePixels> with SingleTickerProviderStateMixin { - AnimationController _controller; +class _DecuplePixelsState extends State<_DecuplePixels> with SingleTickerProviderStateMixin<_DecuplePixels> { + late AnimationController _controller; @override void initState() { @@ -107,7 +105,7 @@ class _DecuplePixelsState extends State<_DecuplePixels> with SingleTickerProvide Widget build(BuildContext context) { return AnimatedBuilder( animation: _controller.view, - builder: (BuildContext context, Widget child) { + builder: (BuildContext context, Widget? child) { return CustomPaint( painter: _PaintDecuplePixels(_controller.value), ); @@ -132,7 +130,7 @@ class _PaintDecuplePixels extends CustomPainter { final Rect rect = RectTween( begin: const Rect.fromLTWH(1, 1, 1, 1), end: const Rect.fromLTWH(11, 1, 1, 1), - ).transform(value); + ).transform(value)!; canvas.drawRect(rect, Paint()..color = Colors.yellow); final Paint black = Paint()..color = Colors.black; canvas diff --git a/packages/flutter/test/animation/animations_test.dart b/packages/flutter/test/animation/animations_test.dart index 2b94a30f40..66f8a6eb7e 100644 --- a/packages/flutter/test/animation/animations_test.dart +++ b/packages/flutter/test/animation/animations_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'; @@ -21,7 +19,7 @@ class BogusCurve extends Curve { void main() { setUp(() { WidgetsFlutterBinding.ensureInitialized(); - WidgetsBinding.instance.resetEpoch(); + WidgetsBinding.instance!.resetEpoch(); ui.window.onBeginFrame = null; ui.window.onDrawFrame = null; }); @@ -240,14 +238,14 @@ void main() { vsync: const TestVSync(), ); final CurvedAnimation curved = CurvedAnimation(parent: controller, curve: BogusCurve()); - FlutterError error; + FlutterError? error; try { curved.value; } on FlutterError catch (e) { error = e; } expect(error, isNotNull); - expect(error.toStringDeep(), matches( + expect(error!.toStringDeep(), matches( // RegExp matcher is required here due to flutter web and flutter mobile generating // slightly different floating point numbers // in Flutter web 0.0 sometimes just appears as 0. or 0 diff --git a/packages/flutter/test/animation/curves_test.dart b/packages/flutter/test/animation/curves_test.dart index 48f70fd276..b8bc87b863 100644 --- a/packages/flutter/test/animation/curves_test.dart +++ b/packages/flutter/test/animation/curves_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'; @@ -275,9 +273,6 @@ void main() { }); test('CatmullRomSpline enforces contract', () { - expect(() { - CatmullRomSpline(null); - }, throwsAssertionError); expect(() { CatmullRomSpline(const []); }, throwsAssertionError); @@ -327,9 +322,6 @@ void main() { }); test('CatmullRomSpline enforces contract when precomputed', () { - expect(() { - CatmullRomSpline.precompute(null); - }, throwsAssertionError); expect(() { CatmullRomSpline.precompute(const []); }, throwsAssertionError); @@ -395,9 +387,6 @@ void main() { }); test('CatmullRomCurve enforces contract', () { - expect(() { - CatmullRomCurve(null); - }, throwsAssertionError); expect(() { CatmullRomCurve(const []); }, throwsAssertionError); @@ -517,9 +506,6 @@ void main() { }); test('CatmullRomCurve enforces contract when precomputed', () { - expect(() { - CatmullRomCurve.precompute(null); - }, throwsAssertionError); expect(() { CatmullRomCurve.precompute(const []); }, throwsAssertionError); diff --git a/packages/flutter/test/animation/futures_test.dart b/packages/flutter/test/animation/futures_test.dart index 3a92903e4b..e389f1c0cf 100644 --- a/packages/flutter/test/animation/futures_test.dart +++ b/packages/flutter/test/animation/futures_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/animation.dart'; import 'package:flutter/scheduler.dart'; diff --git a/packages/flutter/test/animation/iteration_patterns_test.dart b/packages/flutter/test/animation/iteration_patterns_test.dart index 9ab1c31524..2e9ab618dd 100644 --- a/packages/flutter/test/animation/iteration_patterns_test.dart +++ b/packages/flutter/test/animation/iteration_patterns_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/animation.dart'; import 'package:flutter/widgets.dart'; @@ -11,7 +9,7 @@ import 'package:flutter/widgets.dart'; void main() { setUp(() { WidgetsFlutterBinding.ensureInitialized(); - WidgetsBinding.instance.resetEpoch(); + WidgetsBinding.instance!.resetEpoch(); }); test('AnimationController with mutating listener', () { @@ -92,7 +90,7 @@ void main() { final VoidCallback listener1 = () { log.add('listener1'); }; final VoidCallback badListener = () { log.add('badListener'); - throw null; + throw ArgumentError(); }; final VoidCallback listener2 = () { log.add('listener2'); }; @@ -101,7 +99,7 @@ void main() { controller.addListener(listener2); controller.value = 0.2; expect(log, ['listener1', 'badListener', 'listener2']); - expect(tester.takeException(), isNullThrownError); + expect(tester.takeException(), isArgumentError); log.clear(); }); @@ -115,7 +113,7 @@ void main() { final AnimationStatusListener listener1 = (AnimationStatus status) { log.add('listener1'); }; final AnimationStatusListener badListener = (AnimationStatus status) { log.add('badListener'); - throw null; + throw ArgumentError(); }; final AnimationStatusListener listener2 = (AnimationStatus status) { log.add('listener2'); }; @@ -124,7 +122,7 @@ void main() { controller.addStatusListener(listener2); controller.forward(); expect(log, ['listener1', 'badListener', 'listener2']); - expect(tester.takeException(), isNullThrownError); + expect(tester.takeException(), isArgumentError); log.clear(); controller.dispose(); }); diff --git a/packages/flutter/test/animation/tween_test.dart b/packages/flutter/test/animation/tween_test.dart index 6d338d4384..71565febb4 100644 --- a/packages/flutter/test/animation/tween_test.dart +++ b/packages/flutter/test/animation/tween_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/animation.dart'; import 'package:flutter/widgets.dart'; diff --git a/packages/flutter/test/foundation/assertions_test.dart b/packages/flutter/test/foundation/assertions_test.dart index e11f1c56ea..87c3c83b92 100644 --- a/packages/flutter/test/foundation/assertions_test.dart +++ b/packages/flutter/test/foundation/assertions_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 '../flutter_test_alternative.dart'; @@ -442,7 +440,7 @@ void main() { ], replacement: 'test', ); - final List reasons = List(2); + final List reasons = List.filled(2, null); filter.filter( const [ StackFrame(className: 'TestClass', method: 'test1', packageScheme: 'package', package: 'test', packagePath: 'blah.dart', line: 1, column: 1, number: 0, source: ''), @@ -450,6 +448,6 @@ void main() { ], reasons, ); - expect(reasons, List(2)); + expect(reasons, List.filled(2, null)); }); } diff --git a/packages/flutter/test/foundation/bit_field_test.dart b/packages/flutter/test/foundation/bit_field_test.dart index 2e54d63c13..977532ffbf 100644 --- a/packages/flutter/test/foundation/bit_field_test.dart +++ b/packages/flutter/test/foundation/bit_field_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 - @TestOn('!chrome') import 'package:flutter/foundation.dart'; diff --git a/packages/flutter/test/foundation/caching_iterable_test.dart b/packages/flutter/test/foundation/caching_iterable_test.dart index ca950b9c83..82a0a6428a 100644 --- a/packages/flutter/test/foundation/caching_iterable_test.dart +++ b/packages/flutter/test/foundation/caching_iterable_test.dart @@ -2,13 +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 'package:flutter/foundation.dart'; import '../flutter_test_alternative.dart'; -int yieldCount; +int yieldCount = 0; Iterable range(int start, int end) sync* { assert(yieldCount == 0); diff --git a/packages/flutter/test/foundation/capture_output.dart b/packages/flutter/test/foundation/capture_output.dart index 50b161f47e..bf07652afe 100644 --- a/packages/flutter/test/foundation/capture_output.dart +++ b/packages/flutter/test/foundation/capture_output.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'dart:async'; import 'package:flutter/foundation.dart'; diff --git a/packages/flutter/test/foundation/change_notifier_test.dart b/packages/flutter/test/foundation/change_notifier_test.dart index cb3f6a8ab5..1ec3c64e35 100644 --- a/packages/flutter/test/foundation/change_notifier_test.dart +++ b/packages/flutter/test/foundation/change_notifier_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_test/flutter_test.dart'; @@ -41,7 +39,7 @@ void main() { final VoidCallback listener2 = () { log.add('listener2'); }; final VoidCallback badListener = () { log.add('badListener'); - throw null; + throw ArgumentError(); }; final TestNotifier test = TestNotifier(); @@ -95,7 +93,7 @@ void main() { test.addListener(badListener); test.notify(); expect(log, ['listener', 'listener2', 'listener1', 'badListener']); - expect(tester.takeException(), isNullThrownError); + expect(tester.takeException(), isArgumentError); log.clear(); test.addListener(listener1); @@ -105,7 +103,7 @@ void main() { test.addListener(listener2); test.notify(); expect(log, ['badListener', 'listener1', 'listener2']); - expect(tester.takeException(), isNullThrownError); + expect(tester.takeException(), isArgumentError); log.clear(); }); @@ -238,7 +236,7 @@ void main() { final TestNotifier source2 = TestNotifier(); final List log = []; - final Listenable merged = Listenable.merge([null, source1, null, source2, null]); + final Listenable merged = Listenable.merge([null, source1, null, source2, null]); final VoidCallback listener = () { log.add('listener'); }; merged.addListener(listener); @@ -300,7 +298,7 @@ void main() { Listenable listenableUnderTest = Listenable.merge([]); expect(listenableUnderTest.toString(), 'Listenable.merge([])'); - listenableUnderTest = Listenable.merge([null]); + listenableUnderTest = Listenable.merge([null]); expect(listenableUnderTest.toString(), 'Listenable.merge([null])'); listenableUnderTest = Listenable.merge([source1]); @@ -315,7 +313,7 @@ void main() { "Listenable.merge([Instance of 'TestNotifier', Instance of 'TestNotifier'])", ); - listenableUnderTest = Listenable.merge([null, source2]); + listenableUnderTest = Listenable.merge([null, source2]); expect( listenableUnderTest.toString(), "Listenable.merge([null, Instance of 'TestNotifier'])", @@ -382,14 +380,14 @@ void main() { test('Throws FlutterError when disposed and called', () { final TestNotifier testNotifier = TestNotifier(); testNotifier.dispose(); - FlutterError error; + FlutterError? error; try { testNotifier.dispose(); } on FlutterError catch (e) { error = e; } expect(error, isNotNull); - expect(error, isFlutterError); + expect(error!, isFlutterError); expect(error.toStringDeep(), equalsIgnoringHashCodes( 'FlutterError\n' ' A TestNotifier was used after being disposed.\n' diff --git a/packages/flutter/test/foundation/collections_test.dart b/packages/flutter/test/foundation/collections_test.dart index 056d20ce06..ee7ce63fe3 100644 --- a/packages/flutter/test/foundation/collections_test.dart +++ b/packages/flutter/test/foundation/collections_test.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. -// @dart = 2.8 import 'dart:math'; import 'package:flutter/src/foundation/collections.dart'; @@ -64,10 +63,8 @@ void main() { test('MergeSortRandom', () { final Random random = Random(); for (int i = 0; i < 250; i += 1) { - final List list = List(i); - for (int j = 0; j < i; j++) { - list[j] = random.nextInt(i); // Expect some equal elements. - } + // Expect some equal elements. + final List list = List.generate(i, (int j) => random.nextInt(i)); mergeSort(list); for (int j = 1; j < i; j++) { expect(list[j - 1], lessThanOrEqualTo(list[j])); @@ -80,14 +77,12 @@ void main() { // larger case where the internal moving insertion sort is used // larger cases with multiple splittings, numbers just around a power of 2. for (final int size in [8, 50, 511, 512, 513]) { - final List list = List(size); // Class OC compares using id. // With size elements with id's in the range 0..size/4, a number of // collisions are guaranteed. These should be sorted so that the 'order' // part of the objects are still in order. - for (int i = 0; i < size; i++) { - list[i] = OrderedComparable(random.nextInt(size >> 2), i); - } + final List list = List.generate( + size, (int i) => OrderedComparable(random.nextInt(size >> 2), i)); mergeSort(list); OrderedComparable prev = list[0]; for (int i = 1; i < size; i++) { @@ -126,10 +121,8 @@ void main() { test('MergeSortSpecialCases', () { for (final int size in [511, 512, 513]) { // All equal. - final List list = List(size); - for (int i = 0; i < size; i++) { - list[i] = OrderedComparable(0, i); - } + final List list = List.generate( + size, (int i) => OrderedComparable(0, i)); mergeSort(list); for (int i = 0; i < size; i++) { expect(list[i].order, equals(i)); diff --git a/packages/flutter/test/foundation/consolidate_response_test.dart b/packages/flutter/test/foundation/consolidate_response_test.dart index 2b30beca9b..b4775f9abe 100644 --- a/packages/flutter/test/foundation/consolidate_response_test.dart +++ b/packages/flutter/test/foundation/consolidate_response_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 - @TestOn('!chrome') import 'dart:async'; @@ -18,7 +16,7 @@ final Uint8List chunkOne = Uint8List.fromList([0, 1, 2, 3, 4, 5]); final Uint8List chunkTwo = Uint8List.fromList([6, 7, 8, 9, 10]); void main() { group(consolidateHttpClientResponseBytes, () { - MockHttpClientResponse response; + late MockHttpClientResponse response; setUp(() { response = MockHttpClientResponse( @@ -54,11 +52,11 @@ void main() { test('Notifies onBytesReceived for every chunk of bytes', () async { final int syntheticTotal = (chunkOne.length + chunkTwo.length) * 2; response.contentLength = syntheticTotal; - final List records = []; + final List records = []; await consolidateHttpClientResponseBytes( response, - onBytesReceived: (int cumulative, int total) { - records.addAll([cumulative, total]); + onBytesReceived: (int cumulative, int? total) { + records.addAll([cumulative, total]); }, ); @@ -81,7 +79,7 @@ void main() { response.contentLength = -1; final Future> result = consolidateHttpClientResponseBytes( response, - onBytesReceived: (int cumulative, int total) { + onBytesReceived: (int cumulative, int? total) { throw 'misbehaving callback'; }, ); @@ -113,11 +111,11 @@ void main() { test('Notifies onBytesReceived with gzipped numbers', () async { response.contentLength = gzipped.length; - final List records = []; + final List records = []; await consolidateHttpClientResponseBytes( response, - onBytesReceived: (int cumulative, int total) { - records.addAll([cumulative, total]); + onBytesReceived: (int cumulative, int? total) { + records.addAll([cumulative, total]); }, ); @@ -133,15 +131,15 @@ void main() { final int syntheticTotal = (chunkOne.length + chunkTwo.length) * 2; response.compressionState = HttpClientResponseCompressionState.decompressed; response.contentLength = syntheticTotal; - final List records = []; + final List records = []; await consolidateHttpClientResponseBytes( response, - onBytesReceived: (int cumulative, int total) { - records.addAll([cumulative, total]); + onBytesReceived: (int cumulative, int? total) { + records.addAll([cumulative, total]); }, ); - expect(records, [ + expect(records, [ gzippedChunkOne.length, null, gzipped.length, @@ -153,7 +151,7 @@ void main() { } class MockHttpClientResponse extends Fake implements HttpClientResponse { - MockHttpClientResponse({this.error, this.chunkOne, this.chunkTwo}); + MockHttpClientResponse({this.error, this.chunkOne = const [], this.chunkTwo = const []}); final dynamic error; final List chunkOne; @@ -166,10 +164,10 @@ class MockHttpClientResponse extends Fake implements HttpClientResponse { HttpClientResponseCompressionState compressionState = HttpClientResponseCompressionState.notCompressed; @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}) { if (error != null) { return Stream>.fromFuture( - Future>.error(error)).listen( + Future>.error(error as Object)).listen( onData, onDone: onDone, onError: onError, diff --git a/packages/flutter/test/foundation/constants_test.dart b/packages/flutter/test/foundation/constants_test.dart index c895edee86..f0083d012e 100644 --- a/packages/flutter/test/foundation/constants_test.dart +++ b/packages/flutter/test/foundation/constants_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 - @TestOn('!chrome') // This test is not intended to run on the web. import 'package:flutter/foundation.dart'; import '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/foundation/covariant_templates_test.dart b/packages/flutter/test/foundation/covariant_templates_test.dart index 2342e3d459..1b0cdeb7b7 100644 --- a/packages/flutter/test/foundation/covariant_templates_test.dart +++ b/packages/flutter/test/foundation/covariant_templates_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'; class X {} @@ -11,7 +9,7 @@ class X {} class Y extends X {} class A { - U u; + U? u; } void main() { diff --git a/packages/flutter/test/foundation/debug_test.dart b/packages/flutter/test/foundation/debug_test.dart index 34b8958514..d5effab542 100644 --- a/packages/flutter/test/foundation/debug_test.dart +++ b/packages/flutter/test/foundation/debug_test.dart @@ -2,21 +2,19 @@ // 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_test/flutter_test.dart'; void main() { group('debugInstrumentAction', () { - DebugPrintCallback originalDebugPrintCallback; - StringBuffer printBuffer; + late DebugPrintCallback originalDebugPrintCallback; + late StringBuffer printBuffer; setUp(() { debugInstrumentationEnabled = true; printBuffer = StringBuffer(); originalDebugPrintCallback = debugPrint; - debugPrint = (String message, { int wrapWidth }) { + debugPrint = (String? message, { int? wrapWidth }) { printBuffer.writeln(message); }; }); diff --git a/packages/flutter/test/foundation/defines_test.dart b/packages/flutter/test/foundation/defines_test.dart index 41d2d10a44..daf5835788 100644 --- a/packages/flutter/test/foundation/defines_test.dart +++ b/packages/flutter/test/foundation/defines_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_test/flutter_test.dart'; diff --git a/packages/flutter/test/foundation/diagnostics_json_test.dart b/packages/flutter/test/foundation/diagnostics_json_test.dart index 33ae10b8f4..d02152f130 100644 --- a/packages/flutter/test/foundation/diagnostics_json_test.dart +++ b/packages/flutter/test/foundation/diagnostics_json_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/material.dart'; import 'package:flutter/widgets.dart'; @@ -13,7 +11,7 @@ void main() { test('Element diagnostics json includes widgetRuntimeType', () async { final Element element = _TestElement(); - final Map json = element.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate()); + final Map json = element.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate()); expect(json['widgetRuntimeType'], 'Placeholder'); expect(json['stateful'], isFalse); }); @@ -21,7 +19,7 @@ void main() { test('StatefulElement diagnostics are stateful', () { final Element element = StatefulElement(const Tooltip(message: 'foo')); - final Map json = element.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate()); + final Map json = element.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate()); expect(json['widgetRuntimeType'], 'Tooltip'); expect(json['stateful'], isTrue); }); @@ -70,13 +68,13 @@ void main() { ); test('default', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate()); + final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate()); expect(result.containsKey('properties'), isFalse); expect(result.containsKey('children'), isFalse); }); test('subtreeDepth 1', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(subtreeDepth: 1)); + final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(subtreeDepth: 1)); expect(result.containsKey('properties'), isFalse); final List> children = result['children'] as List>; expect(children[0].containsKey('children'), isFalse); @@ -85,7 +83,7 @@ void main() { }); test('subtreeDepth 5', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(subtreeDepth: 5)); + final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(subtreeDepth: 5)); expect(result.containsKey('properties'), isFalse); final List> children = result['children'] as List>; expect(children[0]['children'], hasLength(0)); @@ -94,13 +92,13 @@ void main() { }); test('includeProperties', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(includeProperties: true)); + final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate(includeProperties: true)); expect(result.containsKey('children'), isFalse); expect(result['properties'], hasLength(7)); }); test('includeProperties with subtreedepth 1', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(const DiagnosticsSerializationDelegate( includeProperties: true, subtreeDepth: 1, )); @@ -113,7 +111,7 @@ void main() { }); test('additionalNodeProperties', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(const TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(const TestDiagnosticsSerializationDelegate( includeProperties: true, subtreeDepth: 1, additionalNodePropertiesMap: { @@ -131,7 +129,7 @@ void main() { }); test('filterProperties - sublist', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( includeProperties: true, propertyFilter: (List nodes, DiagnosticsNode owner) { return nodes.whereType().toList(); @@ -144,7 +142,7 @@ void main() { test('filterProperties - replace', () { bool replaced = false; - final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( includeProperties: true, propertyFilter: (List nodes, DiagnosticsNode owner) { if (replaced) { @@ -162,7 +160,7 @@ void main() { }); test('filterChildren - sublist', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( subtreeDepth: 1, childFilter: (List nodes, DiagnosticsNode owner) { return nodes.where((DiagnosticsNode node) => node.getProperties().isEmpty).toList(); @@ -173,7 +171,7 @@ void main() { }); test('filterChildren - replace', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( subtreeDepth: 1, childFilter: (List nodes, DiagnosticsNode owner) { return nodes.expand((DiagnosticsNode node) => node.getChildren()).toList(); @@ -185,10 +183,10 @@ void main() { }); test('nodeTruncator', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( subtreeDepth: 5, includeProperties: true, - nodeTruncator: (List nodes, DiagnosticsNode owner) { + nodeTruncator: (List nodes, DiagnosticsNode? owner) { return nodes.take(2).toList(); }, )); @@ -202,7 +200,7 @@ void main() { }); test('delegateForAddingNodes', () { - final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( + final Map result = testTree.toDiagnosticsNode().toJsonMap(TestDiagnosticsSerializationDelegate( subtreeDepth: 5, includeProperties: true, nodeDelegator: (DiagnosticsNode node, DiagnosticsSerializationDelegate delegate) { @@ -234,7 +232,7 @@ class _TestElement extends Element { class TestTree extends Object with DiagnosticableTreeMixin { TestTree({ - this.name, + this.name = '', this.style, this.children = const [], this.properties = const [], @@ -243,7 +241,7 @@ class TestTree extends Object with DiagnosticableTreeMixin { final String name; final List children; final List properties; - final DiagnosticsTreeStyle style; + final DiagnosticsTreeStyle? style; @override List debugDescribeChildren() => [ @@ -258,12 +256,16 @@ class TestTree extends Object with DiagnosticableTreeMixin { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); if (style != null) - properties.defaultDiagnosticsTreeStyle = style; + properties.defaultDiagnosticsTreeStyle = style!; this.properties.forEach(properties.add); } } +typedef NodeDelegator = DiagnosticsSerializationDelegate Function(DiagnosticsNode node, TestDiagnosticsSerializationDelegate delegate); +typedef NodeTruncator = List Function(List nodes, DiagnosticsNode? owner); +typedef NodeFilter = List Function(List nodes, DiagnosticsNode owner); + class TestDiagnosticsSerializationDelegate implements DiagnosticsSerializationDelegate { const TestDiagnosticsSerializationDelegate({ this.includeProperties = false, @@ -276,10 +278,10 @@ class TestDiagnosticsSerializationDelegate implements DiagnosticsSerializationDe }); final Map additionalNodePropertiesMap; - final List Function(List nodes, DiagnosticsNode owner) childFilter; - final List Function(List nodes, DiagnosticsNode owner) propertyFilter; - final List Function(List nodes, DiagnosticsNode owner) nodeTruncator; - final DiagnosticsSerializationDelegate Function(DiagnosticsNode node, TestDiagnosticsSerializationDelegate delegate) nodeDelegator; + final NodeFilter? childFilter; + final NodeFilter? propertyFilter; + final NodeTruncator? nodeTruncator; + final NodeDelegator? nodeDelegator; @override Map additionalNodeProperties(DiagnosticsNode node) { @@ -289,7 +291,7 @@ class TestDiagnosticsSerializationDelegate implements DiagnosticsSerializationDe @override DiagnosticsSerializationDelegate delegateForNode(DiagnosticsNode node) { if (nodeDelegator != null) { - return nodeDelegator(node, this); + return nodeDelegator!(node, this); } return subtreeDepth > 0 ? copyWith(subtreeDepth: subtreeDepth - 1) : this; } @@ -299,12 +301,12 @@ class TestDiagnosticsSerializationDelegate implements DiagnosticsSerializationDe @override List filterChildren(List nodes, DiagnosticsNode owner) { - return childFilter != null ? childFilter(nodes, owner) : nodes; + return childFilter?.call(nodes, owner) ?? nodes; } @override List filterProperties(List nodes, DiagnosticsNode owner) { - return propertyFilter != null ? propertyFilter(nodes, owner) : nodes; + return propertyFilter?.call(nodes, owner) ?? nodes; } @override @@ -314,12 +316,12 @@ class TestDiagnosticsSerializationDelegate implements DiagnosticsSerializationDe final int subtreeDepth; @override - List truncateNodesList(List nodes, DiagnosticsNode owner) { - return nodeTruncator != null ? nodeTruncator(nodes, owner) : nodes; + List truncateNodesList(List nodes, DiagnosticsNode? owner) { + return nodeTruncator?.call(nodes, owner) ?? nodes; } @override - DiagnosticsSerializationDelegate copyWith({int subtreeDepth, bool includeProperties}) { + DiagnosticsSerializationDelegate copyWith({int? subtreeDepth, bool? includeProperties}) { return TestDiagnosticsSerializationDelegate( includeProperties: includeProperties ?? this.includeProperties, subtreeDepth: subtreeDepth ?? this.subtreeDepth, diff --git a/packages/flutter/test/foundation/diagnostics_test.dart b/packages/flutter/test/foundation/diagnostics_test.dart index 2bf26be022..6fd09b82e1 100644 --- a/packages/flutter/test/foundation/diagnostics_test.dart +++ b/packages/flutter/test/foundation/diagnostics_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:ui'; @@ -12,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; class TestTree extends Object with DiagnosticableTreeMixin { TestTree({ - this.name, + this.name = '', this.style, this.children = const [], this.properties = const [], @@ -21,7 +19,7 @@ class TestTree extends Object with DiagnosticableTreeMixin { final String name; final List children; final List properties; - final DiagnosticsTreeStyle style; + final DiagnosticsTreeStyle? style; @override List debugDescribeChildren() => [ @@ -36,8 +34,7 @@ class TestTree extends Object with DiagnosticableTreeMixin { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); if (style != null) - properties.defaultDiagnosticsTreeStyle = style; - + properties.defaultDiagnosticsTreeStyle = style!; this.properties.forEach(properties.add); } } @@ -65,7 +62,7 @@ void validateNodeJsonSerializationHelper(Map json, DiagnosticsNo expect(json['level'] ?? describeEnum(DiagnosticLevel.info), equals(describeEnum(node.level))); expect(json['showName'] ?? true, equals(node.showName)); expect(json['emptyBodyDescription'], equals(node.emptyBodyDescription)); - expect(json['style'] ?? describeEnum(DiagnosticsTreeStyle.sparse), equals(describeEnum(node.style))); + expect(json['style'] ?? describeEnum(DiagnosticsTreeStyle.sparse), equals(describeEnum(node.style!))); expect(json['type'], equals(node.runtimeType.toString())); expect(json['hasChildren'] ?? false, equals(node.getChildren().isNotEmpty)); } @@ -122,13 +119,13 @@ void validateObjectFlagPropertyJsonSerialization(ObjectFlagProperty prop validatePropertyJsonSerializationHelper(json, property); } -void validateIterableFlagsPropertyJsonSerialization(FlagsSummary property) { +void validateIterableFlagsPropertyJsonSerialization(FlagsSummary property) { final Map json = simulateJsonSerialization(property); if (property.value.isNotEmpty) { expect(json['values'], equals( property.value.entries - .where((MapEntry entry) => entry.value != null) - .map((MapEntry entry) => entry.key).toList(), + .where((MapEntry entry) => entry.value != null) + .map((MapEntry entry) => entry.key).toList(), )); } else { expect(json.containsKey('values'), isFalse); @@ -141,7 +138,7 @@ void validateIterablePropertyJsonSerialization(IterableProperty property final Map json = simulateJsonSerialization(property); if (property.value != null) { final List valuesJson = json['values'] as List; - final List expectedValues = property.value.map((Object value) => value.toString()).toList(); + final List expectedValues = property.value!.map((Object value) => value.toString()).toList(); expect(listEquals(valuesJson, expectedValues), isTrue); } else { expect(json.containsKey('values'), isFalse); @@ -194,8 +191,8 @@ void main() { test('TreeDiagnosticsMixin control test', () async { void goldenStyleTest( String description, { - DiagnosticsTreeStyle style, - DiagnosticsTreeStyle lastChildStyle, + DiagnosticsTreeStyle? style, + DiagnosticsTreeStyle? lastChildStyle, String golden = '', }) { final TestTree tree = TestTree(children: [ @@ -367,11 +364,11 @@ void main() { test('TreeDiagnosticsMixin tree with properties test', () async { void goldenStyleTest( String description, { - String name, - DiagnosticsTreeStyle style, - DiagnosticsTreeStyle lastChildStyle, + String? name, + DiagnosticsTreeStyle? style, + DiagnosticsTreeStyle? lastChildStyle, DiagnosticsTreeStyle propertyStyle = DiagnosticsTreeStyle.singleLine, - @required String golden, + required String golden, }) { final TestTree tree = TestTree( properties: [ @@ -1696,7 +1693,7 @@ void main() { // Partially empty property { final Function onClick = () { }; - final Map value = { + final Map value = { 'move': null, 'click': onClick, }; @@ -1711,7 +1708,7 @@ void main() { // Empty property (without ifEmpty) { - final Map value = { + final Map value = { 'enter': null, }; final FlagsSummary flags = FlagsSummary( @@ -1724,7 +1721,7 @@ void main() { // Empty property (without ifEmpty) { - final Map value = { + final Map value = { 'enter': null, }; final FlagsSummary flags = FlagsSummary( @@ -1922,14 +1919,14 @@ void main() { expect(messageProperty.name, equals('diagnostics')); expect(messageProperty.value, isNull); expect(messageProperty.showName, isTrue); - validatePropertyJsonSerialization(messageProperty as MessageProperty); + validatePropertyJsonSerialization(messageProperty as DiagnosticsProperty); }); test('error message style wrap test', () { // This tests wrapping of properties with styles typical for error messages. DiagnosticsNode createTreeWithWrappingNodes({ - DiagnosticsTreeStyle rootStyle, - DiagnosticsTreeStyle propertyStyle, + DiagnosticsTreeStyle? rootStyle, + required DiagnosticsTreeStyle propertyStyle, }) { return TestTree( name: 'Test tree', diff --git a/packages/flutter/test/foundation/double_precision_test.dart b/packages/flutter/test/foundation/double_precision_test.dart index 574770f6d0..24f348a1a0 100644 --- a/packages/flutter/test/foundation/double_precision_test.dart +++ b/packages/flutter/test/foundation/double_precision_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 '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/foundation/error_reporting_test.dart b/packages/flutter/test/foundation/error_reporting_test.dart index abed8917a6..62fe867c32 100644 --- a/packages/flutter/test/foundation/error_reporting_test.dart +++ b/packages/flutter/test/foundation/error_reporting_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 - @TestOn('!chrome') // web has different stack traces import 'package:flutter/foundation.dart'; @@ -41,13 +39,13 @@ Future getSampleStack() async { } Future main() async { - final List console = []; + final List console = []; final StackTrace sampleStack = await getSampleStack(); setUp(() async { expect(debugPrint, equals(debugPrintThrottled)); - debugPrint = (String message, { int wrapWidth }) { + debugPrint = (String? message, { int? wrapWidth }) { console.add(message); }; }); @@ -160,7 +158,7 @@ Future main() async { test('Error reporting - NoSuchMethodError', () async { expect(console, isEmpty); - final dynamic exception = NoSuchMethodError.withInvocation(5, + final Object exception = NoSuchMethodError.withInvocation(5, Invocation.method(#foo, [2, 4])); FlutterError.dumpErrorToConsole(FlutterErrorDetails( diff --git a/packages/flutter/test/foundation/isolates_test.dart b/packages/flutter/test/foundation/isolates_test.dart index 17a46bc8a4..bbd339d95b 100644 --- a/packages/flutter/test/foundation/isolates_test.dart +++ b/packages/flutter/test/foundation/isolates_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 - @TestOn('!chrome') // isolates not supported on the web. import 'package:flutter/foundation.dart'; diff --git a/packages/flutter/test/foundation/licenses_test.dart b/packages/flutter/test/foundation/licenses_test.dart index d4623e9718..62262385b0 100644 --- a/packages/flutter/test/foundation/licenses_test.dart +++ b/packages/flutter/test/foundation/licenses_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 '../flutter_test_alternative.dart'; @@ -11,7 +9,7 @@ void main() { test('LicenseEntryWithLineBreaks - most cases', () { // There's some trailing spaces in this string. // To avoid IDEs stripping them, I've escaped them as \u0020. - final List paragraphs = const LicenseEntryWithLineBreaks(null, ''' + final List paragraphs = const LicenseEntryWithLineBreaks([], ''' A A A @@ -159,17 +157,17 @@ S }); test('LicenseEntryWithLineBreaks - leading and trailing whitespace', () { - expect(const LicenseEntryWithLineBreaks(null, ' \n\n ').paragraphs.toList(), isEmpty); - expect(const LicenseEntryWithLineBreaks(null, ' \r\n\r\n ').paragraphs.toList(), isEmpty); + expect(const LicenseEntryWithLineBreaks([], ' \n\n ').paragraphs.toList(), isEmpty); + expect(const LicenseEntryWithLineBreaks([], ' \r\n\r\n ').paragraphs.toList(), isEmpty); List paragraphs; - paragraphs = const LicenseEntryWithLineBreaks(null, ' \nA\n ').paragraphs.toList(); + paragraphs = const LicenseEntryWithLineBreaks([], ' \nA\n ').paragraphs.toList(); expect(paragraphs[0].text, 'A'); expect(paragraphs[0].indent, 0); expect(paragraphs, hasLength(1)); - paragraphs = const LicenseEntryWithLineBreaks(null, '\n\n\nA\n\n\n').paragraphs.toList(); + paragraphs = const LicenseEntryWithLineBreaks([], '\n\n\nA\n\n\n').paragraphs.toList(); expect(paragraphs[0].text, 'A'); expect(paragraphs[0].indent, 0); expect(paragraphs, hasLength(1)); @@ -178,12 +176,12 @@ S test('LicenseRegistry', () async { expect(await LicenseRegistry.licenses.toList(), isEmpty); LicenseRegistry.addLicense(() async* { - yield const LicenseEntryWithLineBreaks(null, 'A'); - yield const LicenseEntryWithLineBreaks(null, 'B'); + yield const LicenseEntryWithLineBreaks([], 'A'); + yield const LicenseEntryWithLineBreaks([], 'B'); }); LicenseRegistry.addLicense(() async* { - yield const LicenseEntryWithLineBreaks(null, 'C'); - yield const LicenseEntryWithLineBreaks(null, 'D'); + yield const LicenseEntryWithLineBreaks([], 'C'); + yield const LicenseEntryWithLineBreaks([], 'D'); }); expect(await LicenseRegistry.licenses.toList(), hasLength(4)); final List licenses = await LicenseRegistry.licenses.toList(); diff --git a/packages/flutter/test/foundation/observer_list_test.dart b/packages/flutter/test/foundation/observer_list_test.dart index a67a8de3bf..840214b535 100644 --- a/packages/flutter/test/foundation/observer_list_test.dart +++ b/packages/flutter/test/foundation/observer_list_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_test/flutter_test.dart'; diff --git a/packages/flutter/test/foundation/platform_helper.dart b/packages/flutter/test/foundation/platform_helper.dart index 03ff5758e0..a30e882ea4 100644 --- a/packages/flutter/test/foundation/platform_helper.dart +++ b/packages/flutter/test/foundation/platform_helper.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:io' show Platform; /// Returns [Platform.pathSeparator], suitably escaped so as to be usable in a diff --git a/packages/flutter/test/foundation/print_test.dart b/packages/flutter/test/foundation/print_test.dart index e20e8edce2..0c1b679cbe 100644 --- a/packages/flutter/test/foundation/print_test.dart +++ b/packages/flutter/test/foundation/print_test.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. -// @dart = 2.10 import 'package:flutter/foundation.dart'; import 'package:fake_async/fake_async.dart'; import '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/foundation/reassemble_test.dart b/packages/flutter/test/foundation/reassemble_test.dart index 1472350166..230bc7f748 100644 --- a/packages/flutter/test/foundation/reassemble_test.dart +++ b/packages/flutter/test/foundation/reassemble_test.dart @@ -2,14 +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 - @TestOn('!chrome') import 'package:flutter/foundation.dart'; import '../flutter_test_alternative.dart'; class TestFoundationFlutterBinding extends BindingBase { - bool wasLocked; + bool? wasLocked; @override Future performReassemble() async { @@ -21,8 +19,6 @@ class TestFoundationFlutterBinding extends BindingBase { TestFoundationFlutterBinding binding = TestFoundationFlutterBinding(); void main() { - binding ??= TestFoundationFlutterBinding(); - test('Pointer events are locked during reassemble', () async { await binding.reassembleApplication(); expect(binding.wasLocked, isTrue); diff --git a/packages/flutter/test/foundation/serialization_test.dart b/packages/flutter/test/foundation/serialization_test.dart index 053b3b475b..3d1ed463e9 100644 --- a/packages/flutter/test/foundation/serialization_test.dart +++ b/packages/flutter/test/foundation/serialization_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 - @TestOn('!chrome') // web does not support certain 64bit behavior import 'dart:typed_data'; diff --git a/packages/flutter/test/foundation/service_extensions_test.dart b/packages/flutter/test/foundation/service_extensions_test.dart index 8d091af49f..c6eb754104 100644 --- a/packages/flutter/test/foundation/service_extensions_test.dart +++ b/packages/flutter/test/foundation/service_extensions_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:convert'; import 'dart:typed_data'; @@ -31,9 +29,10 @@ class TestServiceExtensionsBinding extends BindingBase final Map>> eventsDispatched = >>{}; @override + @protected void registerServiceExtension({ - @required String name, - @required ServiceExtensionCallback callback, + required String name, + required ServiceExtensionCallback callback, }) { expect(extensions.containsKey(name), isFalse); extensions[name] = callback; @@ -55,7 +54,7 @@ class TestServiceExtensionsBinding extends BindingBase Future> testExtension(String name, Map arguments) { expect(extensions.containsKey(name), isTrue); - return extensions[name](arguments); + return extensions[name]!(arguments); } int reassembled = 0; @@ -75,13 +74,10 @@ class TestServiceExtensionsBinding extends BindingBase } Future doFrame() async { frameScheduled = false; - if (ui.window.onBeginFrame != null) - ui.window.onBeginFrame(Duration.zero); + ui.window.onBeginFrame?.call(Duration.zero); await flushMicrotasks(); - if (ui.window.onDrawFrame != null) - ui.window.onDrawFrame(); - if (ui.window.onReportTimings != null) - ui.window.onReportTimings([]); + ui.window.onDrawFrame?.call(); + ui.window.onReportTimings?.call([]); } @override @@ -102,7 +98,7 @@ class TestServiceExtensionsBinding extends BindingBase } } -TestServiceExtensionsBinding binding; +late TestServiceExtensionsBinding binding; Future> hasReassemble(Future> pendingResult) async { bool completed = false; @@ -120,7 +116,7 @@ Future> hasReassemble(Future> pendingR } void main() { - final List console = []; + final List console = []; setUpAll(() async { binding = TestServiceExtensionsBinding()..scheduleFrame(); @@ -150,7 +146,7 @@ void main() { expect(binding.frameScheduled, isFalse); expect(debugPrint, equals(debugPrintThrottled)); - debugPrint = (String message, { int wrapWidth }) { + debugPrint = (String? message, { int? wrapWidth }) { console.add(message); }; }); @@ -208,7 +204,7 @@ void main() { bool lastValue = false; Future _updateAndCheck(bool newValue) async { - Map result; + Map? result; binding.testExtension( 'debugCheckElevationsEnabled', {'enabled': '$newValue'}, @@ -458,8 +454,8 @@ void main() { bool completed; completed = false; - ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler('flutter/assets', (ByteData message) async { - expect(utf8.decode(message.buffer.asUint8List()), 'test'); + ServicesBinding.instance!.defaultBinaryMessenger.setMockMessageHandler('flutter/assets', (ByteData? message) async { + expect(utf8.decode(message!.buffer.asUint8List()), 'test'); completed = true; return ByteData(5); // 0x0000000000 }); @@ -472,8 +468,7 @@ void main() { expect(completed, isTrue); completed = false; data = await rootBundle.loadStructuredData('test', (String value) async { - expect(true, isFalse); - return null; + throw Error(); }); expect(data, isTrue); expect(completed, isFalse); @@ -486,7 +481,7 @@ void main() { }); expect(data, isFalse); expect(completed, isTrue); - ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler('flutter/assets', null); + ServicesBinding.instance!.defaultBinaryMessenger.setMockMessageHandler('flutter/assets', null); }); test('Service extensions - exit', () async { diff --git a/packages/flutter/test/foundation/stack_frame_test.dart b/packages/flutter/test/foundation/stack_frame_test.dart index 6cfb62f12f..d5fb66b2cd 100644 --- a/packages/flutter/test/foundation/stack_frame_test.dart +++ b/packages/flutter/test/foundation/stack_frame_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 '../flutter_test_alternative.dart'; diff --git a/packages/flutter/test/foundation/stack_trace_test.dart b/packages/flutter/test/foundation/stack_trace_test.dart index 1234e73d35..b565755e9e 100644 --- a/packages/flutter/test/foundation/stack_trace_test.dart +++ b/packages/flutter/test/foundation/stack_trace_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 - @TestOn('!chrome') // web has different stack traces import 'package:flutter/foundation.dart'; diff --git a/packages/flutter/test/foundation/synchronous_future_test.dart b/packages/flutter/test/foundation/synchronous_future_test.dart index 7539d53dd2..40cfe1bf16 100644 --- a/packages/flutter/test/foundation/synchronous_future_test.dart +++ b/packages/flutter/test/foundation/synchronous_future_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 '../flutter_test_alternative.dart'; @@ -11,7 +9,7 @@ void main() { test('SynchronousFuture control test', () async { final Future future = SynchronousFuture(42); - int result; + int? result; future.then((int value) { result = value; }); expect(result, equals(42)); @@ -39,16 +37,16 @@ void main() { expect(await completeResult, equals(42)); - Object exception; + Object? exception; try { await future.whenComplete(() { - throw null; + throw ArgumentError(); }); // Unreached. expect(false, isTrue); } catch (e) { exception = e; } - expect(exception, isNullThrownError); + expect(exception, isArgumentError); }); }