diff --git a/packages/flutter/test/widgets/restoration_mixin_test.dart b/packages/flutter/test/widgets/restoration_mixin_test.dart index fc360df336..8e0ff5d783 100644 --- a/packages/flutter/test/widgets/restoration_mixin_test.dart +++ b/packages/flutter/test/widgets/restoration_mixin_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/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -29,12 +27,12 @@ void main() { manager.doSerialization(); final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); - expect(state.bucket.restorationId, id); + expect(state.bucket?.restorationId, id); expect(rawData[childrenMapKey].containsKey(id), isTrue); expect(state.property.value, 10); expect(rawData[childrenMapKey][id][valuesMapKey]['foo'], 10); expect(state.property.log, ['createDefaultValue', 'initWithValue', 'toPrimitives']); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); expect(state.restoreStateLog.single, isNull); }); @@ -53,10 +51,10 @@ void main() { manager.doSerialization(); final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); - expect(state.bucket.restorationId, 'child1'); + expect(state.bucket!.restorationId, 'child1'); expect(state.property.value, 22); expect(state.property.log, ['fromPrimitives', 'initWithValue']); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); expect(state.restoreStateLog.single, isNull); }); @@ -76,9 +74,9 @@ void main() { // Claimed existing bucket with data. final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); - expect(state.bucket.restorationId, 'child1'); - expect(state.bucket.read('foo'), 22); - final RestorationBucket bucket = state.bucket; + expect(state.bucket!.restorationId, 'child1'); + expect(state.bucket!.read('foo'), 22); + final RestorationBucket bucket = state.bucket!; state.property.log.clear(); state.restoreStateLog.clear(); @@ -94,12 +92,12 @@ void main() { ); manager.doSerialization(); - expect(state.bucket.restorationId, 'something else'); - expect(state.bucket.read('foo'), 22); + expect(state.bucket!.restorationId, 'something else'); + expect(state.bucket!.read('foo'), 22); expect(state.bucket, same(bucket)); expect(state.property.log, isEmpty); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); }); testWidgets('renames existing bucket when didUpdateRestorationId is called', (WidgetTester tester) async { @@ -118,9 +116,9 @@ void main() { // Claimed existing bucket with data. final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); - expect(state.bucket.restorationId, 'child1'); - expect(state.bucket.read('foo'), 22); - final RestorationBucket bucket = state.bucket; + expect(state.bucket!.restorationId, 'child1'); + expect(state.bucket!.read('foo'), 22); + final RestorationBucket bucket = state.bucket!; state.property.log.clear(); state.restoreStateLog.clear(); @@ -129,12 +127,12 @@ void main() { state.injectId('newnewnew'); manager.doSerialization(); - expect(state.bucket.restorationId, 'newnewnew'); - expect(state.bucket.read('foo'), 22); + expect(state.bucket!.restorationId, 'newnewnew'); + expect(state.bucket!.read('foo'), 22); expect(state.bucket, same(bucket)); expect(state.property.log, isEmpty); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); }); testWidgets('Disposing widget removes its data', (WidgetTester tester) async { @@ -185,9 +183,9 @@ void main() { expect(state.property.log, ['createDefaultValue', 'initWithValue']); state.property.log.clear(); expect(state.restoreStateLog.single, isNull); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); state.restoreStateLog.clear(); - state.toogleBucketLog.clear(); + state.toggleBucketLog.clear(); // Change id to non-null. await tester.pumpWidget( @@ -200,17 +198,17 @@ void main() { ); manager.doSerialization(); expect(state.bucket, isNotNull); - expect(state.bucket.restorationId, 'child1'); + expect(state.bucket!.restorationId, 'child1'); expect(state.property.value, 10); expect(rawData[childrenMapKey]['child1'][valuesMapKey]['foo'], 10); expect(state.property.log, ['toPrimitives']); state.property.log.clear(); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog.single, isNull); + expect(state.toggleBucketLog.single, isNull); state.restoreStateLog.clear(); - state.toogleBucketLog.clear(); + state.toggleBucketLog.clear(); - final RestorationBucket bucket = state.bucket; + final RestorationBucket bucket = state.bucket!; // Change id back to null. await tester.pumpWidget( @@ -226,7 +224,7 @@ void main() { expect(rawData[childrenMapKey].containsKey('child1'), isFalse); expect(state.property.log, isEmpty); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog.single, same(bucket)); + expect(state.toggleBucketLog.single, same(bucket)); }); testWidgets('move in and out of scope', (WidgetTester tester) async { @@ -248,9 +246,9 @@ void main() { expect(state.property.log, ['createDefaultValue', 'initWithValue']); state.property.log.clear(); expect(state.restoreStateLog.single, isNull); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); state.restoreStateLog.clear(); - state.toogleBucketLog.clear(); + state.toggleBucketLog.clear(); // Move it under a valid scope. await tester.pumpWidget( @@ -264,17 +262,17 @@ void main() { ); manager.doSerialization(); expect(state.bucket, isNotNull); - expect(state.bucket.restorationId, 'child1'); + expect(state.bucket!.restorationId, 'child1'); expect(state.property.value, 10); expect(rawData[childrenMapKey]['child1'][valuesMapKey]['foo'], 10); expect(state.property.log, ['toPrimitives']); state.property.log.clear(); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog.single, isNull); + expect(state.toggleBucketLog.single, isNull); state.restoreStateLog.clear(); - state.toogleBucketLog.clear(); + state.toggleBucketLog.clear(); - final RestorationBucket bucket = state.bucket; + final RestorationBucket bucket = state.bucket!; // Move out of scope again. await tester.pumpWidget( @@ -288,7 +286,7 @@ void main() { expect(rawData[childrenMapKey].containsKey('child1'), isFalse); expect(state.property.log, isEmpty); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog.single, same(bucket)); + expect(state.toggleBucketLog.single, same(bucket)); }); testWidgets('moving scope moves its data', (WidgetTester tester) async { @@ -316,13 +314,13 @@ void main() { ); manager.doSerialization(); final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); - expect(state.bucket.restorationId, 'moving-child'); + expect(state.bucket!.restorationId, 'moving-child'); expect(rawData[childrenMapKey]['fixed'][childrenMapKey].containsKey('moving-child'), isTrue); - final RestorationBucket bucket = state.bucket; + final RestorationBucket bucket = state.bucket!; state.property.log.clear(); state.restoreStateLog.clear(); - state.bucket.write('value', 11); + state.bucket!.write('value', 11); manager.doSerialization(); // Move widget. @@ -345,11 +343,11 @@ void main() { ), ); manager.doSerialization(); - expect(state.bucket.restorationId, 'moving-child'); + expect(state.bucket!.restorationId, 'moving-child'); expect(state.bucket, same(bucket)); - expect(state.bucket.read('value'), 11); + expect(state.bucket!.read('value'), 11); expect(state.property.log, isEmpty); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); expect(state.restoreStateLog, isEmpty); expect(rawData[childrenMapKey]['fixed'], isEmpty); @@ -371,7 +369,7 @@ void main() { expect(state.property.value, 10); // default expect(state.property.log, ['createDefaultValue', 'initWithValue', 'toPrimitives']); expect(state.restoreStateLog.single, isNull); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); _clearLogs(state); state.setProperties(() { @@ -381,7 +379,7 @@ void main() { expect(state.property.value, 20); expect(state.property.log, ['toPrimitives']); expect(state.restoreStateLog, isEmpty); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); _clearLogs(state); final _TestRestorableWidgetState oldState = state; @@ -392,7 +390,7 @@ void main() { expect(state.property.value, 20); expect(state.property.log, ['fromPrimitives', 'initWithValue']); expect(state.restoreStateLog.single, isNull); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); }); testWidgets('restore while running', (WidgetTester tester) async { @@ -423,7 +421,7 @@ void main() { _clearLogs(state); final _TestRestorableWidgetState oldState = state; - final RestorationBucket oldBucket = oldState.bucket; + final RestorationBucket oldBucket = oldState.bucket!; await tester.restoreFrom(data); state = tester.state(find.byType(_TestRestorableWidget)); @@ -431,7 +429,7 @@ void main() { expect(state.property.value, 20); expect(state.property.log, ['fromPrimitives', 'initWithValue']); expect(state.restoreStateLog.single, oldBucket); - expect(state.toogleBucketLog, isEmpty); + expect(state.toggleBucketLog, isEmpty); }); testWidgets('can register additional property outside of restoreState', (WidgetTester tester) async { @@ -446,28 +444,28 @@ void main() { final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); state.registerAdditionalProperty(); - expect(state.additionalProperty.value, 11); - expect(state.additionalProperty.log, ['createDefaultValue', 'initWithValue', 'toPrimitives']); + expect(state.additionalProperty!.value, 11); + expect(state.additionalProperty!.log, ['createDefaultValue', 'initWithValue', 'toPrimitives']); state.setProperties(() { - state.additionalProperty.value = 33; + state.additionalProperty!.value = 33; }); await tester.pump(); - expect(state.additionalProperty.value, 33); + expect(state.additionalProperty!.value, 33); final TestRestorationData data = await tester.getRestorationData(); state.setProperties(() { - state.additionalProperty.value = 44; + state.additionalProperty!.value = 44; }); await tester.pump(); - expect(state.additionalProperty.value, 44); + expect(state.additionalProperty!.value, 44); _clearLogs(state); await tester.restoreFrom(data); expect(state, same(tester.state(find.byType(_TestRestorableWidget)))); - expect(state.additionalProperty.value, 33); + expect(state.additionalProperty!.value, 33); expect(state.property.log, ['fromPrimitives', 'initWithValue']); }); @@ -517,7 +515,7 @@ void main() { }); await tester.pump(); expect(state.property.value, 30); - expect(state.bucket.read('foo'), 30); + expect(state.bucket!.read('foo'), 30); _clearLogs(state); state.setProperties(() { @@ -525,14 +523,14 @@ void main() { }); await tester.pump(); expect(state.property.value, 30); - expect(state.bucket.contains('foo'), isFalse); + expect(state.bucket!.contains('foo'), isFalse); expect(state.property.log, isEmpty); state.setProperties(() { state.property.value = 40; }); await tester.pump(); - expect(state.bucket.contains('foo'), isFalse); + expect(state.bucket!.contains('foo'), isFalse); expect(state.property.log, isEmpty); await tester.restartAndRestore(); @@ -557,20 +555,20 @@ void main() { state.property.enabled = false; }); await tester.pump(); - expect(state.bucket.contains('foo'), isFalse); + expect(state.bucket!.contains('foo'), isFalse); state.setProperties(() { state.property.value = 40; }); await tester.pump(); expect(state.property.value, 40); - expect(state.bucket.contains('foo'), isFalse); + expect(state.bucket!.contains('foo'), isFalse); expect(state.property.log, isEmpty); state.setProperties(() { state.property.enabled = true; }); await tester.pump(); - expect(state.bucket.read('foo'), 40); + expect(state.bucket!.read('foo'), 40); expect(state.property.log, ['toPrimitives']); await tester.restartAndRestore(); @@ -591,18 +589,18 @@ void main() { final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); state.registerAdditionalProperty(); await tester.pump(); - expect(state.additionalProperty.value, 11); - expect(state.bucket.read('additional'), 11); + expect(state.additionalProperty!.value, 11); + expect(state.bucket!.read('additional'), 11); state.unregisterAdditionalProperty(); await tester.pump(); - expect(state.bucket.contains('additional'), isFalse); - expect(() => state.additionalProperty.value, throwsAssertionError); // No longer registered. + expect(state.bucket!.contains('additional'), isFalse); + expect(() => state.additionalProperty!.value, throwsAssertionError); // No longer registered. // Can register the same property again. state.registerAdditionalProperty(); await tester.pump(); - expect(state.additionalProperty.value, 11); - expect(state.bucket.read('additional'), 11); + expect(state.additionalProperty!.value, 11); + expect(state.bucket!.read('additional'), 11); }); testWidgets('Disposing a property unregisters it, but keeps data', (WidgetTester tester) async { @@ -617,20 +615,20 @@ void main() { final _TestRestorableWidgetState state = tester.state(find.byType(_TestRestorableWidget)); state.registerAdditionalProperty(); await tester.pump(); - expect(state.additionalProperty.value, 11); - expect(state.bucket.read('additional'), 11); + expect(state.additionalProperty!.value, 11); + expect(state.bucket!.read('additional'), 11); - state.additionalProperty.dispose(); + state.additionalProperty!.dispose(); await tester.pump(); - expect(state.bucket.read('additional'), 11); + expect(state.bucket!.read('additional'), 11); // Can register property under same id again. state.additionalProperty = _TestRestorableProperty(22); state.registerAdditionalProperty(); await tester.pump(); - expect(state.additionalProperty.value, 11); // Old value restored. - expect(state.bucket.read('additional'), 11); + expect(state.additionalProperty!.value, 11); // Old value restored. + expect(state.bucket!.read('additional'), 11); }); test('RestorableProperty throws after disposed', () { @@ -642,16 +640,16 @@ void main() { void _clearLogs(_TestRestorableWidgetState state) { state.property.log.clear(); - state.additionalProperty?.log?.clear(); + state.additionalProperty?.log.clear(); state.restoreStateLog.clear(); - state.toogleBucketLog.clear(); + state.toggleBucketLog.clear(); } class _TestRestorableWidget extends StatefulWidget { - const _TestRestorableWidget({Key key, this.restorationId}) : super(key: key); + const _TestRestorableWidget({Key? key, this.restorationId}) : super(key: key); - final String restorationId; + final String? restorationId; @override State<_TestRestorableWidget> createState() => _TestRestorableWidgetState(); @@ -659,25 +657,24 @@ class _TestRestorableWidget extends StatefulWidget { class _TestRestorableWidgetState extends State<_TestRestorableWidget> with RestorationMixin { final _TestRestorableProperty property = _TestRestorableProperty(10); - _TestRestorableProperty additionalProperty; + _TestRestorableProperty? additionalProperty; bool _rerigisterAdditionalProperty = false; - final List restoreStateLog = []; - final List toogleBucketLog = []; - + final List restoreStateLog = []; + final List toggleBucketLog = []; @override - void restoreState(RestorationBucket oldBucket, bool initialRestore) { + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { restoreStateLog.add(oldBucket); registerForRestoration(property, 'foo'); if (_rerigisterAdditionalProperty && additionalProperty != null) { - registerForRestoration(additionalProperty, 'additional'); + registerForRestoration(additionalProperty!, 'additional'); } } @override - void didToggleBucket(RestorationBucket oldBucket) { - toogleBucketLog.add(oldBucket); + void didToggleBucket(RestorationBucket? oldBucket) { + toggleBucketLog.add(oldBucket); super.didToggleBucket(oldBucket); } @@ -695,7 +692,7 @@ class _TestRestorableWidgetState extends State<_TestRestorableWidget> with Resto void setProperties(VoidCallback fn) => setState(fn); - String _injectedId; + String? _injectedId; void injectId(String id) { _injectedId = id; didUpdateRestorationId(); @@ -703,12 +700,12 @@ class _TestRestorableWidgetState extends State<_TestRestorableWidget> with Resto void registerAdditionalProperty({bool reregister = true}) { additionalProperty ??= _TestRestorableProperty(11); - registerForRestoration(additionalProperty, 'additional'); + registerForRestoration(additionalProperty!, 'additional'); _rerigisterAdditionalProperty = reregister; } void unregisterAdditionalProperty() { - unregisterFromRestoration(additionalProperty); + unregisterFromRestoration(additionalProperty!); } void registerPropertyUnderSameId() { @@ -716,7 +713,7 @@ class _TestRestorableWidgetState extends State<_TestRestorableWidget> with Resto } @override - String get restorationId => _injectedId ?? widget.restorationId; + String? get restorationId => _injectedId ?? widget.restorationId; } Map _createRawDataSet() { diff --git a/packages/flutter/test/widgets/restoration_scope_test.dart b/packages/flutter/test/widgets/restoration_scope_test.dart index 259023d2e0..deaeed5fb4 100644 --- a/packages/flutter/test/widgets/restoration_scope_test.dart +++ b/packages/flutter/test/widgets/restoration_scope_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/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -74,7 +72,7 @@ void main() { manager.doSerialization(); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, id); + expect(state.bucket!.restorationId, id); expect(rawData[childrenMapKey].containsKey(id), isTrue); }); @@ -94,8 +92,8 @@ void main() { manager.doSerialization(); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'child1'); - expect(state.bucket.read('foo'), 22); + expect(state.bucket!.restorationId, 'child1'); + expect(state.bucket!.read('foo'), 22); }); testWidgets('renames existing bucket when new ID is provided', (WidgetTester tester) async { @@ -115,9 +113,9 @@ void main() { // Claimed existing bucket with data. final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'child1'); - expect(state.bucket.read('foo'), 22); - final RestorationBucket bucket = state.bucket; + expect(state.bucket!.restorationId, 'child1'); + expect(state.bucket!.read('foo'), 22); + final RestorationBucket bucket = state.bucket!; // Rename the existing bucket. await tester.pumpWidget( @@ -131,8 +129,8 @@ void main() { ); manager.doSerialization(); - expect(state.bucket.restorationId, 'something else'); - expect(state.bucket.read('foo'), 22); + expect(state.bucket!.restorationId, 'something else'); + expect(state.bucket!.read('foo'), 22); expect(state.bucket, same(bucket)); }); @@ -193,7 +191,7 @@ void main() { ); manager.doSerialization(); expect(state.bucket, isNotNull); - expect(state.bucket.restorationId, 'foo'); + expect(state.bucket!.restorationId, 'foo'); // Change id back to null. await tester.pumpWidget( @@ -237,7 +235,7 @@ void main() { ); manager.doSerialization(); expect(state.bucket, isNotNull); - expect(state.bucket.restorationId, 'foo'); + expect(state.bucket!.restorationId, 'foo'); // Move out of scope again. await tester.pumpWidget( @@ -288,11 +286,11 @@ void main() { ); manager.doSerialization(); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'moving-child'); + expect(state.bucket!.restorationId, 'moving-child'); expect(rawData[childrenMapKey]['fixed'][childrenMapKey].containsKey('moving-child'), isTrue); - final RestorationBucket bucket = state.bucket; + final RestorationBucket bucket = state.bucket!; - state.bucket.write('value', 11); + state.bucket!.write('value', 11); manager.doSerialization(); // Move scope. @@ -316,9 +314,9 @@ void main() { ), ); manager.doSerialization(); - expect(state.bucket.restorationId, 'moving-child'); + expect(state.bucket!.restorationId, 'moving-child'); expect(state.bucket, same(bucket)); - expect(state.bucket.read('value'), 11); + expect(state.bucket!.read('value'), 11); expect(rawData[childrenMapKey]['fixed'], isEmpty); expect(rawData[childrenMapKey].containsKey('moving-child'), isTrue); diff --git a/packages/flutter/test/widgets/restoration_scopes_moving_test.dart b/packages/flutter/test/widgets/restoration_scopes_moving_test.dart index 5053f25363..3c07df3870 100644 --- a/packages/flutter/test/widgets/restoration_scopes_moving_test.dart +++ b/packages/flutter/test/widgets/restoration_scopes_moving_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_test/flutter_test.dart'; @@ -123,13 +121,13 @@ class TestWidgetWithCounterChildState extends State int toggleCount = 0; @override - void didToggleBucket(RestorationBucket oldBucket) { + void didToggleBucket(RestorationBucket? oldBucket) { super.didToggleBucket(oldBucket); toggleCount++; } @override - void restoreState(RestorationBucket oldBucket, bool initialRestore) { + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { registerForRestoration(childRestorationEnabled, 'childRestorationEnabled'); } @@ -163,7 +161,7 @@ class TestWidgetWithCounterChildState extends State class Counter extends StatefulWidget { const Counter({this.restorationId}); - final String restorationId; + final String? restorationId; @override State createState() => CounterState(); @@ -173,10 +171,10 @@ class CounterState extends State with RestorationMixin { final RestorableInt count = RestorableInt(0); @override - String get restorationId => widget.restorationId; + String? get restorationId => widget.restorationId; @override - void restoreState(RestorationBucket oldBucket, bool initialRestore) { + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { registerForRestoration(count, 'counter'); } @@ -202,20 +200,20 @@ class CounterState extends State with RestorationMixin { } class TestWidget extends StatefulWidget { - const TestWidget({@required this.restorationId}); + const TestWidget({required this.restorationId}); - final String restorationId; + final String? restorationId; @override State createState() => TestWidgetState(); } class TestWidgetState extends State with RestorationMixin { - List buckets = []; + List buckets = []; List flags = []; @override - void restoreState(RestorationBucket oldBucket, bool initialRestore) { + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { buckets.add(oldBucket); flags.add(initialRestore); } @@ -223,13 +221,13 @@ class TestWidgetState extends State with RestorationMixin { int toggleCount = 0; @override - void didToggleBucket(RestorationBucket oldBucket) { + void didToggleBucket(RestorationBucket? oldBucket) { super.didToggleBucket(oldBucket); toggleCount++; } @override - String get restorationId => widget.restorationId; + String? get restorationId => widget.restorationId; @override Widget build(BuildContext context) { diff --git a/packages/flutter/test/widgets/root_restoration_scope_test.dart b/packages/flutter/test/widgets/root_restoration_scope_test.dart index 32dc1a1eda..85d57ce314 100644 --- a/packages/flutter/test/widgets/root_restoration_scope_test.dart +++ b/packages/flutter/test/widgets/root_restoration_scope_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 'package:flutter/foundation.dart'; @@ -44,7 +42,7 @@ void main() { expect(binding.restorationManager.rootBucketAccessed, 0); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); expect(rawData[childrenMapKey].containsKey('root-child'), isTrue); expect(find.text('Hello'), findsOneWidget); @@ -82,7 +80,7 @@ void main() { expect(binding.firstFrameIsDeferred, isFalse); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); expect(rawData[childrenMapKey].containsKey('root-child'), isTrue); }); @@ -108,7 +106,7 @@ void main() { expect(binding.firstFrameIsDeferred, isFalse); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); expect(rawData[childrenMapKey].containsKey('root-child'), isTrue); }); @@ -158,7 +156,7 @@ void main() { expect(binding.restorationManager.rootBucketAccessed, 1); expect(find.text('Hello'), findsOneWidget); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); // Change ID back to null. await tester.pumpWidget( @@ -203,7 +201,7 @@ void main() { expect(binding.restorationManager.rootBucketAccessed, 0); expect(find.text('Hello'), findsOneWidget); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); expect(inScopeRawData[childrenMapKey].containsKey('root-child'), isTrue); // Move out of scope. @@ -232,7 +230,7 @@ void main() { expect(binding.restorationManager.rootBucketAccessed, 1); expect(find.text('Hello'), findsOneWidget); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); expect(outOfScopeRawData[childrenMapKey].containsKey('root-child'), isTrue); expect(inScopeRawData, isEmpty); @@ -255,7 +253,7 @@ void main() { expect(binding.restorationManager.rootBucketAccessed, 1); expect(find.text('Hello'), findsOneWidget); - expect(state.bucket.restorationId, 'root-child'); + expect(state.bucket!.restorationId, 'root-child'); expect(outOfScopeRawData, isEmpty); expect(inScopeRawData[childrenMapKey].containsKey('root-child'), isTrue); }); @@ -280,9 +278,9 @@ void main() { expect(binding.restorationManager.rootBucketAccessed, 1); expect(find.text('Hello'), findsOneWidget); final BucketSpyState state = tester.state(find.byType(BucketSpy)); - state.bucket.write('foo', 42); + state.bucket!.write('foo', 42); expect(firstRawData[childrenMapKey]['root-child'][valuesMapKey]['foo'], 42); - final RestorationBucket firstBucket = state.bucket; + final RestorationBucket firstBucket = state.bucket!; // Replace with new root. final Map secondRawData = { @@ -300,7 +298,7 @@ void main() { firstRoot.dispose(); expect(state.bucket, isNot(same(firstBucket))); - expect(state.bucket.read('foo'), 22); + expect(state.bucket!.read('foo'), 22); }); testWidgets('injects null when rootBucket is null', (WidgetTester tester) async { @@ -361,7 +359,7 @@ void main() { final BucketSpyState state = tester.state(find.byType(BucketSpy)); expect(state.bucket, isNotNull); - binding.restorationManager.rootBucket = SynchronousFuture(null); + binding.restorationManager.rootBucket = SynchronousFuture(null); await tester.pump(); root.dispose(); @@ -372,7 +370,7 @@ void main() { } class TestAutomatedTestWidgetsFlutterBinding extends AutomatedTestWidgetsFlutterBinding { - MockRestorationManager _restorationManager; + late MockRestorationManager _restorationManager; @override MockRestorationManager get restorationManager => _restorationManager; diff --git a/packages/flutter/test/widgets/rotated_box_test.dart b/packages/flutter/test/widgets/rotated_box_test.dart index 360e4f7ea7..c112804284 100644 --- a/packages/flutter/test/widgets/rotated_box_test.dart +++ b/packages/flutter/test/widgets/rotated_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_test/flutter_test.dart'; import 'package:flutter/material.dart'; diff --git a/packages/flutter/test/widgets/route_notification_messages_test.dart b/packages/flutter/test/widgets/route_notification_messages_test.dart index 8aaf3e6563..3542d527d4 100644 --- a/packages/flutter/test/widgets/route_notification_messages_test.dart +++ b/packages/flutter/test/widgets/route_notification_messages_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:ui'; @@ -14,7 +12,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class OnTapPage extends StatelessWidget { - const OnTapPage({Key key, this.id, this.onTap}) : super(key: key); + const OnTapPage({Key? key, required this.id, required this.onTap}) : super(key: key); final String id; final VoidCallback onTap; @@ -28,7 +26,7 @@ class OnTapPage extends StatelessWidget { behavior: HitTestBehavior.opaque, child: Container( child: Center( - child: Text(id, style: Theme.of(context).textTheme.headline3), + child: Text(id, style: Theme.of(context)!.textTheme.headline3), ), ), ), @@ -271,7 +269,7 @@ void main() { final SimpleRouterDelegate delegate = SimpleRouterDelegate( reportConfiguration: true, builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + return Text(information.location!); } ); @@ -323,24 +321,24 @@ class SimpleRouteInformationParser extends RouteInformationParser with ChangeNotifier { SimpleRouterDelegate({ - @required this.builder, + required this.builder, this.onPopRoute, this.reportConfiguration = false, }); RouteInformation get routeInformation => _routeInformation; - RouteInformation _routeInformation; + late RouteInformation _routeInformation; set routeInformation(RouteInformation newValue) { _routeInformation = newValue; notifyListeners(); } SimpleRouterDelegateBuilder builder; - SimpleRouterDelegatePopRoute onPopRoute; + SimpleRouterDelegatePopRoute? onPopRoute; final bool reportConfiguration; @override - RouteInformation get currentConfiguration { + RouteInformation? get currentConfiguration { if (reportConfiguration) return routeInformation; return null; @@ -355,7 +353,7 @@ class SimpleRouterDelegate extends RouterDelegate with ChangeN @override Future popRoute() { if (onPopRoute != null) - return onPopRoute(); + return onPopRoute!(); return SynchronousFuture(true); } @@ -364,7 +362,7 @@ class SimpleRouterDelegate extends RouterDelegate with ChangeN } class TestPage extends Page { - const TestPage({LocalKey key, String name}) : super(key: key, name: name); + const TestPage({LocalKey? key, String? name}) : super(key: key, name: name); @override Route createRoute(BuildContext context) { diff --git a/packages/flutter/test/widgets/router_test.dart b/packages/flutter/test/widgets/router_test.dart index 20343ddbd5..8f4685028d 100644 --- a/packages/flutter/test/widgets/router_test.dart +++ b/packages/flutter/test/widgets/router_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'; import 'package:flutter/material.dart'; @@ -20,8 +18,8 @@ void main() { routeInformationProvider: provider, routeInformationParser: SimpleRouteInformationParser(), routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); } ), ) @@ -43,10 +41,10 @@ void main() { ); final SimpleAsyncRouteInformationParser parser = SimpleAsyncRouteInformationParser(); final SimpleAsyncRouterDelegate delegate = SimpleAsyncRouterDelegate( - builder: (BuildContext context, RouteInformation information) { + builder: (BuildContext context, RouteInformation? information) { if (information == null) return const Text('waiting'); - return Text(information.location); + return Text(information.location!); } ); await tester.runAsync(() async { @@ -84,10 +82,10 @@ void main() { await tester.pumpWidget(buildBoilerPlate( Text('dummy', key: key) )); - final BuildContext textContext = key.currentContext; + final BuildContext textContext = key.currentContext!; // This should not throw error. - Router router = Router.of(textContext, nullOk: true); + Router? router = Router.of(textContext, nullOk: true); expect(router, isNull); // Test when the nullOk is not specified. @@ -113,8 +111,8 @@ void main() { routeInformationProvider: provider, routeInformationParser: SimpleRouteInformationParser(), routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); }, onPopRoute: () { provider.value = const RouteInformation( @@ -149,8 +147,8 @@ void main() { Router( routeInformationProvider: provider, routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); }, ), ); @@ -169,8 +167,8 @@ void main() { Router( routeInformationParser: SimpleRouteInformationParser(), routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); }, ), ); @@ -191,8 +189,8 @@ void main() { ); final BackButtonDispatcher dispatcher = RootBackButtonDispatcher(); final SimpleNavigatorRouterDelegate delegate = SimpleNavigatorRouterDelegate( - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); }, onPopPage: (Route route, void result) { provider.value = const RouteInformation( @@ -214,7 +212,7 @@ void main() { // Pushes a nameless route. showDialog( useRootNavigator: false, - context: delegate.navigatorKey.currentContext, + context: delegate.navigatorKey.currentContext!, builder: (BuildContext context) => const Text('dialog') ); await tester.pumpAndSettle(); @@ -249,15 +247,15 @@ void main() { routeInformationProvider: provider, routeInformationParser: SimpleRouteInformationParser(), routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { + builder: (BuildContext context, RouteInformation? information) { final BackButtonDispatcher innerDispatcher = ChildBackButtonDispatcher(outerDispatcher); innerDispatcher.takePriority(); // Creates the sub-router. return Router( backButtonDispatcher: innerDispatcher, routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation innerInformation) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? innerInformation) { + return Text(information!.location!); }, onPopRoute: () { provider.value = const RouteInformation( @@ -301,15 +299,15 @@ void main() { routeInformationProvider: provider, routeInformationParser: SimpleRouteInformationParser(), routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { + builder: (BuildContext context, RouteInformation? information) { // Creates the sub-router. return Column( children: [ - Text(information.location), + Text(information!.location!), Router( backButtonDispatcher: innerDispatcher1, routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation innerInformation) { + builder: (BuildContext context, RouteInformation? innerInformation) { return Container(); }, onPopRoute: () { @@ -323,7 +321,7 @@ void main() { Router( backButtonDispatcher: innerDispatcher2, routerDelegate: SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation innerInformation) { + builder: (BuildContext context, RouteInformation? innerInformation) { return Container(); }, onPopRoute: () { @@ -373,7 +371,7 @@ void main() { }); testWidgets('router does report URL change correctly', (WidgetTester tester) async { - RouteInformation reportedRouteInformation; + RouteInformation? reportedRouteInformation; final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider( onRouterReport: (RouteInformation information) { // Makes sure we only report once after manually cleaning up. @@ -383,8 +381,8 @@ void main() { ); final SimpleRouterDelegate delegate = SimpleRouterDelegate( reportConfiguration: true, - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); } ); delegate.onPopRoute = () { @@ -415,7 +413,7 @@ void main() { await tester.pump(); expect(find.text('initial'), findsNothing); expect(find.text('update'), findsOneWidget); - expect(reportedRouteInformation.location, 'update'); + expect(reportedRouteInformation!.location, 'update'); // The router should not report if only state changes. reportedRouteInformation = null; @@ -433,13 +431,13 @@ void main() { expect(result, isTrue); await tester.pump(); expect(find.text('popped'), findsOneWidget); - expect(reportedRouteInformation.location, 'popped'); + expect(reportedRouteInformation!.location, 'popped'); }); testWidgets('router can be forced to recognize or ignore navigating events', (WidgetTester tester) async { - RouteInformation reportedRouteInformation; + RouteInformation? reportedRouteInformation; bool isNavigating = false; - RouteInformation nextRouteInformation; + late RouteInformation nextRouteInformation; final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider( onRouterReport: (RouteInformation information) { // Makes sure we only report once after manually cleaning up. @@ -451,9 +449,9 @@ void main() { location: 'initial', ); final SimpleRouterDelegate delegate = SimpleRouterDelegate(reportConfiguration: true); - delegate.builder = (BuildContext context, RouteInformation information) { + delegate.builder = (BuildContext context, RouteInformation? information) { return ElevatedButton( - child: Text(information.location), + child: Text(information!.location!), onPressed: () { if (isNavigating) { Router.navigate(context, () { @@ -497,11 +495,11 @@ void main() { // report a route information because isNavigating = true. await tester.tap(find.byType(ElevatedButton)); await tester.pump(); - expect(reportedRouteInformation.location, 'update'); + expect(reportedRouteInformation!.location, 'update'); }); testWidgets('router does not report when route information is up to date with route information provider', (WidgetTester tester) async { - RouteInformation reportedRouteInformation; + RouteInformation? reportedRouteInformation; final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider( onRouterReport: (RouteInformation information) { reportedRouteInformation = information; @@ -511,8 +509,8 @@ void main() { location: 'initial', ); final SimpleRouterDelegate delegate = SimpleRouterDelegate(reportConfiguration: true); - delegate.builder = (BuildContext context, RouteInformation routeInformation) { - return Text(routeInformation.location); + delegate.builder = (BuildContext context, RouteInformation? routeInformation) { + return Text(routeInformation!.location!); }; await tester.pumpWidget(buildBoilerPlate( @@ -546,10 +544,10 @@ void main() { ), ); final SimpleRouterDelegate delegate = SimpleRouterDelegate( - builder: (BuildContext context, RouteInformation information) { + builder: (BuildContext context, RouteInformation? information) { final List children = []; - if (information.location != null) - children.add(Text(information.location)); + if (information!.location! != null) + children.add(Text(information.location!)); if (information.state != null) children.add(Text(information.state.toString())); return Column( @@ -573,7 +571,7 @@ void main() { final ByteData routerMessage = const JSONMethodCodec().encodeMethodCall( const MethodCall('pushRouteInformation', testRouteInformation) ); - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', routerMessage, (_) { }); + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', routerMessage, (_) { }); await tester.pump(); expect(find.text('testRouteName'), findsOneWidget); expect(find.text('state'), findsOneWidget); @@ -582,7 +580,7 @@ void main() { const String testRouteName = 'newTestRouteName'; final ByteData message = const JSONMethodCodec().encodeMethodCall( const MethodCall('pushRoute', testRouteName)); - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); await tester.pump(); expect(find.text('newTestRouteName'), findsOneWidget); }); @@ -596,8 +594,8 @@ void main() { ); final SimpleRouterDelegate delegate = SimpleRouterDelegate( reportConfiguration: true, - builder: (BuildContext context, RouteInformation information) { - return Text(information.location); + builder: (BuildContext context, RouteInformation? information) { + return Text(information!.location!); } ); delegate.onPopRoute = () { @@ -617,7 +615,7 @@ void main() { // Pop route through the message channel. final ByteData message = const JSONMethodCodec().encodeMethodCall(const MethodCall('popRoute')); - await ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); + await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/navigation', message, (_) { }); await tester.pump(); expect(find.text('popped'), findsOneWidget); }); @@ -631,7 +629,7 @@ Widget buildBoilerPlate(Widget child) { ); } -typedef SimpleRouterDelegateBuilder = Widget Function(BuildContext, RouteInformation); +typedef SimpleRouterDelegateBuilder = Widget Function(BuildContext, RouteInformation?); typedef SimpleRouterDelegatePopRoute = Future Function(); typedef SimpleNavigatorRouterDelegatePopPage = bool Function(Route route, T result); typedef RouterReportRouterInformation = void Function(RouteInformation); @@ -657,19 +655,19 @@ class SimpleRouterDelegate extends RouterDelegate with ChangeN this.reportConfiguration = false, }); - RouteInformation get routeInformation => _routeInformation; - RouteInformation _routeInformation; - set routeInformation(RouteInformation newValue) { + RouteInformation? get routeInformation => _routeInformation; + RouteInformation? _routeInformation; + set routeInformation(RouteInformation? newValue) { _routeInformation = newValue; notifyListeners(); } - SimpleRouterDelegateBuilder builder; - SimpleRouterDelegatePopRoute onPopRoute; + SimpleRouterDelegateBuilder? builder; + SimpleRouterDelegatePopRoute? onPopRoute; final bool reportConfiguration; @override - RouteInformation get currentConfiguration { + RouteInformation? get currentConfiguration { if (reportConfiguration) return routeInformation; return null; @@ -683,26 +681,24 @@ class SimpleRouterDelegate extends RouterDelegate with ChangeN @override Future popRoute() { - if (onPopRoute != null) - return onPopRoute(); - return SynchronousFuture(true); + return onPopRoute?.call() ?? SynchronousFuture(true); } @override - Widget build(BuildContext context) => builder(context, routeInformation); + Widget build(BuildContext context) => builder!(context, routeInformation); } class SimpleNavigatorRouterDelegate extends RouterDelegate with PopNavigatorRouterDelegateMixin, ChangeNotifier { SimpleNavigatorRouterDelegate({ - @required this.builder, - this.onPopPage, + required this.builder, + required this.onPopPage, }); @override GlobalKey navigatorKey = GlobalKey(); RouteInformation get routeInformation => _routeInformation; - RouteInformation _routeInformation; + late RouteInformation _routeInformation; set routeInformation(RouteInformation newValue) { _routeInformation = newValue; notifyListeners(); @@ -733,7 +729,7 @@ class SimpleNavigatorRouterDelegate extends RouterDelegate wit child: Text('base'), ), MaterialPage( - key: ValueKey(routeInformation?.location), + key: ValueKey(routeInformation.location!), child: builder(context, routeInformation), ) ], @@ -746,11 +742,11 @@ class SimpleRouteInformationProvider extends RouteInformationProvider with Chang this.onRouterReport }); - RouterReportRouterInformation onRouterReport; + RouterReportRouterInformation? onRouterReport; @override RouteInformation get value => _value; - RouteInformation _value; + late RouteInformation _value; set value(RouteInformation newValue) { _value = newValue; notifyListeners(); @@ -758,15 +754,14 @@ class SimpleRouteInformationProvider extends RouteInformationProvider with Chang @override void routerReportsNewRouteInformation(RouteInformation routeInformation) { - if (onRouterReport != null) - onRouterReport(routeInformation); + onRouterReport?.call(routeInformation); } } class SimpleAsyncRouteInformationParser extends RouteInformationParser { SimpleAsyncRouteInformationParser(); - Future parsingFuture; + late Future parsingFuture; @override Future parseRouteInformation(RouteInformation information) { @@ -781,18 +776,18 @@ class SimpleAsyncRouteInformationParser extends RouteInformationParser with ChangeNotifier{ SimpleAsyncRouterDelegate({ - @required this.builder, + required this.builder, }); - RouteInformation get routeInformation => _routeInformation; - RouteInformation _routeInformation; - set routeInformation(RouteInformation newValue) { + RouteInformation? get routeInformation => _routeInformation; + RouteInformation? _routeInformation; + set routeInformation(RouteInformation? newValue) { _routeInformation = newValue; notifyListeners(); } SimpleRouterDelegateBuilder builder; - Future setNewRouteFuture; + late Future setNewRouteFuture; @override Future setNewRoutePath(RouteInformation configuration) { diff --git a/packages/flutter/test/widgets/row_test.dart b/packages/flutter/test/widgets/row_test.dart index 9934cf5d4b..4671ace3e7 100644 --- a/packages/flutter/test/widgets/row_test.dart +++ b/packages/flutter/test/widgets/row_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/widgets.dart'; @@ -37,7 +35,7 @@ void main() { const Key child1Key = Key('child1'); const Key child2Key = Key('child2'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -68,7 +66,7 @@ void main() { const Key child1Key = Key('child1'); const Key child2Key = Key('child2'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -98,7 +96,7 @@ void main() { const Key child0Key = Key('child0'); const Key child1Key = Key('child1'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -129,7 +127,7 @@ void main() { const Key child1Key = Key('child1'); const Key child2Key = Key('child2'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -161,7 +159,7 @@ void main() { const Key child1Key = Key('child1'); const Key child2Key = Key('child2'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -194,7 +192,7 @@ void main() { const Key child2Key = Key('child2'); const Key child3Key = Key('child3'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -227,7 +225,7 @@ void main() { const Key child1Key = Key('child1'); const Key child2Key = Key('child2'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -258,7 +256,7 @@ void main() { const Key child0Key = Key('child0'); const Key child1Key = Key('child1'); - final FlutterExceptionHandler oldHandler = FlutterError.onError; + final FlutterExceptionHandler? oldHandler = FlutterError.onError; dynamic exception; FlutterError.onError = (FlutterErrorDetails details) { exception ??= details.exception; @@ -344,19 +342,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(600.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(100.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(700.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -394,19 +392,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(100.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(200.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -442,13 +440,13 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(300.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(400.0)); expect(OrderPainter.log, [1, 2]); @@ -486,19 +484,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(500.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(600.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(700.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -536,19 +534,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(350.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(700.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -588,25 +586,25 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(50.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(250.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(450.0)); renderBox = tester.renderObject(find.byKey(child3Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(650.0)); expect(OrderPainter.log, [1, 2, 3, 4]); @@ -644,19 +642,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(200.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(50.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(200.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(300.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(200.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(550.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -692,13 +690,13 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(150.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(100.0)); expect(OrderPainter.log, [1, 2]); @@ -767,19 +765,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(700.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(600.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(100.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -817,19 +815,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(700.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(600.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(500.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -865,13 +863,13 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(400.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(300.0)); expect(OrderPainter.log, [1, 2]); @@ -909,19 +907,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(200.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(100.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -959,19 +957,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(700.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(350.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -1011,25 +1009,25 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(650.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(450.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(250.0)); renderBox = tester.renderObject(find.byKey(child3Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(50.0)); expect(OrderPainter.log, [1, 2, 3, 4]); @@ -1067,19 +1065,19 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(200.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(550.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(200.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(300.0)); renderBox = tester.renderObject(find.byKey(child2Key)); expect(renderBox.size.width, equals(200.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(50.0)); expect(OrderPainter.log, [1, 2, 3]); @@ -1115,13 +1113,13 @@ void main() { renderBox = tester.renderObject(find.byKey(child0Key)); expect(renderBox.size.width, equals(100.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(150.0)); renderBox = tester.renderObject(find.byKey(child1Key)); expect(renderBox.size.width, equals(150.0)); expect(renderBox.size.height, equals(100.0)); - boxParentData = renderBox.parentData as BoxParentData; + boxParentData = renderBox.parentData! as BoxParentData; expect(boxParentData.offset.dx, equals(0.0)); expect(OrderPainter.log, [1, 2]); diff --git a/packages/flutter/test/widgets/rtl_test.dart b/packages/flutter/test/widgets/rtl_test.dart index 4abc46a61a..1281e06e95 100644 --- a/packages/flutter/test/widgets/rtl_test.dart +++ b/packages/flutter/test/widgets/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_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; @@ -26,20 +24,20 @@ void main() { await tester.pumpWidget( const Padding( - key: GlobalObjectKey>(null), + key: GlobalObjectKey>(Object()), padding: EdgeInsets.only(left: 1.0), ), ); await tester.pumpWidget(const Directionality( textDirection: TextDirection.rtl, child: Padding( - key: GlobalObjectKey>(null), + key: GlobalObjectKey>(Object()), padding: EdgeInsetsDirectional.only(start: 1.0), ), )); await tester.pumpWidget( const Padding( - key: GlobalObjectKey>(null), + key: GlobalObjectKey>(Object()), padding: EdgeInsets.only(left: 1.0), ), ); diff --git a/packages/flutter/test/widgets/run_app_async_test.dart b/packages/flutter/test/widgets/run_app_async_test.dart index 93bd5c7c9a..69b75a8373 100644 --- a/packages/flutter/test/widgets/run_app_async_test.dart +++ b/packages/flutter/test/widgets/run_app_async_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_test/flutter_test.dart'; import 'package:fake_async/fake_async.dart'; @@ -11,7 +9,7 @@ import 'package:fake_async/fake_async.dart'; void main() { setUp(() { WidgetsFlutterBinding.ensureInitialized(); - WidgetsBinding.instance.resetEpoch(); + WidgetsBinding.instance!.resetEpoch(); }); test('WidgetBinding build rendering tree and warm up frame back to back', () { @@ -25,9 +23,9 @@ void main() { ), ); // Rendering tree is not built synchronously. - expect(WidgetsBinding.instance.renderViewElement, isNull); + expect(WidgetsBinding.instance!.renderViewElement, isNull); fakeAsync.flushTimers(); - expect(WidgetsBinding.instance.renderViewElement, isNotNull); + expect(WidgetsBinding.instance!.renderViewElement, isNotNull); }); }); } diff --git a/packages/flutter/test/widgets/run_app_test.dart b/packages/flutter/test/widgets/run_app_test.dart index 3c3b95f32c..67da589e39 100644 --- a/packages/flutter/test/widgets/run_app_test.dart +++ b/packages/flutter/test/widgets/run_app_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_test/flutter_test.dart'; diff --git a/packages/flutter/test/widgets/safe_area_test.dart b/packages/flutter/test/widgets/safe_area_test.dart index 06514bc73a..2cc2fe4a19 100644 --- a/packages/flutter/test/widgets/safe_area_test.dart +++ b/packages/flutter/test/widgets/safe_area_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/rendering.dart'; import 'package:flutter/widgets.dart'; diff --git a/packages/flutter/test/widgets/scroll_activity_test.dart b/packages/flutter/test/widgets/scroll_activity_test.dart index 0fc5229d5a..9f8c3b02a4 100644 --- a/packages/flutter/test/widgets/scroll_activity_test.dart +++ b/packages/flutter/test/widgets/scroll_activity_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/scheduler.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -167,7 +165,7 @@ class _PageView62209State extends State { } class Carousel62209Page extends StatelessWidget { - const Carousel62209Page({this.number, Key key}) : super(key: key); + const Carousel62209Page({required this.number, Key? key}) : super(key: key); final int number; @@ -178,7 +176,7 @@ class Carousel62209Page extends StatelessWidget { } class Carousel62209 extends StatefulWidget { - const Carousel62209({Key key, this.pages}) : super(key: key); + const Carousel62209({Key? key, required this.pages}) : super(key: key); final List pages; @@ -188,11 +186,11 @@ class Carousel62209 extends StatefulWidget { class _Carousel62209State extends State { // page variables - PageController _pageController; + late PageController _pageController; int _currentPage = 0; // controls updates outside of user interaction - List _pages; + late List _pages; bool _jumpingToPage = false; @override @@ -216,13 +214,13 @@ class _Carousel62209State extends State { _pages = widget.pages.toList(); } else { _jumpingToPage = true; - SchedulerBinding.instance.addPostFrameCallback((_) { + SchedulerBinding.instance!.addPostFrameCallback((_) { if (mounted) { setState(() { _pages = widget.pages.toList(); _currentPage = newPage; _pageController.jumpToPage(_currentPage); - SchedulerBinding.instance.addPostFrameCallback((_) { + SchedulerBinding.instance!.addPostFrameCallback((_) { _jumpingToPage = false; }); }); @@ -240,7 +238,7 @@ class _Carousel62209State extends State { bool _handleScrollNotification(ScrollNotification notification) { if (notification is ScrollUpdateNotification) { - final int page = _pageController.page.round(); + final int page = _pageController.page!.round(); if (!_jumpingToPage && _currentPage != page) { _currentPage = page; } diff --git a/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart b/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart index 47aedaf905..ce58c553ea 100644 --- a/packages/flutter/test/widgets/scroll_aware_image_provider_test.dart +++ b/packages/flutter/test/widgets/scroll_aware_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:ui' as ui show Image; import 'package:flutter_test/flutter_test.dart'; @@ -13,29 +11,29 @@ import '../painting/image_test_utils.dart'; void main() { - ui.Image testImage; + late ui.Image testImage; setUpAll(() async { testImage = await createTestImage(width: 10, height: 10); }); tearDown(() { - imageCache.clear(); + imageCache?.clear(); }); T _findPhysics(WidgetTester tester) { - return Scrollable.of(find.byType(TestWidget).evaluate().first).position.physics as T; + return Scrollable.of(find.byType(TestWidget).evaluate().first)!.position.physics as T; } ScrollMetrics _findMetrics(WidgetTester tester) { - return Scrollable.of(find.byType(TestWidget).evaluate().first).position; + return Scrollable.of(find.byType(TestWidget).evaluate().first)!.position; } testWidgets('ScrollAwareImageProvider does not delay if widget is not in scrollable', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); await tester.pumpWidget(TestWidget(key)); - final DisposableBuildContext context = DisposableBuildContext(key.currentState); + final DisposableBuildContext context = DisposableBuildContext(key.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -43,19 +41,19 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); final ImageStream stream = imageProvider.resolve(ImageConfiguration.empty); expect(testImageProvider.configuration, ImageConfiguration.empty); expect(stream.completer, isNotNull); - expect(stream.completer.hasListeners, true); - expect(imageCache.containsKey(testImageProvider), true); - expect(imageCache.currentSize, 0); + expect(stream.completer!.hasListeners, true); + expect(imageCache!.containsKey(testImageProvider), true); + expect(imageCache!.currentSize, 0); testImageProvider.complete(); - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); }); testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is not scrolling', (WidgetTester tester) async { @@ -70,7 +68,7 @@ void main() { ), )); - final DisposableBuildContext context = DisposableBuildContext(key.currentState); + final DisposableBuildContext context = DisposableBuildContext(key.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -78,19 +76,19 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); final ImageStream stream = imageProvider.resolve(ImageConfiguration.empty); expect(testImageProvider.configuration, ImageConfiguration.empty); expect(stream.completer, isNotNull); - expect(stream.completer.hasListeners, true); - expect(imageCache.containsKey(testImageProvider), true); - expect(imageCache.currentSize, 0); + expect(stream.completer!.hasListeners, true); + expect(imageCache!.containsKey(testImageProvider), true); + expect(imageCache!.currentSize, 0); testImageProvider.complete(); - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); expect(_findPhysics(tester).velocities, [0]); }); @@ -110,7 +108,7 @@ void main() { ), )); - final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState); + final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -118,7 +116,7 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); scrollController.animateTo( 100, @@ -142,13 +140,13 @@ void main() { expect(testImageProvider.configuration, ImageConfiguration.empty); expect(stream.completer, isNotNull); - expect(stream.completer.hasListeners, true); - expect(imageCache.containsKey(testImageProvider), true); - expect(imageCache.currentSize, 0); + expect(stream.completer!.hasListeners, true); + expect(imageCache!.containsKey(testImageProvider), true); + expect(imageCache!.currentSize, 0); testImageProvider.complete(); - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); }); testWidgets('ScrollAwareImageProvider delays if in scrollable that is scrolling fast', (WidgetTester tester) async { @@ -167,7 +165,7 @@ void main() { ), )); - final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState); + final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -175,7 +173,7 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); scrollController.animateTo( 3000, @@ -200,22 +198,22 @@ void main() { expect(testImageProvider.configuration, null); expect(stream.completer, null); - expect(imageCache.containsKey(testImageProvider), false); - expect(imageCache.currentSize, 0); + expect(imageCache!.containsKey(testImageProvider), false); + expect(imageCache!.currentSize, 0); await tester.pump(const Duration(seconds: 1)); expect(physics.velocities.last, 0); expect(testImageProvider.configuration, ImageConfiguration.empty); expect(stream.completer, isNotNull); - expect(stream.completer.hasListeners, true); + expect(stream.completer!.hasListeners, true); - expect(imageCache.containsKey(testImageProvider), true); - expect(imageCache.currentSize, 0); + expect(imageCache!.containsKey(testImageProvider), true); + expect(imageCache!.currentSize, 0); testImageProvider.complete(); - expect(imageCache.currentSize, 1); + expect(imageCache!.currentSize, 1); }); testWidgets('ScrollAwareImageProvider delays if in scrollable that is scrolling fast and fizzles if disposed', (WidgetTester tester) async { @@ -234,7 +232,7 @@ void main() { ), )); - final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState); + final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -242,7 +240,7 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); scrollController.animateTo( 3000, @@ -267,8 +265,8 @@ void main() { expect(testImageProvider.configuration, null); expect(stream.completer, null); - expect(imageCache.containsKey(testImageProvider), false); - expect(imageCache.currentSize, 0); + expect(imageCache!.containsKey(testImageProvider), false); + expect(imageCache!.currentSize, 0); // as if we had picked a context that scrolled out of the tree. context.dispose(); @@ -279,12 +277,12 @@ void main() { expect(testImageProvider.configuration, null); expect(stream.completer, null); - expect(imageCache.containsKey(testImageProvider), false); - expect(imageCache.currentSize, 0); + expect(imageCache!.containsKey(testImageProvider), false); + expect(imageCache!.currentSize, 0); testImageProvider.complete(); - expect(imageCache.currentSize, 0); + expect(imageCache!.currentSize, 0); }); testWidgets('ScrollAwareImageProvider resolves from ImageCache and does not set completer twice', (WidgetTester tester) async { @@ -299,7 +297,7 @@ void main() { ), )); - final DisposableBuildContext context = DisposableBuildContext(key.currentState); + final DisposableBuildContext context = DisposableBuildContext(key.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -307,7 +305,7 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); final ControllablePhysics physics = _findPhysics(tester); physics.recommendDeferredLoadingValue = true; @@ -316,28 +314,28 @@ void main() { expect(testImageProvider.configuration, null); expect(stream.completer, null); - expect(imageCache.containsKey(testImageProvider), false); - expect(imageCache.currentSize, 0); + expect(imageCache!.containsKey(testImageProvider), false); + expect(imageCache!.currentSize, 0); // Simulate a case where someone else has managed to complete this stream - // so it can land in the cache right before we stop scrolling fast. // If we miss the early return, we will fail. testImageProvider.complete(); - imageCache.putIfAbsent(testImageProvider, () => testImageProvider.load(testImageProvider, PaintingBinding.instance.instantiateImageCodec)); + imageCache!.putIfAbsent(testImageProvider, () => testImageProvider.load(testImageProvider, PaintingBinding.instance!.instantiateImageCodec)); // We've stopped scrolling fast. physics.recommendDeferredLoadingValue = false; await tester.idle(); - expect(imageCache.containsKey(testImageProvider), true); - expect(imageCache.currentSize, 1); + expect(imageCache!.containsKey(testImageProvider), true); + expect(imageCache!.currentSize, 1); expect(testImageProvider.loadCallCount, 1); expect(stream.completer, null); }); testWidgets('ScrollAwareImageProvider does not block LRU updates to image cache', (WidgetTester tester) async { - final int oldSize = imageCache.maximumSize; - imageCache.maximumSize = 1; + final int oldSize = imageCache!.maximumSize; + imageCache!.maximumSize = 1; final GlobalKey key = GlobalKey(); final ScrollController scrollController = ScrollController(); @@ -350,7 +348,7 @@ void main() { ), )); - final DisposableBuildContext context = DisposableBuildContext(key.currentState); + final DisposableBuildContext context = DisposableBuildContext(key.currentState!); final TestImageProvider testImageProvider = TestImageProvider(testImage); final ScrollAwareImageProvider imageProvider = ScrollAwareImageProvider( context: context, @@ -358,7 +356,7 @@ void main() { ); expect(testImageProvider.configuration, null); - expect(imageCache.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider), false); final ControllablePhysics physics = _findPhysics(tester); physics.recommendDeferredLoadingValue = true; @@ -367,41 +365,41 @@ void main() { expect(testImageProvider.configuration, null); expect(stream.completer, null); - expect(imageCache.currentSize, 0); + expect(imageCache!.currentSize, 0); // Occupy the only slot in the cache with another image. final TestImageProvider testImageProvider2 = TestImageProvider(testImage); testImageProvider2.complete(); - await precacheImage(testImageProvider2, context.context); - expect(imageCache.containsKey(testImageProvider), false); - expect(imageCache.containsKey(testImageProvider2), true); - expect(imageCache.currentSize, 1); + await precacheImage(testImageProvider2, context.context!); + expect(imageCache!.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider2), true); + expect(imageCache!.currentSize, 1); // Complete the original image while we're still scrolling fast. testImageProvider.complete(); - stream.setCompleter(testImageProvider.load(testImageProvider, PaintingBinding.instance.instantiateImageCodec)); + stream.setCompleter(testImageProvider.load(testImageProvider, PaintingBinding.instance!.instantiateImageCodec)); // Verify that this hasn't changed the cache state yet - expect(imageCache.containsKey(testImageProvider), false); - expect(imageCache.containsKey(testImageProvider2), true); - expect(imageCache.currentSize, 1); + expect(imageCache!.containsKey(testImageProvider), false); + expect(imageCache!.containsKey(testImageProvider2), true); + expect(imageCache!.currentSize, 1); expect(testImageProvider.loadCallCount, 1); await tester.pump(); // After pumping a frame, the original image should be in the cache because // it took the LRU slot. - expect(imageCache.containsKey(testImageProvider), true); - expect(imageCache.containsKey(testImageProvider2), false); - expect(imageCache.currentSize, 1); + expect(imageCache!.containsKey(testImageProvider), true); + expect(imageCache!.containsKey(testImageProvider2), false); + expect(imageCache!.currentSize, 1); expect(testImageProvider.loadCallCount, 1); - imageCache.maximumSize = oldSize; + imageCache!.maximumSize = oldSize; }); } class TestWidget extends StatefulWidget { - const TestWidget(Key key) : super(key: key); + const TestWidget(Key? key) : super(key: key); @override State createState() => TestWidgetState(); @@ -413,13 +411,13 @@ class TestWidgetState extends State { } class RecordingPhysics extends ScrollPhysics { - RecordingPhysics({ ScrollPhysics parent }) : super(parent: parent); + RecordingPhysics({ ScrollPhysics? parent }) : super(parent: parent); final List velocities = []; @override - RecordingPhysics applyTo(ScrollPhysics ancestor) { - return RecordingPhysics(parent: buildParent(ancestor)); + RecordingPhysics applyTo(ScrollPhysics? ancestor) { + return RecordingPhysics(parent: buildParent(ancestor)!); } @override @@ -433,13 +431,13 @@ class RecordingPhysics extends ScrollPhysics { // times without worrying about actual scrolling mechanics. // ignore: must_be_immutable class ControllablePhysics extends ScrollPhysics { - ControllablePhysics({ ScrollPhysics parent }) : super(parent: parent); + ControllablePhysics({ ScrollPhysics? parent }) : super(parent: parent); bool recommendDeferredLoadingValue = false; @override - ControllablePhysics applyTo(ScrollPhysics ancestor) { - return ControllablePhysics(parent: buildParent(ancestor)); + ControllablePhysics applyTo(ScrollPhysics? ancestor) { + return ControllablePhysics(parent: buildParent(ancestor)!); } @override diff --git a/packages/flutter/test/widgets/scroll_behavior_test.dart b/packages/flutter/test/widgets/scroll_behavior_test.dart index 126f1afb53..618321c848 100644 --- a/packages/flutter/test/widgets/scroll_behavior_test.dart +++ b/packages/flutter/test/widgets/scroll_behavior_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/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; -GestureVelocityTrackerBuilder lastCreatedBuilder; +late GestureVelocityTrackerBuilder lastCreatedBuilder; class TestScrollBehavior extends ScrollBehavior { const TestScrollBehavior(this.flag); @@ -36,15 +34,15 @@ class TestScrollBehavior extends ScrollBehavior { void main() { testWidgets('Inherited ScrollConfiguration changed', (WidgetTester tester) async { final GlobalKey key = GlobalKey(debugLabel: 'scrollable'); - TestScrollBehavior behavior; - ScrollPositionWithSingleContext position; + TestScrollBehavior? behavior; + late ScrollPositionWithSingleContext position; final Widget scrollView = SingleChildScrollView( key: key, child: Builder( builder: (BuildContext context) { behavior = ScrollConfiguration.of(context) as TestScrollBehavior; - position = Scrollable.of(context).position as ScrollPositionWithSingleContext; + position = Scrollable.of(context)!.position as ScrollPositionWithSingleContext; return Container(height: 1000.0); }, ), @@ -58,7 +56,7 @@ void main() { ); expect(behavior, isNotNull); - expect(behavior.flag, isTrue); + expect(behavior!.flag, isTrue); expect(position.physics, isA()); expect(lastCreatedBuilder(const PointerDownEvent()), isA()); ScrollMetrics metrics = position.copyWith(); @@ -74,7 +72,7 @@ void main() { ); expect(behavior, isNotNull); - expect(behavior.flag, isFalse); + expect(behavior!.flag, isFalse); expect(position.physics, isA()); expect(lastCreatedBuilder(const PointerDownEvent()), isA()); // Regression test for https://github.com/flutter/flutter/issues/5856 diff --git a/packages/flutter/test/widgets/scroll_controller_test.dart b/packages/flutter/test/widgets/scroll_controller_test.dart index 8ca8a51224..688826b4c3 100644 --- a/packages/flutter/test/widgets/scroll_controller_test.dart +++ b/packages/flutter/test/widgets/scroll_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 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; diff --git a/packages/flutter/test/widgets/scroll_events_test.dart b/packages/flutter/test/widgets/scroll_events_test.dart index 90d2a43737..d562be1025 100644 --- a/packages/flutter/test/widgets/scroll_events_test.dart +++ b/packages/flutter/test/widgets/scroll_events_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 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; -import 'package:meta/meta.dart'; -Widget _buildScroller({ List log }) { +Widget _buildScroller({ required List log }) { return NotificationListener( onNotification: (ScrollNotification notification) { if (notification is ScrollStartNotification) { @@ -29,7 +26,7 @@ Widget _buildScroller({ List log }) { } void main() { - Completer animateTo(WidgetTester tester, double newScrollOffset, { @required Duration duration }) { + Completer animateTo(WidgetTester tester, double newScrollOffset, { required Duration duration }) { final Completer completer = Completer(); final ScrollableState scrollable = tester.state(find.byType(Scrollable)); scrollable.position.animateTo(newScrollOffset, duration: duration, curve: Curves.linear).whenComplete(completer.complete); diff --git a/packages/flutter/test/widgets/scroll_interaction_test.dart b/packages/flutter/test/widgets/scroll_interaction_test.dart index 1cf104924a..7afdf1aa32 100644 --- a/packages/flutter/test/widgets/scroll_interaction_test.dart +++ b/packages/flutter/test/widgets/scroll_interaction_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/widgets/scroll_notification_test.dart b/packages/flutter/test/widgets/scroll_notification_test.dart index e71e6255c9..7b4b9dc571 100644 --- a/packages/flutter/test/widgets/scroll_notification_test.dart +++ b/packages/flutter/test/widgets/scroll_notification_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/gestures.dart'; import 'package:flutter/material.dart'; @@ -11,7 +9,7 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('Scroll notification basics', (WidgetTester tester) async { - ScrollNotification notification; + late ScrollNotification notification; await tester.pumpWidget(NotificationListener( onNotification: (ScrollNotification value) { @@ -30,7 +28,7 @@ void main() { expect(notification.depth, equals(0)); final ScrollStartNotification start = notification as ScrollStartNotification; expect(start.dragDetails, isNotNull); - expect(start.dragDetails.globalPosition, equals(const Offset(100.0, 100.0))); + expect(start.dragDetails!.globalPosition, equals(const Offset(100.0, 100.0))); await gesture.moveBy(const Offset(-10.0, -10.0)); await tester.pump(const Duration(seconds: 1)); @@ -38,8 +36,8 @@ void main() { expect(notification.depth, equals(0)); final ScrollUpdateNotification update = notification as ScrollUpdateNotification; expect(update.dragDetails, isNotNull); - expect(update.dragDetails.globalPosition, equals(const Offset(90.0, 90.0))); - expect(update.dragDetails.delta, equals(const Offset(0.0, -10.0))); + expect(update.dragDetails!.globalPosition, equals(const Offset(90.0, 90.0))); + expect(update.dragDetails!.delta, equals(const Offset(0.0, -10.0))); await gesture.up(); await tester.pump(const Duration(seconds: 1)); @@ -47,7 +45,7 @@ void main() { expect(notification.depth, equals(0)); final ScrollEndNotification end = notification as ScrollEndNotification; expect(end.dragDetails, isNotNull); - expect(end.dragDetails.velocity, equals(Velocity.zero)); + expect(end.dragDetails!.velocity, equals(Velocity.zero)); }); testWidgets('Scroll notification depth', (WidgetTester tester) async { diff --git a/packages/flutter/test/widgets/scroll_physics_test.dart b/packages/flutter/test/widgets/scroll_physics_test.dart index fdb7a14291..45bdbf461e 100644 --- a/packages/flutter/test/widgets/scroll_physics_test.dart +++ b/packages/flutter/test/widgets/scroll_physics_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/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -12,20 +10,20 @@ import 'package:flutter_test/flutter_test.dart'; class TestScrollPhysics extends ScrollPhysics { const TestScrollPhysics({ - this.name, - ScrollPhysics parent + required this.name, + ScrollPhysics? parent }) : super(parent: parent); final String name; @override - TestScrollPhysics applyTo(ScrollPhysics ancestor) { + TestScrollPhysics applyTo(ScrollPhysics? ancestor) { return TestScrollPhysics( name: name, - parent: parent?.applyTo(ancestor) ?? ancestor, + parent: parent?.applyTo(ancestor) ?? ancestor!, ); } - TestScrollPhysics get namedParent => parent as TestScrollPhysics; + TestScrollPhysics get namedParent => parent! as TestScrollPhysics; String get names => parent == null ? name : '$name ${namedParent.names}'; @override @@ -69,7 +67,7 @@ void main() { const ScrollPhysics always = AlwaysScrollableScrollPhysics(); const ScrollPhysics page = PageScrollPhysics(); - String types(ScrollPhysics s) => s.parent == null ? '${s.runtimeType}' : '${s.runtimeType} ${types(s.parent)}'; + String types(ScrollPhysics? value) => value!.parent == null ? '${value.runtimeType}' : '${value.runtimeType} ${types(value.parent)}'; expect( types(bounce.applyTo(clamp.applyTo(never.applyTo(always.applyTo(page))))), @@ -112,13 +110,13 @@ void main() { // Calls to createBallisticSimulation may happen on every frame (i.e. when the maxScrollExtent changes) // Changing velocity for time 0 may cause a sudden, unwanted damping/speedup effect - expect(bounce.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000)); - expect(clamp.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000)); - expect(page.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000)); + expect(bounce.createBallisticSimulation(position, 1000)!.dx(0), moreOrLessEquals(1000)); + expect(clamp.createBallisticSimulation(position, 1000)!.dx(0), moreOrLessEquals(1000)); + expect(page.createBallisticSimulation(position, 1000)!.dx(0), moreOrLessEquals(1000)); }); group('BouncingScrollPhysics test', () { - BouncingScrollPhysics physicsUnderTest; + late BouncingScrollPhysics physicsUnderTest; setUp(() { physicsUnderTest = const BouncingScrollPhysics(); @@ -253,7 +251,7 @@ void main() { axisDirection: AxisDirection.down, ); expect(position.pixels, pixels); - FlutterError error; + late FlutterError error; try { physics.applyBoundaryConditions(position, pixels); } on FlutterError catch (e) { diff --git a/packages/flutter/test/widgets/scroll_position_test.dart b/packages/flutter/test/widgets/scroll_position_test.dart index 1a8075c065..726db582f1 100644 --- a/packages/flutter/test/widgets/scroll_position_test.dart +++ b/packages/flutter/test/widgets/scroll_position_test.dart @@ -2,11 +2,8 @@ // 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:meta/meta.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/material.dart'; @@ -16,8 +13,8 @@ ScrollController _controller = ScrollController( class ThePositiveNumbers extends StatelessWidget { const ThePositiveNumbers({ - Key key, - @required this.from, + Key? key, + required this.from, }) : super(key: key); final int from; @override @@ -93,7 +90,7 @@ Future performTest(WidgetTester tester, bool maintainState) async { expect(find.text('16'), findsNothing, reason: 'with maintainState: $maintainState'); expect(find.text('100'), findsNothing, reason: 'with maintainState: $maintainState'); - navigatorKey.currentState.pushNamed('/second'); + navigatorKey.currentState!.pushNamed('/second'); await tester.pump(); // navigating always takes two frames, one to start... await tester.pump(const Duration(seconds: 1)); // ...and one to end the transition @@ -114,7 +111,7 @@ Future performTest(WidgetTester tester, bool maintainState) async { expect(find.text('10010'), findsNothing, reason: 'with maintainState: $maintainState'); expect(find.text('10100'), findsNothing, reason: 'with maintainState: $maintainState'); - navigatorKey.currentState.pop(); + navigatorKey.currentState!.pop(); await tester.pump(); // again, navigating always takes two frames // Ensure we don't clamp the scroll offset even during the navigation. diff --git a/packages/flutter/test/widgets/scroll_simulation_test.dart b/packages/flutter/test/widgets/scroll_simulation_test.dart index 7ad4b263e3..fc2a7052c5 100644 --- a/packages/flutter/test/widgets/scroll_simulation_test.dart +++ b/packages/flutter/test/widgets/scroll_simulation_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/widgets/scroll_view_test.dart b/packages/flutter/test/widgets/scroll_view_test.dart index 4ea27cc1ce..5f89f3f3b6 100644 --- a/packages/flutter/test/widgets/scroll_view_test.dart +++ b/packages/flutter/test/widgets/scroll_view_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'; import 'package:flutter/gestures.dart' show DragStartBehavior; @@ -33,7 +31,7 @@ class WidgetsLocalizationsDelegate extends LocalizationsDelegate false; } -Widget textFieldBoilerplate({ Widget child }) { +Widget textFieldBoilerplate({ required Widget child }) { return MaterialApp( home: Localizations( locale: const Locale('en', 'US'), @@ -125,11 +123,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('ListView.builder dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -159,11 +157,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('ListView.custom dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -195,11 +193,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('ListView.separated dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -230,11 +228,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('GridView dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -264,11 +262,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('GridView.builder dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -299,11 +297,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('GridView.count dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -333,11 +331,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('GridView.extent dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -367,11 +365,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('GridView.custom dismiss keyboard onDrag test', (WidgetTester tester) async { @@ -404,11 +402,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('ListView dismiss keyboard manual test', (WidgetTester tester) async { @@ -435,11 +433,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('ListView.builder dismiss keyboard manual test', (WidgetTester tester) async { @@ -469,11 +467,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('ListView.custom dismiss keyboard manual test', (WidgetTester tester) async { @@ -505,11 +503,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('ListView.separated dismiss keyboard manual test', (WidgetTester tester) async { @@ -540,11 +538,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('GridView dismiss keyboard manual test', (WidgetTester tester) async { @@ -574,11 +572,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('GridView.builder dismiss keyboard manual test', (WidgetTester tester) async { @@ -609,11 +607,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('GridView.count dismiss keyboard manual test', (WidgetTester tester) async { @@ -643,11 +641,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('GridView.extent dismiss keyboard manual test', (WidgetTester tester) async { @@ -677,11 +675,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('GridView.custom dismiss keyboard manual test', (WidgetTester tester) async { @@ -714,11 +712,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); }); testWidgets('ListView restart ballistic activity out of range', (WidgetTester tester) async { @@ -831,11 +829,11 @@ void main() { final Finder finder = find.byType(TextField).first; final TextField textField = tester.widget(finder); await tester.showKeyboard(finder); - expect(textField.focusNode.hasFocus, isTrue); + expect(textField.focusNode!.hasFocus, isTrue); await tester.drag(finder, const Offset(0.0, -40.0)); await tester.pumpAndSettle(); - expect(textField.focusNode.hasFocus, isFalse); + expect(textField.focusNode!.hasFocus, isFalse); }); testWidgets('Can jumpTo during drag', (WidgetTester tester) async { @@ -1164,41 +1162,6 @@ void main() { // A separatorBuilder that always returns a Divider is fine await tester.pumpWidget(buildFrame(const Divider())); expect(tester.takeException(), isNull); - - // A separatorBuilder that returns null throws a FlutterError - await tester.pumpWidget(buildFrame(null)); - expect(tester.takeException(), isFlutterError); - expect(find.byType(ErrorWidget), findsOneWidget); - }); - - testWidgets('itemBuilder can return null', (WidgetTester tester) async { - const List listOfValues = ['ALPHA', 'BETA', 'GAMMA', 'DELTA']; - const Key key = Key('list'); - const int RENDER_NULL_AT = 2; // only render the first 2 values - - Widget buildFrame() { - return MaterialApp( - home: Material( - child: ListView.builder( - key: key, - itemBuilder: (BuildContext context, int index) { - if (index == RENDER_NULL_AT) { - return null; - } - return Text(listOfValues[index]); - }, - itemCount: listOfValues.length, - ), - ), - ); - } - - // The length of a list is itemCount or the index of the first itemBuilder - // that returns null, whichever is smaller - await tester.pumpWidget(buildFrame()); - expect(tester.takeException(), isNull); - expect(find.byType(ErrorWidget), findsNothing); - expect(find.byType(Text), findsNWidgets(RENDER_NULL_AT)); }); testWidgets('when itemBuilder throws, creates Error Widget', (WidgetTester tester) async { diff --git a/packages/flutter/test/widgets/scrollable_animations_test.dart b/packages/flutter/test/widgets/scrollable_animations_test.dart index 3b8c27b306..98341b5759 100644 --- a/packages/flutter/test/widgets/scrollable_animations_test.dart +++ b/packages/flutter/test/widgets/scrollable_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 'package:flutter_test/flutter_test.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; @@ -71,10 +69,10 @@ void main() { final double targetPosition = controller.position.pixels + doubleTolerance; controller.position.animateTo(targetPosition, duration: const Duration(seconds: 10), curve: Curves.linear); - expect(SchedulerBinding.instance.transientCallbackCount, equals(1), reason: 'Expected an animation.'); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(1), reason: 'Expected an animation.'); }); } void expectNoAnimation() { - expect(SchedulerBinding.instance.transientCallbackCount, equals(0), reason: 'Expected no animation.'); + expect(SchedulerBinding.instance!.transientCallbackCount, equals(0), reason: 'Expected no animation.'); } diff --git a/packages/flutter/test/widgets/scrollable_dispose_test.dart b/packages/flutter/test/widgets/scrollable_dispose_test.dart index 6500c19e51..e0bdc0afb6 100644 --- a/packages/flutter/test/widgets/scrollable_dispose_test.dart +++ b/packages/flutter/test/widgets/scrollable_dispose_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_test/flutter_test.dart'; diff --git a/packages/flutter/test/widgets/scrollable_fling_test.dart b/packages/flutter/test/widgets/scrollable_fling_test.dart index a4b5c355ef..87515f36a3 100644 --- a/packages/flutter/test/widgets/scrollable_fling_test.dart +++ b/packages/flutter/test/widgets/scrollable_fling_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/material.dart'; import 'package:flutter/gestures.dart' show DragStartBehavior; diff --git a/packages/flutter/test/widgets/scrollable_grid_test.dart b/packages/flutter/test/widgets/scrollable_grid_test.dart index 24e773e077..03bb4d78f3 100644 --- a/packages/flutter/test/widgets/scrollable_grid_test.dart +++ b/packages/flutter/test/widgets/scrollable_grid_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'; import 'package:flutter/rendering.dart'; diff --git a/packages/flutter/test/widgets/scrollable_in_overlay_test.dart b/packages/flutter/test/widgets/scrollable_in_overlay_test.dart index eb8ff0604b..cca29027de 100644 --- a/packages/flutter/test/widgets/scrollable_in_overlay_test.dart +++ b/packages/flutter/test/widgets/scrollable_in_overlay_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/material.dart'; diff --git a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart b/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart index 793c152e28..56a2b84c33 100644 --- a/packages/flutter/test/widgets/scrollable_list_hit_testing_test.dart +++ b/packages/flutter/test/widgets/scrollable_list_hit_testing_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/rendering.dart'; import 'package:flutter/widgets.dart'; diff --git a/packages/flutter/test/widgets/scrollable_of_test.dart b/packages/flutter/test/widgets/scrollable_of_test.dart index c480b786f2..19d3ac246c 100644 --- a/packages/flutter/test/widgets/scrollable_of_test.dart +++ b/packages/flutter/test/widgets/scrollable_of_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_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; class ScrollPositionListener extends StatefulWidget { - const ScrollPositionListener({ Key key, this.child, this.log}) : super(key: key); + const ScrollPositionListener({ Key? key, required this.child, required this.log}) : super(key: key); final Widget child; final ValueChanged log; @@ -18,7 +16,7 @@ class ScrollPositionListener extends StatefulWidget { } class _ScrollPositionListenerState extends State { - ScrollPosition _position; + ScrollPosition? _position; @override void didChangeDependencies() { @@ -26,7 +24,7 @@ class _ScrollPositionListenerState extends State { _position?.removeListener(listener); _position = Scrollable.of(context)?.position; _position?.addListener(listener); - widget.log('didChangeDependencies ${_position?.pixels?.toStringAsFixed(1)}'); + widget.log('didChangeDependencies ${_position?.pixels.toStringAsFixed(1)}'); } @override @@ -39,20 +37,20 @@ class _ScrollPositionListenerState extends State { Widget build(BuildContext context) => widget.child; void listener() { - widget.log('listener ${_position?.pixels?.toStringAsFixed(1)}'); + widget.log('listener ${_position?.pixels.toStringAsFixed(1)}'); } } void main() { testWidgets('Scrollable.of() dependent rebuilds when Scrollable position changes', (WidgetTester tester) async { - String logValue; + late String logValue; final ScrollController controller = ScrollController(); // Changing the SingleChildScrollView's physics causes the // ScrollController's ScrollPosition to be rebuilt. - Widget buildFrame(ScrollPhysics physics) { + Widget buildFrame(ScrollPhysics? physics) { return SingleChildScrollView( controller: controller, physics: physics, @@ -86,7 +84,7 @@ void main() { }); testWidgets('Scrollable.of() is possible using ScrollNotification context', (WidgetTester tester) async { - ScrollNotification notification; + late ScrollNotification notification; await tester.pumpWidget(NotificationListener( onNotification: (ScrollNotification value) { @@ -102,6 +100,6 @@ void main() { await tester.pump(const Duration(seconds: 1)); final StatefulElement scrollableElement = find.byType(Scrollable).evaluate().first as StatefulElement; - expect(Scrollable.of(notification.context), equals(scrollableElement.state)); + expect(Scrollable.of(notification.context!), equals(scrollableElement.state)); }); } diff --git a/packages/flutter/test/widgets/scrollable_restoration_test.dart b/packages/flutter/test/widgets/scrollable_restoration_test.dart index 8dcb34a175..8733787264 100644 --- a/packages/flutter/test/widgets/scrollable_restoration_test.dart +++ b/packages/flutter/test/widgets/scrollable_restoration_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 'package:flutter_test/flutter_test.dart'; @@ -397,20 +395,20 @@ void main() { ), ); - expect(tester.renderObject(find.byType(SliverAppBar)).geometry.paintExtent, 150); + expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 150); expect(find.text('Tile 0'), findsOneWidget); expect(find.text('Tile 10'), findsNothing); await tester.drag(find.byType(ListView), const Offset(0, -500)); await tester.pump(); - expect(tester.renderObject(find.byType(SliverAppBar)).geometry.paintExtent, 56); + expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 56); expect(find.text('Tile 0'), findsNothing); expect(find.text('Tile 10'), findsOneWidget); await tester.restartAndRestore(); - expect(tester.renderObject(find.byType(SliverAppBar)).geometry.paintExtent, 56); + expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 56); expect(find.text('Tile 0'), findsNothing); expect(find.text('Tile 10'), findsOneWidget); @@ -418,13 +416,13 @@ void main() { await tester.drag(find.byType(ListView), const Offset(0, 600)); await tester.pump(); - expect(tester.renderObject(find.byType(SliverAppBar)).geometry.paintExtent, 150); + expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 150); expect(find.text('Tile 0'), findsOneWidget); expect(find.text('Tile 10'), findsNothing); await tester.restoreFrom(data); - expect(tester.renderObject(find.byType(SliverAppBar)).geometry.paintExtent, 56); + expect(tester.renderObject(find.byType(SliverAppBar)).geometry!.paintExtent, 56); expect(find.text('Tile 0'), findsNothing); expect(find.text('Tile 10'), findsOneWidget); }); @@ -552,7 +550,7 @@ Future restoreScrollAndVerify(WidgetTester tester, {double secondOffset = } class TestHarness extends StatelessWidget { - const TestHarness({Key key, this.child, this.height = 100}) : super(key: key); + const TestHarness({Key? key, required this.child, this.height = 100}) : super(key: key); final Widget child; final double height;