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 @@
// 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<int>('foo'), 22);
expect(state.bucket!.restorationId, 'child1');
expect(state.bucket!.read<int>('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<int>('foo'), 22);
final RestorationBucket bucket = state.bucket;
expect(state.bucket!.restorationId, 'child1');
expect(state.bucket!.read<int>('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<int>('foo'), 22);
expect(state.bucket!.restorationId, 'something else');
expect(state.bucket!.read<int>('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<int>('value'), 11);
expect(state.bucket!.read<int>('value'), 11);
expect(rawData[childrenMapKey]['fixed'], isEmpty);
expect(rawData[childrenMapKey].containsKey('moving-child'), isTrue);
......
......@@ -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<TestWidgetWithCounterChild>
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<TestWidgetWithCounterChild>
class Counter extends StatefulWidget {
const Counter({this.restorationId});
final String restorationId;
final String? restorationId;
@override
State<Counter> createState() => CounterState();
......@@ -173,10 +171,10 @@ class CounterState extends State<Counter> 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<Counter> with RestorationMixin {
}
class TestWidget extends StatefulWidget {
const TestWidget({@required this.restorationId});
const TestWidget({required this.restorationId});
final String restorationId;
final String? restorationId;
@override
State<TestWidget> createState() => TestWidgetState();
}
class TestWidgetState extends State<TestWidget> with RestorationMixin {
List<RestorationBucket> buckets = <RestorationBucket>[];
List<RestorationBucket?> buckets = <RestorationBucket>[];
List<bool> flags = <bool>[];
@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<TestWidget> 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) {
......
......@@ -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<String, dynamic> secondRawData = <String, dynamic>{
......@@ -300,7 +298,7 @@ void main() {
firstRoot.dispose();
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 {
......@@ -361,7 +359,7 @@ void main() {
final BucketSpyState state = tester.state(find.byType(BucketSpy));
expect(state.bucket, isNotNull);
binding.restorationManager.rootBucket = SynchronousFuture<RestorationBucket>(null);
binding.restorationManager.rootBucket = SynchronousFuture<RestorationBucket?>(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;
......
......@@ -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';
......
......@@ -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<RouteInformati
class SimpleRouterDelegate extends RouterDelegate<RouteInformation> 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<RouteInformation> with ChangeN
@override
Future<bool> popRoute() {
if (onPopRoute != null)
return onPopRoute();
return onPopRoute!();
return SynchronousFuture<bool>(true);
}
......@@ -364,7 +362,7 @@ class SimpleRouterDelegate extends RouterDelegate<RouteInformation> with ChangeN
}
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
Route<void> createRoute(BuildContext context) {
......
This diff is collapsed.
......@@ -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<State<StatefulWidget>>(null),
key: GlobalObjectKey<State<StatefulWidget>>(Object()),
padding: EdgeInsets.only(left: 1.0),
),
);
await tester.pumpWidget(const Directionality(
textDirection: TextDirection.rtl,
child: Padding(
key: GlobalObjectKey<State<StatefulWidget>>(null),
key: GlobalObjectKey<State<StatefulWidget>>(Object()),
padding: EdgeInsetsDirectional.only(start: 1.0),
),
));
await tester.pumpWidget(
const Padding(
key: GlobalObjectKey<State<StatefulWidget>>(null),
key: GlobalObjectKey<State<StatefulWidget>>(Object()),
padding: EdgeInsets.only(left: 1.0),
),
);
......
......@@ -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);
});
});
}
......@@ -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';
......
......@@ -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';
......
......@@ -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<PageView62209> {
}
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<Carousel62209Page> pages;
......@@ -188,11 +186,11 @@ class Carousel62209 extends StatefulWidget {
class _Carousel62209State extends State<Carousel62209> {
// page variables
PageController _pageController;
late PageController _pageController;
int _currentPage = 0;
// controls updates outside of user interaction
List<Carousel62209Page> _pages;
late List<Carousel62209Page> _pages;
bool _jumpingToPage = false;
@override
......@@ -216,13 +214,13 @@ class _Carousel62209State extends State<Carousel62209> {
_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<Carousel62209> {
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;
}
......
......@@ -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<ClampingScrollPhysics>());
expect(lastCreatedBuilder(const PointerDownEvent()), isA<VelocityTracker>());
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<BouncingScrollPhysics>());
expect(lastCreatedBuilder(const PointerDownEvent()), isA<IOSScrollViewFlingVelocityTracker>());
// Regression test for https://github.com/flutter/flutter/issues/5856
......
......@@ -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';
......
......@@ -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<String> log }) {
Widget _buildScroller({ required List<String> log }) {
return NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) {
if (notification is ScrollStartNotification) {
......@@ -29,7 +26,7 @@ Widget _buildScroller({ List<String> log }) {
}
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 ScrollableState scrollable = tester.state(find.byType(Scrollable));
scrollable.position.animateTo(newScrollOffset, duration: duration, curve: Curves.linear).whenComplete(completer.complete);
......
......@@ -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';
......
......@@ -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<ScrollNotification>(
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 {
......
......@@ -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) {
......
......@@ -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<void> 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<void> 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.
......
......@@ -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';
......
......@@ -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.');
}
......@@ -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';
......
......@@ -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;
......
......@@ -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';
......
......@@ -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';
......
......@@ -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';
......
......@@ -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<String> log;
......@@ -18,7 +16,7 @@ class ScrollPositionListener extends StatefulWidget {
}
class _ScrollPositionListenerState extends State<ScrollPositionListener> {
ScrollPosition _position;
ScrollPosition? _position;
@override
void didChangeDependencies() {
......@@ -26,7 +24,7 @@ class _ScrollPositionListenerState extends State<ScrollPositionListener> {
_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<ScrollPositionListener> {
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<ScrollNotification>(
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));
});
}
......@@ -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<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 10'), findsNothing);
await tester.drag(find.byType(ListView), const Offset(0, -500));
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 10'), findsOneWidget);
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 10'), findsOneWidget);
......@@ -418,13 +416,13 @@ void main() {
await tester.drag(find.byType(ListView), const Offset(0, 600));
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 10'), findsNothing);
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 10'), findsOneWidget);
});
......@@ -552,7 +550,7 @@ Future<void> 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;
......
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