Unverified Commit 3f56178d authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Convert some more widget tests to NNBD (#68129)

parent f7ee4402
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -74,7 +72,7 @@ void main() { ...@@ -74,7 +72,7 @@ void main() {
manager.doSerialization(); manager.doSerialization();
final BucketSpyState state = tester.state(find.byType(BucketSpy)); final BucketSpyState state = tester.state(find.byType(BucketSpy));
expect(state.bucket.restorationId, id); expect(state.bucket!.restorationId, id);
expect(rawData[childrenMapKey].containsKey(id), isTrue); expect(rawData[childrenMapKey].containsKey(id), isTrue);
}); });
...@@ -94,8 +92,8 @@ void main() { ...@@ -94,8 +92,8 @@ void main() {
manager.doSerialization(); manager.doSerialization();
final BucketSpyState state = tester.state(find.byType(BucketSpy)); final BucketSpyState state = tester.state(find.byType(BucketSpy));
expect(state.bucket.restorationId, 'child1'); expect(state.bucket!.restorationId, 'child1');
expect(state.bucket.read<int>('foo'), 22); expect(state.bucket!.read<int>('foo'), 22);
}); });
testWidgets('renames existing bucket when new ID is provided', (WidgetTester tester) async { testWidgets('renames existing bucket when new ID is provided', (WidgetTester tester) async {
...@@ -115,9 +113,9 @@ void main() { ...@@ -115,9 +113,9 @@ void main() {
// Claimed existing bucket with data. // Claimed existing bucket with data.
final BucketSpyState state = tester.state(find.byType(BucketSpy)); final BucketSpyState state = tester.state(find.byType(BucketSpy));
expect(state.bucket.restorationId, 'child1'); expect(state.bucket!.restorationId, 'child1');
expect(state.bucket.read<int>('foo'), 22); expect(state.bucket!.read<int>('foo'), 22);
final RestorationBucket bucket = state.bucket; final RestorationBucket bucket = state.bucket!;
// Rename the existing bucket. // Rename the existing bucket.
await tester.pumpWidget( await tester.pumpWidget(
...@@ -131,8 +129,8 @@ void main() { ...@@ -131,8 +129,8 @@ void main() {
); );
manager.doSerialization(); manager.doSerialization();
expect(state.bucket.restorationId, 'something else'); expect(state.bucket!.restorationId, 'something else');
expect(state.bucket.read<int>('foo'), 22); expect(state.bucket!.read<int>('foo'), 22);
expect(state.bucket, same(bucket)); expect(state.bucket, same(bucket));
}); });
...@@ -193,7 +191,7 @@ void main() { ...@@ -193,7 +191,7 @@ void main() {
); );
manager.doSerialization(); manager.doSerialization();
expect(state.bucket, isNotNull); expect(state.bucket, isNotNull);
expect(state.bucket.restorationId, 'foo'); expect(state.bucket!.restorationId, 'foo');
// Change id back to null. // Change id back to null.
await tester.pumpWidget( await tester.pumpWidget(
...@@ -237,7 +235,7 @@ void main() { ...@@ -237,7 +235,7 @@ void main() {
); );
manager.doSerialization(); manager.doSerialization();
expect(state.bucket, isNotNull); expect(state.bucket, isNotNull);
expect(state.bucket.restorationId, 'foo'); expect(state.bucket!.restorationId, 'foo');
// Move out of scope again. // Move out of scope again.
await tester.pumpWidget( await tester.pumpWidget(
...@@ -288,11 +286,11 @@ void main() { ...@@ -288,11 +286,11 @@ void main() {
); );
manager.doSerialization(); manager.doSerialization();
final BucketSpyState state = tester.state(find.byType(BucketSpy)); 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); 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(); manager.doSerialization();
// Move scope. // Move scope.
...@@ -316,9 +314,9 @@ void main() { ...@@ -316,9 +314,9 @@ void main() {
), ),
); );
manager.doSerialization(); manager.doSerialization();
expect(state.bucket.restorationId, 'moving-child'); expect(state.bucket!.restorationId, 'moving-child');
expect(state.bucket, same(bucket)); expect(state.bucket, same(bucket));
expect(state.bucket.read<int>('value'), 11); expect(state.bucket!.read<int>('value'), 11);
expect(rawData[childrenMapKey]['fixed'], isEmpty); expect(rawData[childrenMapKey]['fixed'], isEmpty);
expect(rawData[childrenMapKey].containsKey('moving-child'), isTrue); expect(rawData[childrenMapKey].containsKey('moving-child'), isTrue);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -123,13 +121,13 @@ class TestWidgetWithCounterChildState extends State<TestWidgetWithCounterChild> ...@@ -123,13 +121,13 @@ class TestWidgetWithCounterChildState extends State<TestWidgetWithCounterChild>
int toggleCount = 0; int toggleCount = 0;
@override @override
void didToggleBucket(RestorationBucket oldBucket) { void didToggleBucket(RestorationBucket? oldBucket) {
super.didToggleBucket(oldBucket); super.didToggleBucket(oldBucket);
toggleCount++; toggleCount++;
} }
@override @override
void restoreState(RestorationBucket oldBucket, bool initialRestore) { void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(childRestorationEnabled, 'childRestorationEnabled'); registerForRestoration(childRestorationEnabled, 'childRestorationEnabled');
} }
...@@ -163,7 +161,7 @@ class TestWidgetWithCounterChildState extends State<TestWidgetWithCounterChild> ...@@ -163,7 +161,7 @@ class TestWidgetWithCounterChildState extends State<TestWidgetWithCounterChild>
class Counter extends StatefulWidget { class Counter extends StatefulWidget {
const Counter({this.restorationId}); const Counter({this.restorationId});
final String restorationId; final String? restorationId;
@override @override
State<Counter> createState() => CounterState(); State<Counter> createState() => CounterState();
...@@ -173,10 +171,10 @@ class CounterState extends State<Counter> with RestorationMixin { ...@@ -173,10 +171,10 @@ class CounterState extends State<Counter> with RestorationMixin {
final RestorableInt count = RestorableInt(0); final RestorableInt count = RestorableInt(0);
@override @override
String get restorationId => widget.restorationId; String? get restorationId => widget.restorationId;
@override @override
void restoreState(RestorationBucket oldBucket, bool initialRestore) { void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(count, 'counter'); registerForRestoration(count, 'counter');
} }
...@@ -202,20 +200,20 @@ class CounterState extends State<Counter> with RestorationMixin { ...@@ -202,20 +200,20 @@ class CounterState extends State<Counter> with RestorationMixin {
} }
class TestWidget extends StatefulWidget { class TestWidget extends StatefulWidget {
const TestWidget({@required this.restorationId}); const TestWidget({required this.restorationId});
final String restorationId; final String? restorationId;
@override @override
State<TestWidget> createState() => TestWidgetState(); State<TestWidget> createState() => TestWidgetState();
} }
class TestWidgetState extends State<TestWidget> with RestorationMixin { class TestWidgetState extends State<TestWidget> with RestorationMixin {
List<RestorationBucket> buckets = <RestorationBucket>[]; List<RestorationBucket?> buckets = <RestorationBucket>[];
List<bool> flags = <bool>[]; List<bool> flags = <bool>[];
@override @override
void restoreState(RestorationBucket oldBucket, bool initialRestore) { void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
buckets.add(oldBucket); buckets.add(oldBucket);
flags.add(initialRestore); flags.add(initialRestore);
} }
...@@ -223,13 +221,13 @@ class TestWidgetState extends State<TestWidget> with RestorationMixin { ...@@ -223,13 +221,13 @@ class TestWidgetState extends State<TestWidget> with RestorationMixin {
int toggleCount = 0; int toggleCount = 0;
@override @override
void didToggleBucket(RestorationBucket oldBucket) { void didToggleBucket(RestorationBucket? oldBucket) {
super.didToggleBucket(oldBucket); super.didToggleBucket(oldBucket);
toggleCount++; toggleCount++;
} }
@override @override
String get restorationId => widget.restorationId; String? get restorationId => widget.restorationId;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -44,7 +42,7 @@ void main() { ...@@ -44,7 +42,7 @@ void main() {
expect(binding.restorationManager.rootBucketAccessed, 0); expect(binding.restorationManager.rootBucketAccessed, 0);
final BucketSpyState state = tester.state(find.byType(BucketSpy)); 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(rawData[childrenMapKey].containsKey('root-child'), isTrue);
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
...@@ -82,7 +80,7 @@ void main() { ...@@ -82,7 +80,7 @@ void main() {
expect(binding.firstFrameIsDeferred, isFalse); expect(binding.firstFrameIsDeferred, isFalse);
final BucketSpyState state = tester.state(find.byType(BucketSpy)); 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(rawData[childrenMapKey].containsKey('root-child'), isTrue);
}); });
...@@ -108,7 +106,7 @@ void main() { ...@@ -108,7 +106,7 @@ void main() {
expect(binding.firstFrameIsDeferred, isFalse); expect(binding.firstFrameIsDeferred, isFalse);
final BucketSpyState state = tester.state(find.byType(BucketSpy)); 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(rawData[childrenMapKey].containsKey('root-child'), isTrue);
}); });
...@@ -158,7 +156,7 @@ void main() { ...@@ -158,7 +156,7 @@ void main() {
expect(binding.restorationManager.rootBucketAccessed, 1); expect(binding.restorationManager.rootBucketAccessed, 1);
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
expect(state.bucket.restorationId, 'root-child'); expect(state.bucket!.restorationId, 'root-child');
// Change ID back to null. // Change ID back to null.
await tester.pumpWidget( await tester.pumpWidget(
...@@ -203,7 +201,7 @@ void main() { ...@@ -203,7 +201,7 @@ void main() {
expect(binding.restorationManager.rootBucketAccessed, 0); expect(binding.restorationManager.rootBucketAccessed, 0);
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
final BucketSpyState state = tester.state(find.byType(BucketSpy)); 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); expect(inScopeRawData[childrenMapKey].containsKey('root-child'), isTrue);
// Move out of scope. // Move out of scope.
...@@ -232,7 +230,7 @@ void main() { ...@@ -232,7 +230,7 @@ void main() {
expect(binding.restorationManager.rootBucketAccessed, 1); expect(binding.restorationManager.rootBucketAccessed, 1);
expect(find.text('Hello'), findsOneWidget); 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(outOfScopeRawData[childrenMapKey].containsKey('root-child'), isTrue);
expect(inScopeRawData, isEmpty); expect(inScopeRawData, isEmpty);
...@@ -255,7 +253,7 @@ void main() { ...@@ -255,7 +253,7 @@ void main() {
expect(binding.restorationManager.rootBucketAccessed, 1); expect(binding.restorationManager.rootBucketAccessed, 1);
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
expect(state.bucket.restorationId, 'root-child'); expect(state.bucket!.restorationId, 'root-child');
expect(outOfScopeRawData, isEmpty); expect(outOfScopeRawData, isEmpty);
expect(inScopeRawData[childrenMapKey].containsKey('root-child'), isTrue); expect(inScopeRawData[childrenMapKey].containsKey('root-child'), isTrue);
}); });
...@@ -280,9 +278,9 @@ void main() { ...@@ -280,9 +278,9 @@ void main() {
expect(binding.restorationManager.rootBucketAccessed, 1); expect(binding.restorationManager.rootBucketAccessed, 1);
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
final BucketSpyState state = tester.state(find.byType(BucketSpy)); 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); expect(firstRawData[childrenMapKey]['root-child'][valuesMapKey]['foo'], 42);
final RestorationBucket firstBucket = state.bucket; final RestorationBucket firstBucket = state.bucket!;
// Replace with new root. // Replace with new root.
final Map<String, dynamic> secondRawData = <String, dynamic>{ final Map<String, dynamic> secondRawData = <String, dynamic>{
...@@ -300,7 +298,7 @@ void main() { ...@@ -300,7 +298,7 @@ void main() {
firstRoot.dispose(); firstRoot.dispose();
expect(state.bucket, isNot(same(firstBucket))); expect(state.bucket, isNot(same(firstBucket)));
expect(state.bucket.read<int>('foo'), 22); expect(state.bucket!.read<int>('foo'), 22);
}); });
testWidgets('injects null when rootBucket is null', (WidgetTester tester) async { testWidgets('injects null when rootBucket is null', (WidgetTester tester) async {
...@@ -361,7 +359,7 @@ void main() { ...@@ -361,7 +359,7 @@ void main() {
final BucketSpyState state = tester.state(find.byType(BucketSpy)); final BucketSpyState state = tester.state(find.byType(BucketSpy));
expect(state.bucket, isNotNull); expect(state.bucket, isNotNull);
binding.restorationManager.rootBucket = SynchronousFuture<RestorationBucket>(null); binding.restorationManager.rootBucket = SynchronousFuture<RestorationBucket?>(null);
await tester.pump(); await tester.pump();
root.dispose(); root.dispose();
...@@ -372,7 +370,7 @@ void main() { ...@@ -372,7 +370,7 @@ void main() {
} }
class TestAutomatedTestWidgetsFlutterBinding extends AutomatedTestWidgetsFlutterBinding { class TestAutomatedTestWidgetsFlutterBinding extends AutomatedTestWidgetsFlutterBinding {
MockRestorationManager _restorationManager; late MockRestorationManager _restorationManager;
@override @override
MockRestorationManager get restorationManager => _restorationManager; MockRestorationManager get restorationManager => _restorationManager;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
@TestOn('chrome') @TestOn('chrome')
import 'dart:ui'; import 'dart:ui';
...@@ -14,7 +12,7 @@ import 'package:flutter/material.dart'; ...@@ -14,7 +12,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
class OnTapPage extends StatelessWidget { 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 String id;
final VoidCallback onTap; final VoidCallback onTap;
...@@ -28,7 +26,7 @@ class OnTapPage extends StatelessWidget { ...@@ -28,7 +26,7 @@ class OnTapPage extends StatelessWidget {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
child: Container( child: Container(
child: Center( 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() { ...@@ -271,7 +269,7 @@ void main() {
final SimpleRouterDelegate delegate = SimpleRouterDelegate( final SimpleRouterDelegate delegate = SimpleRouterDelegate(
reportConfiguration: true, reportConfiguration: true,
builder: (BuildContext context, RouteInformation information) { builder: (BuildContext context, RouteInformation information) {
return Text(information.location); return Text(information.location!);
} }
); );
...@@ -323,24 +321,24 @@ class SimpleRouteInformationParser extends RouteInformationParser<RouteInformati ...@@ -323,24 +321,24 @@ class SimpleRouteInformationParser extends RouteInformationParser<RouteInformati
class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeNotifier { class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeNotifier {
SimpleRouterDelegate({ SimpleRouterDelegate({
@required this.builder, required this.builder,
this.onPopRoute, this.onPopRoute,
this.reportConfiguration = false, this.reportConfiguration = false,
}); });
RouteInformation get routeInformation => _routeInformation; RouteInformation get routeInformation => _routeInformation;
RouteInformation _routeInformation; late RouteInformation _routeInformation;
set routeInformation(RouteInformation newValue) { set routeInformation(RouteInformation newValue) {
_routeInformation = newValue; _routeInformation = newValue;
notifyListeners(); notifyListeners();
} }
SimpleRouterDelegateBuilder builder; SimpleRouterDelegateBuilder builder;
SimpleRouterDelegatePopRoute onPopRoute; SimpleRouterDelegatePopRoute? onPopRoute;
final bool reportConfiguration; final bool reportConfiguration;
@override @override
RouteInformation get currentConfiguration { RouteInformation? get currentConfiguration {
if (reportConfiguration) if (reportConfiguration)
return routeInformation; return routeInformation;
return null; return null;
...@@ -355,7 +353,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN ...@@ -355,7 +353,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
@override @override
Future<bool> popRoute() { Future<bool> popRoute() {
if (onPopRoute != null) if (onPopRoute != null)
return onPopRoute(); return onPopRoute!();
return SynchronousFuture<bool>(true); return SynchronousFuture<bool>(true);
} }
...@@ -364,7 +362,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN ...@@ -364,7 +362,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
} }
class TestPage extends Page<void> { class TestPage extends Page<void> {
const TestPage({LocalKey key, String name}) : super(key: key, name: name); const TestPage({LocalKey? key, String? name}) : super(key: key, name: name);
@override @override
Route<void> createRoute(BuildContext context) { Route<void> createRoute(BuildContext context) {
......
This diff is collapsed.
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -26,20 +24,20 @@ void main() { ...@@ -26,20 +24,20 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
const Padding( const Padding(
key: GlobalObjectKey<State<StatefulWidget>>(null), key: GlobalObjectKey<State<StatefulWidget>>(Object()),
padding: EdgeInsets.only(left: 1.0), padding: EdgeInsets.only(left: 1.0),
), ),
); );
await tester.pumpWidget(const Directionality( await tester.pumpWidget(const Directionality(
textDirection: TextDirection.rtl, textDirection: TextDirection.rtl,
child: Padding( child: Padding(
key: GlobalObjectKey<State<StatefulWidget>>(null), key: GlobalObjectKey<State<StatefulWidget>>(Object()),
padding: EdgeInsetsDirectional.only(start: 1.0), padding: EdgeInsetsDirectional.only(start: 1.0),
), ),
)); ));
await tester.pumpWidget( await tester.pumpWidget(
const Padding( const Padding(
key: GlobalObjectKey<State<StatefulWidget>>(null), key: GlobalObjectKey<State<StatefulWidget>>(Object()),
padding: EdgeInsets.only(left: 1.0), padding: EdgeInsets.only(left: 1.0),
), ),
); );
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:fake_async/fake_async.dart'; import 'package:fake_async/fake_async.dart';
...@@ -11,7 +9,7 @@ import 'package:fake_async/fake_async.dart'; ...@@ -11,7 +9,7 @@ import 'package:fake_async/fake_async.dart';
void main() { void main() {
setUp(() { setUp(() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
WidgetsBinding.instance.resetEpoch(); WidgetsBinding.instance!.resetEpoch();
}); });
test('WidgetBinding build rendering tree and warm up frame back to back', () { test('WidgetBinding build rendering tree and warm up frame back to back', () {
...@@ -25,9 +23,9 @@ void main() { ...@@ -25,9 +23,9 @@ void main() {
), ),
); );
// Rendering tree is not built synchronously. // Rendering tree is not built synchronously.
expect(WidgetsBinding.instance.renderViewElement, isNull); expect(WidgetsBinding.instance!.renderViewElement, isNull);
fakeAsync.flushTimers(); fakeAsync.flushTimers();
expect(WidgetsBinding.instance.renderViewElement, isNotNull); expect(WidgetsBinding.instance!.renderViewElement, isNotNull);
}); });
}); });
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -167,7 +165,7 @@ class _PageView62209State extends State<PageView62209> { ...@@ -167,7 +165,7 @@ class _PageView62209State extends State<PageView62209> {
} }
class Carousel62209Page extends StatelessWidget { 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; final int number;
...@@ -178,7 +176,7 @@ class Carousel62209Page extends StatelessWidget { ...@@ -178,7 +176,7 @@ class Carousel62209Page extends StatelessWidget {
} }
class Carousel62209 extends StatefulWidget { 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<Carousel62209Page> pages; final List<Carousel62209Page> pages;
...@@ -188,11 +186,11 @@ class Carousel62209 extends StatefulWidget { ...@@ -188,11 +186,11 @@ class Carousel62209 extends StatefulWidget {
class _Carousel62209State extends State<Carousel62209> { class _Carousel62209State extends State<Carousel62209> {
// page variables // page variables
PageController _pageController; late PageController _pageController;
int _currentPage = 0; int _currentPage = 0;
// controls updates outside of user interaction // controls updates outside of user interaction
List<Carousel62209Page> _pages; late List<Carousel62209Page> _pages;
bool _jumpingToPage = false; bool _jumpingToPage = false;
@override @override
...@@ -216,13 +214,13 @@ class _Carousel62209State extends State<Carousel62209> { ...@@ -216,13 +214,13 @@ class _Carousel62209State extends State<Carousel62209> {
_pages = widget.pages.toList(); _pages = widget.pages.toList();
} else { } else {
_jumpingToPage = true; _jumpingToPage = true;
SchedulerBinding.instance.addPostFrameCallback((_) { SchedulerBinding.instance!.addPostFrameCallback((_) {
if (mounted) { if (mounted) {
setState(() { setState(() {
_pages = widget.pages.toList(); _pages = widget.pages.toList();
_currentPage = newPage; _currentPage = newPage;
_pageController.jumpToPage(_currentPage); _pageController.jumpToPage(_currentPage);
SchedulerBinding.instance.addPostFrameCallback((_) { SchedulerBinding.instance!.addPostFrameCallback((_) {
_jumpingToPage = false; _jumpingToPage = false;
}); });
}); });
...@@ -240,7 +238,7 @@ class _Carousel62209State extends State<Carousel62209> { ...@@ -240,7 +238,7 @@ class _Carousel62209State extends State<Carousel62209> {
bool _handleScrollNotification(ScrollNotification notification) { bool _handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollUpdateNotification) { if (notification is ScrollUpdateNotification) {
final int page = _pageController.page.round(); final int page = _pageController.page!.round();
if (!_jumpingToPage && _currentPage != page) { if (!_jumpingToPage && _currentPage != page) {
_currentPage = page; _currentPage = page;
} }
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
GestureVelocityTrackerBuilder lastCreatedBuilder; late GestureVelocityTrackerBuilder lastCreatedBuilder;
class TestScrollBehavior extends ScrollBehavior { class TestScrollBehavior extends ScrollBehavior {
const TestScrollBehavior(this.flag); const TestScrollBehavior(this.flag);
...@@ -36,15 +34,15 @@ class TestScrollBehavior extends ScrollBehavior { ...@@ -36,15 +34,15 @@ class TestScrollBehavior extends ScrollBehavior {
void main() { void main() {
testWidgets('Inherited ScrollConfiguration changed', (WidgetTester tester) async { testWidgets('Inherited ScrollConfiguration changed', (WidgetTester tester) async {
final GlobalKey key = GlobalKey(debugLabel: 'scrollable'); final GlobalKey key = GlobalKey(debugLabel: 'scrollable');
TestScrollBehavior behavior; TestScrollBehavior? behavior;
ScrollPositionWithSingleContext position; late ScrollPositionWithSingleContext position;
final Widget scrollView = SingleChildScrollView( final Widget scrollView = SingleChildScrollView(
key: key, key: key,
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
behavior = ScrollConfiguration.of(context) as TestScrollBehavior; 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); return Container(height: 1000.0);
}, },
), ),
...@@ -58,7 +56,7 @@ void main() { ...@@ -58,7 +56,7 @@ void main() {
); );
expect(behavior, isNotNull); expect(behavior, isNotNull);
expect(behavior.flag, isTrue); expect(behavior!.flag, isTrue);
expect(position.physics, isA<ClampingScrollPhysics>()); expect(position.physics, isA<ClampingScrollPhysics>());
expect(lastCreatedBuilder(const PointerDownEvent()), isA<VelocityTracker>()); expect(lastCreatedBuilder(const PointerDownEvent()), isA<VelocityTracker>());
ScrollMetrics metrics = position.copyWith(); ScrollMetrics metrics = position.copyWith();
...@@ -74,7 +72,7 @@ void main() { ...@@ -74,7 +72,7 @@ void main() {
); );
expect(behavior, isNotNull); expect(behavior, isNotNull);
expect(behavior.flag, isFalse); expect(behavior!.flag, isFalse);
expect(position.physics, isA<BouncingScrollPhysics>()); expect(position.physics, isA<BouncingScrollPhysics>());
expect(lastCreatedBuilder(const PointerDownEvent()), isA<IOSScrollViewFlingVelocityTracker>()); expect(lastCreatedBuilder(const PointerDownEvent()), isA<IOSScrollViewFlingVelocityTracker>());
// Regression test for https://github.com/flutter/flutter/issues/5856 // Regression test for https://github.com/flutter/flutter/issues/5856
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,15 +2,12 @@ ...@@ -2,15 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
Widget _buildScroller({ List<String> log }) { Widget _buildScroller({ required List<String> log }) {
return NotificationListener<ScrollNotification>( return NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) { onNotification: (ScrollNotification notification) {
if (notification is ScrollStartNotification) { if (notification is ScrollStartNotification) {
...@@ -29,7 +26,7 @@ Widget _buildScroller({ List<String> log }) { ...@@ -29,7 +26,7 @@ Widget _buildScroller({ List<String> log }) {
} }
void main() { void main() {
Completer<void> animateTo(WidgetTester tester, double newScrollOffset, { @required Duration duration }) { Completer<void> animateTo(WidgetTester tester, double newScrollOffset, { required Duration duration }) {
final Completer<void> completer = Completer<void>(); final Completer<void> completer = Completer<void>();
final ScrollableState scrollable = tester.state(find.byType(Scrollable)); final ScrollableState scrollable = tester.state(find.byType(Scrollable));
scrollable.position.animateTo(newScrollOffset, duration: duration, curve: Curves.linear).whenComplete(completer.complete); scrollable.position.animateTo(newScrollOffset, duration: duration, curve: Curves.linear).whenComplete(completer.complete);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -11,7 +9,7 @@ import 'package:flutter/widgets.dart'; ...@@ -11,7 +9,7 @@ import 'package:flutter/widgets.dart';
void main() { void main() {
testWidgets('Scroll notification basics', (WidgetTester tester) async { testWidgets('Scroll notification basics', (WidgetTester tester) async {
ScrollNotification notification; late ScrollNotification notification;
await tester.pumpWidget(NotificationListener<ScrollNotification>( await tester.pumpWidget(NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) { onNotification: (ScrollNotification value) {
...@@ -30,7 +28,7 @@ void main() { ...@@ -30,7 +28,7 @@ void main() {
expect(notification.depth, equals(0)); expect(notification.depth, equals(0));
final ScrollStartNotification start = notification as ScrollStartNotification; final ScrollStartNotification start = notification as ScrollStartNotification;
expect(start.dragDetails, isNotNull); 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 gesture.moveBy(const Offset(-10.0, -10.0));
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
...@@ -38,8 +36,8 @@ void main() { ...@@ -38,8 +36,8 @@ void main() {
expect(notification.depth, equals(0)); expect(notification.depth, equals(0));
final ScrollUpdateNotification update = notification as ScrollUpdateNotification; final ScrollUpdateNotification update = notification as ScrollUpdateNotification;
expect(update.dragDetails, isNotNull); expect(update.dragDetails, isNotNull);
expect(update.dragDetails.globalPosition, equals(const Offset(90.0, 90.0))); 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!.delta, equals(const Offset(0.0, -10.0)));
await gesture.up(); await gesture.up();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
...@@ -47,7 +45,7 @@ void main() { ...@@ -47,7 +45,7 @@ void main() {
expect(notification.depth, equals(0)); expect(notification.depth, equals(0));
final ScrollEndNotification end = notification as ScrollEndNotification; final ScrollEndNotification end = notification as ScrollEndNotification;
expect(end.dragDetails, isNotNull); 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 { testWidgets('Scroll notification depth', (WidgetTester tester) async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -12,20 +10,20 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -12,20 +10,20 @@ import 'package:flutter_test/flutter_test.dart';
class TestScrollPhysics extends ScrollPhysics { class TestScrollPhysics extends ScrollPhysics {
const TestScrollPhysics({ const TestScrollPhysics({
this.name, required this.name,
ScrollPhysics parent ScrollPhysics? parent
}) : super(parent: parent); }) : super(parent: parent);
final String name; final String name;
@override @override
TestScrollPhysics applyTo(ScrollPhysics ancestor) { TestScrollPhysics applyTo(ScrollPhysics? ancestor) {
return TestScrollPhysics( return TestScrollPhysics(
name: name, 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}'; String get names => parent == null ? name : '$name ${namedParent.names}';
@override @override
...@@ -69,7 +67,7 @@ void main() { ...@@ -69,7 +67,7 @@ void main() {
const ScrollPhysics always = AlwaysScrollableScrollPhysics(); const ScrollPhysics always = AlwaysScrollableScrollPhysics();
const ScrollPhysics page = PageScrollPhysics(); 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( expect(
types(bounce.applyTo(clamp.applyTo(never.applyTo(always.applyTo(page))))), types(bounce.applyTo(clamp.applyTo(never.applyTo(always.applyTo(page))))),
...@@ -112,13 +110,13 @@ void main() { ...@@ -112,13 +110,13 @@ void main() {
// Calls to createBallisticSimulation may happen on every frame (i.e. when the maxScrollExtent changes) // 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 // Changing velocity for time 0 may cause a sudden, unwanted damping/speedup effect
expect(bounce.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(clamp.createBallisticSimulation(position, 1000)!.dx(0), moreOrLessEquals(1000));
expect(page.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000)); expect(page.createBallisticSimulation(position, 1000)!.dx(0), moreOrLessEquals(1000));
}); });
group('BouncingScrollPhysics test', () { group('BouncingScrollPhysics test', () {
BouncingScrollPhysics physicsUnderTest; late BouncingScrollPhysics physicsUnderTest;
setUp(() { setUp(() {
physicsUnderTest = const BouncingScrollPhysics(); physicsUnderTest = const BouncingScrollPhysics();
...@@ -253,7 +251,7 @@ void main() { ...@@ -253,7 +251,7 @@ void main() {
axisDirection: AxisDirection.down, axisDirection: AxisDirection.down,
); );
expect(position.pixels, pixels); expect(position.pixels, pixels);
FlutterError error; late FlutterError error;
try { try {
physics.applyBoundaryConditions(position, pixels); physics.applyBoundaryConditions(position, pixels);
} on FlutterError catch (e) { } on FlutterError catch (e) {
......
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:ui'; import 'dart:ui';
import 'package:meta/meta.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -16,8 +13,8 @@ ScrollController _controller = ScrollController( ...@@ -16,8 +13,8 @@ ScrollController _controller = ScrollController(
class ThePositiveNumbers extends StatelessWidget { class ThePositiveNumbers extends StatelessWidget {
const ThePositiveNumbers({ const ThePositiveNumbers({
Key key, Key? key,
@required this.from, required this.from,
}) : super(key: key); }) : super(key: key);
final int from; final int from;
@override @override
...@@ -93,7 +90,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async { ...@@ -93,7 +90,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
expect(find.text('16'), findsNothing, reason: 'with maintainState: $maintainState'); expect(find.text('16'), findsNothing, reason: 'with maintainState: $maintainState');
expect(find.text('100'), 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(); // navigating always takes two frames, one to start...
await tester.pump(const Duration(seconds: 1)); // ...and one to end the transition await tester.pump(const Duration(seconds: 1)); // ...and one to end the transition
...@@ -114,7 +111,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async { ...@@ -114,7 +111,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
expect(find.text('10010'), findsNothing, reason: 'with maintainState: $maintainState'); expect(find.text('10010'), findsNothing, reason: 'with maintainState: $maintainState');
expect(find.text('10100'), 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 await tester.pump(); // again, navigating always takes two frames
// Ensure we don't clamp the scroll offset even during the navigation. // Ensure we don't clamp the scroll offset even during the navigation.
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
...@@ -71,10 +69,10 @@ void main() { ...@@ -71,10 +69,10 @@ void main() {
final double targetPosition = controller.position.pixels + doubleTolerance; final double targetPosition = controller.position.pixels + doubleTolerance;
controller.position.animateTo(targetPosition, duration: const Duration(seconds: 10), curve: Curves.linear); 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() { void expectNoAnimation() {
expect(SchedulerBinding.instance.transientCallbackCount, equals(0), reason: 'Expected no animation.'); expect(SchedulerBinding.instance!.transientCallbackCount, equals(0), reason: 'Expected no animation.');
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart' show DragStartBehavior; import 'package:flutter/gestures.dart' show DragStartBehavior;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
class ScrollPositionListener extends StatefulWidget { 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 Widget child;
final ValueChanged<String> log; final ValueChanged<String> log;
...@@ -18,7 +16,7 @@ class ScrollPositionListener extends StatefulWidget { ...@@ -18,7 +16,7 @@ class ScrollPositionListener extends StatefulWidget {
} }
class _ScrollPositionListenerState extends State<ScrollPositionListener> { class _ScrollPositionListenerState extends State<ScrollPositionListener> {
ScrollPosition _position; ScrollPosition? _position;
@override @override
void didChangeDependencies() { void didChangeDependencies() {
...@@ -26,7 +24,7 @@ class _ScrollPositionListenerState extends State<ScrollPositionListener> { ...@@ -26,7 +24,7 @@ class _ScrollPositionListenerState extends State<ScrollPositionListener> {
_position?.removeListener(listener); _position?.removeListener(listener);
_position = Scrollable.of(context)?.position; _position = Scrollable.of(context)?.position;
_position?.addListener(listener); _position?.addListener(listener);
widget.log('didChangeDependencies ${_position?.pixels?.toStringAsFixed(1)}'); widget.log('didChangeDependencies ${_position?.pixels.toStringAsFixed(1)}');
} }
@override @override
...@@ -39,20 +37,20 @@ class _ScrollPositionListenerState extends State<ScrollPositionListener> { ...@@ -39,20 +37,20 @@ class _ScrollPositionListenerState extends State<ScrollPositionListener> {
Widget build(BuildContext context) => widget.child; Widget build(BuildContext context) => widget.child;
void listener() { void listener() {
widget.log('listener ${_position?.pixels?.toStringAsFixed(1)}'); widget.log('listener ${_position?.pixels.toStringAsFixed(1)}');
} }
} }
void main() { void main() {
testWidgets('Scrollable.of() dependent rebuilds when Scrollable position changes', (WidgetTester tester) async { testWidgets('Scrollable.of() dependent rebuilds when Scrollable position changes', (WidgetTester tester) async {
String logValue; late String logValue;
final ScrollController controller = ScrollController(); final ScrollController controller = ScrollController();
// Changing the SingleChildScrollView's physics causes the // Changing the SingleChildScrollView's physics causes the
// ScrollController's ScrollPosition to be rebuilt. // ScrollController's ScrollPosition to be rebuilt.
Widget buildFrame(ScrollPhysics physics) { Widget buildFrame(ScrollPhysics? physics) {
return SingleChildScrollView( return SingleChildScrollView(
controller: controller, controller: controller,
physics: physics, physics: physics,
...@@ -86,7 +84,7 @@ void main() { ...@@ -86,7 +84,7 @@ void main() {
}); });
testWidgets('Scrollable.of() is possible using ScrollNotification context', (WidgetTester tester) async { testWidgets('Scrollable.of() is possible using ScrollNotification context', (WidgetTester tester) async {
ScrollNotification notification; late ScrollNotification notification;
await tester.pumpWidget(NotificationListener<ScrollNotification>( await tester.pumpWidget(NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification value) { onNotification: (ScrollNotification value) {
...@@ -102,6 +100,6 @@ void main() { ...@@ -102,6 +100,6 @@ void main() {
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
final StatefulElement scrollableElement = find.byType(Scrollable).evaluate().first as StatefulElement; 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));
}); });
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -397,20 +395,20 @@ void main() { ...@@ -397,20 +395,20 @@ void main() {
), ),
); );
expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry.paintExtent, 150); expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry!.paintExtent, 150);
expect(find.text('Tile 0'), findsOneWidget); expect(find.text('Tile 0'), findsOneWidget);
expect(find.text('Tile 10'), findsNothing); expect(find.text('Tile 10'), findsNothing);
await tester.drag(find.byType(ListView), const Offset(0, -500)); await tester.drag(find.byType(ListView), const Offset(0, -500));
await tester.pump(); await tester.pump();
expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry.paintExtent, 56); expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry!.paintExtent, 56);
expect(find.text('Tile 0'), findsNothing); expect(find.text('Tile 0'), findsNothing);
expect(find.text('Tile 10'), findsOneWidget); expect(find.text('Tile 10'), findsOneWidget);
await tester.restartAndRestore(); await tester.restartAndRestore();
expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry.paintExtent, 56); expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry!.paintExtent, 56);
expect(find.text('Tile 0'), findsNothing); expect(find.text('Tile 0'), findsNothing);
expect(find.text('Tile 10'), findsOneWidget); expect(find.text('Tile 10'), findsOneWidget);
...@@ -418,13 +416,13 @@ void main() { ...@@ -418,13 +416,13 @@ void main() {
await tester.drag(find.byType(ListView), const Offset(0, 600)); await tester.drag(find.byType(ListView), const Offset(0, 600));
await tester.pump(); await tester.pump();
expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry.paintExtent, 150); expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry!.paintExtent, 150);
expect(find.text('Tile 0'), findsOneWidget); expect(find.text('Tile 0'), findsOneWidget);
expect(find.text('Tile 10'), findsNothing); expect(find.text('Tile 10'), findsNothing);
await tester.restoreFrom(data); await tester.restoreFrom(data);
expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry.paintExtent, 56); expect(tester.renderObject<RenderSliver>(find.byType(SliverAppBar)).geometry!.paintExtent, 56);
expect(find.text('Tile 0'), findsNothing); expect(find.text('Tile 0'), findsNothing);
expect(find.text('Tile 10'), findsOneWidget); expect(find.text('Tile 10'), findsOneWidget);
}); });
...@@ -552,7 +550,7 @@ Future<void> restoreScrollAndVerify(WidgetTester tester, {double secondOffset = ...@@ -552,7 +550,7 @@ Future<void> restoreScrollAndVerify(WidgetTester tester, {double secondOffset =
} }
class TestHarness extends StatelessWidget { 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 Widget child;
final double height; final double height;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment