Unverified Commit d127f2c9 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix nullability for some routing related stuff (#67675)

parent 4042eb97
...@@ -2225,7 +2225,7 @@ class FollowerLayer extends ContainerLayer { ...@@ -2225,7 +2225,7 @@ class FollowerLayer extends ContainerLayer {
Matrix4? _invertedTransform; Matrix4? _invertedTransform;
bool _inverseDirty = true; bool _inverseDirty = true;
Offset? _transformOffset<S extends Object>(Offset localPosition) { Offset? _transformOffset(Offset localPosition) {
if (_inverseDirty) { if (_inverseDirty) {
_invertedTransform = Matrix4.tryInvert(getLastTransform()!); _invertedTransform = Matrix4.tryInvert(getLastTransform()!);
_inverseDirty = false; _inverseDirty = false;
...@@ -2245,7 +2245,7 @@ class FollowerLayer extends ContainerLayer { ...@@ -2245,7 +2245,7 @@ class FollowerLayer extends ContainerLayer {
} }
return false; return false;
} }
final Offset? transformedOffset = _transformOffset<S>(localPosition); final Offset? transformedOffset = _transformOffset(localPosition);
if (transformedOffset == null) { if (transformedOffset == null) {
return false; return false;
} }
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +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.
import 'dart:io'; import 'dart:io';
import 'dart:ui'; import 'dart:ui';
...@@ -737,7 +736,7 @@ class RawKeyboard { ...@@ -737,7 +736,7 @@ class RawKeyboard {
} }
@immutable @immutable
class _ModifierSidePair extends Object { class _ModifierSidePair {
const _ModifierSidePair(this.modifier, this.side); const _ModifierSidePair(this.modifier, this.side);
final ModifierKey modifier; final ModifierKey modifier;
......
...@@ -131,7 +131,6 @@ class Draggable<T extends Object> extends StatefulWidget { ...@@ -131,7 +131,6 @@ class Draggable<T extends Object> extends StatefulWidget {
assert(maxSimultaneousDrags == null || maxSimultaneousDrags >= 0), assert(maxSimultaneousDrags == null || maxSimultaneousDrags >= 0),
super(key: key); super(key: key);
/// The data that will be dropped by this draggable. /// The data that will be dropped by this draggable.
final T? data; final T? data;
......
...@@ -881,7 +881,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T ...@@ -881,7 +881,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
/// The given [BuildContext] will be rebuilt if the state of the route changes /// The given [BuildContext] will be rebuilt if the state of the route changes
/// while it is visible (specifically, if [isCurrent] or [canPop] change value). /// while it is visible (specifically, if [isCurrent] or [canPop] change value).
@optionalTypeArgs @optionalTypeArgs
static ModalRoute<T>? of<T extends Object>(BuildContext context) { static ModalRoute<T>? of<T extends Object?>(BuildContext context) {
final _ModalScopeStatus? widget = context.dependOnInheritedWidgetOfExactType<_ModalScopeStatus>(); final _ModalScopeStatus? widget = context.dependOnInheritedWidgetOfExactType<_ModalScopeStatus>();
return widget?.route as ModalRoute<T>?; return widget?.route as ModalRoute<T>?;
} }
...@@ -1818,7 +1818,7 @@ class _DialogRoute<T> extends PopupRoute<T> { ...@@ -1818,7 +1818,7 @@ class _DialogRoute<T> extends PopupRoute<T> {
/// ///
/// * [showDialog], which displays a Material-style dialog. /// * [showDialog], which displays a Material-style dialog.
/// * [showCupertinoDialog], which displays an iOS-style dialog. /// * [showCupertinoDialog], which displays an iOS-style dialog.
Future<T> showGeneralDialog<T extends Object>({ Future<T> showGeneralDialog<T extends Object?>({
required BuildContext context, required BuildContext context,
required RoutePageBuilder pageBuilder, required RoutePageBuilder pageBuilder,
bool barrierDismissible = false, bool barrierDismissible = false,
......
...@@ -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:collection'; import 'dart:collection';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -19,7 +17,7 @@ final List<String> results = <String>[]; ...@@ -19,7 +17,7 @@ final List<String> results = <String>[];
Set<TestRoute> routes = HashSet<TestRoute>(); Set<TestRoute> routes = HashSet<TestRoute>();
class TestRoute extends Route<String> with LocalHistoryRoute<String> { class TestRoute extends Route<String?> with LocalHistoryRoute<String?> {
TestRoute(this.name); TestRoute(this.name);
final String name; final String name;
...@@ -57,7 +55,7 @@ class TestRoute extends Route<String> with LocalHistoryRoute<String> { ...@@ -57,7 +55,7 @@ class TestRoute extends Route<String> with LocalHistoryRoute<String> {
} }
@override @override
void didReplace(Route<dynamic> oldRoute) { void didReplace(Route<dynamic>? oldRoute) {
expect(oldRoute, isA<TestRoute>()); expect(oldRoute, isA<TestRoute>());
final TestRoute castRoute = oldRoute as TestRoute; final TestRoute castRoute = oldRoute as TestRoute;
log('didReplace ${castRoute.name}'); log('didReplace ${castRoute.name}');
...@@ -65,11 +63,11 @@ class TestRoute extends Route<String> with LocalHistoryRoute<String> { ...@@ -65,11 +63,11 @@ class TestRoute extends Route<String> with LocalHistoryRoute<String> {
} }
@override @override
bool didPop(String result) { bool didPop(String? result) {
log('didPop $result'); log('didPop $result');
bool returnValue; bool returnValue;
if (returnValue = super.didPop(result)) if (returnValue = super.didPop(result))
navigator.finalizeRoute(this); navigator!.finalizeRoute(this);
return returnValue; return returnValue;
} }
...@@ -82,9 +80,9 @@ class TestRoute extends Route<String> with LocalHistoryRoute<String> { ...@@ -82,9 +80,9 @@ class TestRoute extends Route<String> with LocalHistoryRoute<String> {
} }
@override @override
void didChangeNext(Route<dynamic> nextRoute) { void didChangeNext(Route<dynamic>? nextRoute) {
expect(nextRoute, anyOf(isNull, isA<TestRoute>())); expect(nextRoute, anyOf(isNull, isA<TestRoute>()));
final TestRoute castRoute = nextRoute as TestRoute; final TestRoute? castRoute = nextRoute as TestRoute?;
log('didChangeNext ${castRoute?.name}'); log('didChangeNext ${castRoute?.name}');
super.didChangeNext(castRoute); super.didChangeNext(castRoute);
} }
...@@ -148,7 +146,7 @@ void main() { ...@@ -148,7 +146,7 @@ void main() {
), ),
), ),
); );
final NavigatorState host = navigatorKey.currentState; final NavigatorState host = navigatorKey.currentState!;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -159,7 +157,7 @@ void main() { ...@@ -159,7 +157,7 @@ void main() {
'initial: didChangeNext null', 'initial: didChangeNext null',
], ],
); );
TestRoute second; late TestRoute second;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -231,7 +229,7 @@ void main() { ...@@ -231,7 +229,7 @@ void main() {
), ),
), ),
); );
final NavigatorState host = navigatorKey.currentState; final NavigatorState host = navigatorKey.currentState!;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -242,7 +240,7 @@ void main() { ...@@ -242,7 +240,7 @@ void main() {
'first: didChangeNext null', 'first: didChangeNext null',
], ],
); );
TestRoute second; late TestRoute second;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -294,7 +292,7 @@ void main() { ...@@ -294,7 +292,7 @@ void main() {
'second: didChangeNext three', 'second: didChangeNext three',
], ],
); );
TestRoute four; late TestRoute four;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -342,7 +340,7 @@ void main() { ...@@ -342,7 +340,7 @@ void main() {
), ),
), ),
); );
final NavigatorState host = navigatorKey.currentState; final NavigatorState host = navigatorKey.currentState!;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -364,7 +362,7 @@ void main() { ...@@ -364,7 +362,7 @@ void main() {
'A: didChangeNext B', 'A: didChangeNext B',
], ],
); );
TestRoute routeC; late TestRoute routeC;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -377,7 +375,7 @@ void main() { ...@@ -377,7 +375,7 @@ void main() {
], ],
); );
expect(routeC.isActive, isTrue); expect(routeC.isActive, isTrue);
TestRoute routeB; late TestRoute routeB;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -424,7 +422,7 @@ void main() { ...@@ -424,7 +422,7 @@ void main() {
), ),
), ),
); );
final NavigatorState host = navigatorKey.currentState; final NavigatorState host = navigatorKey.currentState!;
await runNavigatorTest( await runNavigatorTest(
tester, tester,
host, host,
...@@ -552,7 +550,7 @@ void main() { ...@@ -552,7 +550,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
PageRouteBuilder<void>( PageRouteBuilder<void>(
settings: settings, settings: settings,
pageBuilder: (BuildContext context, Animation<double> input, Animation<double> out) { pageBuilder: (BuildContext context, Animation<double> input, Animation<double> out) {
...@@ -601,7 +599,7 @@ void main() { ...@@ -601,7 +599,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
PageRouteBuilder<void>( PageRouteBuilder<void>(
settings: settings, settings: settings,
pageBuilder: (BuildContext context, Animation<double> input, Animation<double> out) { pageBuilder: (BuildContext context, Animation<double> input, Animation<double> out) {
...@@ -656,9 +654,9 @@ void main() { ...@@ -656,9 +654,9 @@ void main() {
); );
// Push page one, its secondary animation is kAlwaysDismissedAnimation. // Push page one, its secondary animation is kAlwaysDismissedAnimation.
ProxyAnimation secondaryAnimationProxyPageOne; late ProxyAnimation secondaryAnimationProxyPageOne;
ProxyAnimation animationPageOne; late ProxyAnimation animationPageOne;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation; secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation;
...@@ -675,9 +673,9 @@ void main() { ...@@ -675,9 +673,9 @@ void main() {
// Push page two, the secondary animation of page one is the primary // Push page two, the secondary animation of page one is the primary
// animation of page two. // animation of page two.
ProxyAnimation secondaryAnimationProxyPageTwo; late ProxyAnimation secondaryAnimationProxyPageTwo;
ProxyAnimation animationPageTwo; late ProxyAnimation animationPageTwo;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
secondaryAnimationProxyPageTwo = secondaryAnimation as ProxyAnimation; secondaryAnimationProxyPageTwo = secondaryAnimation as ProxyAnimation;
...@@ -695,7 +693,7 @@ void main() { ...@@ -695,7 +693,7 @@ void main() {
// Pop page two, the secondary animation of page one becomes // Pop page two, the secondary animation of page one becomes
// kAlwaysDismissedAnimation. // kAlwaysDismissedAnimation.
navigator.currentState.pop(); navigator.currentState!.pop();
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
expect(secondaryAnimationPageOne.parent, animationPageTwo.parent); expect(secondaryAnimationPageOne.parent, animationPageTwo.parent);
...@@ -714,9 +712,9 @@ void main() { ...@@ -714,9 +712,9 @@ void main() {
); );
// Push page one, its secondary animation is kAlwaysDismissedAnimation. // Push page one, its secondary animation is kAlwaysDismissedAnimation.
ProxyAnimation secondaryAnimationProxyPageOne; late ProxyAnimation secondaryAnimationProxyPageOne;
ProxyAnimation animationPageOne; late ProxyAnimation animationPageOne;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation; secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation;
...@@ -733,10 +731,10 @@ void main() { ...@@ -733,10 +731,10 @@ void main() {
// Push page two, the secondary animation of page one is the primary // Push page two, the secondary animation of page one is the primary
// animation of page two. // animation of page two.
ProxyAnimation secondaryAnimationProxyPageTwo; late ProxyAnimation secondaryAnimationProxyPageTwo;
ProxyAnimation animationPageTwo; late ProxyAnimation animationPageTwo;
Route<void> secondRoute; Route<void> secondRoute;
navigator.currentState.push( navigator.currentState!.push(
secondRoute = PageRouteBuilder<void>( secondRoute = PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
secondaryAnimationProxyPageTwo = secondaryAnimation as ProxyAnimation; secondaryAnimationProxyPageTwo = secondaryAnimation as ProxyAnimation;
...@@ -754,7 +752,7 @@ void main() { ...@@ -754,7 +752,7 @@ void main() {
// Remove the second route, the secondary animation of page one is // Remove the second route, the secondary animation of page one is
// kAlwaysDismissedAnimation again. // kAlwaysDismissedAnimation again.
navigator.currentState.removeRoute(secondRoute); navigator.currentState!.removeRoute(secondRoute);
await tester.pump(); await tester.pump();
expect(secondaryAnimationPageOne.parent, kAlwaysDismissedAnimation); expect(secondaryAnimationPageOne.parent, kAlwaysDismissedAnimation);
}); });
...@@ -769,9 +767,9 @@ void main() { ...@@ -769,9 +767,9 @@ void main() {
); );
// Push page one, its secondary animation is kAlwaysDismissedAnimation. // Push page one, its secondary animation is kAlwaysDismissedAnimation.
ProxyAnimation secondaryAnimationProxyPageOne; late ProxyAnimation secondaryAnimationProxyPageOne;
ProxyAnimation animationPageOne; late ProxyAnimation animationPageOne;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation; secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation;
...@@ -788,8 +786,8 @@ void main() { ...@@ -788,8 +786,8 @@ void main() {
// Push page two, the secondary animation of page one is the primary // Push page two, the secondary animation of page one is the primary
// animation of page two. // animation of page two.
ProxyAnimation animationPageTwo; late ProxyAnimation animationPageTwo;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
animationPageTwo = animation as ProxyAnimation; animationPageTwo = animation as ProxyAnimation;
...@@ -803,8 +801,8 @@ void main() { ...@@ -803,8 +801,8 @@ void main() {
// Replace with a different route while push is ongoing to trigger // Replace with a different route while push is ongoing to trigger
// TrainHopping. // TrainHopping.
ProxyAnimation animationPageThree; late ProxyAnimation animationPageThree;
navigator.currentState.pushReplacement( navigator.currentState!.pushReplacement(
TestPageRouteBuilder( TestPageRouteBuilder(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
animationPageThree = animation as ProxyAnimation; animationPageThree = animation as ProxyAnimation;
...@@ -825,7 +823,7 @@ void main() { ...@@ -825,7 +823,7 @@ void main() {
expect(secondaryAnimationPageOne.parent, animationPageThree.parent); expect(secondaryAnimationPageOne.parent, animationPageThree.parent);
// Pop page three. // Pop page three.
navigator.currentState.pop(); navigator.currentState!.pop();
await tester.pump(); await tester.pump();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(secondaryAnimationPageOne.parent, kAlwaysDismissedAnimation); expect(secondaryAnimationPageOne.parent, kAlwaysDismissedAnimation);
...@@ -841,9 +839,9 @@ void main() { ...@@ -841,9 +839,9 @@ void main() {
); );
// Push page one, its secondary animation is kAlwaysDismissedAnimation. // Push page one, its secondary animation is kAlwaysDismissedAnimation.
ProxyAnimation secondaryAnimationProxyPageOne; late ProxyAnimation secondaryAnimationProxyPageOne;
ProxyAnimation animationPageOne; late ProxyAnimation animationPageOne;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation; secondaryAnimationProxyPageOne = secondaryAnimation as ProxyAnimation;
...@@ -860,8 +858,8 @@ void main() { ...@@ -860,8 +858,8 @@ void main() {
// Push page two, the secondary animation of page one is the primary // Push page two, the secondary animation of page one is the primary
// animation of page two. // animation of page two.
ProxyAnimation animationPageTwo; late ProxyAnimation animationPageTwo;
navigator.currentState.push( navigator.currentState!.push(
PageRouteBuilder<void>( PageRouteBuilder<void>(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
animationPageTwo = animation as ProxyAnimation; animationPageTwo = animation as ProxyAnimation;
...@@ -875,7 +873,7 @@ void main() { ...@@ -875,7 +873,7 @@ void main() {
// Replace with a different route while push is ongoing to trigger // Replace with a different route while push is ongoing to trigger
// TrainHopping. // TrainHopping.
navigator.currentState.pushReplacement( navigator.currentState!.pushReplacement(
TestPageRouteBuilder( TestPageRouteBuilder(
pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (_, Animation<double> animation, Animation<double> secondaryAnimation) {
return const Text('Page Three'); return const Text('Page Three');
...@@ -889,7 +887,7 @@ void main() { ...@@ -889,7 +887,7 @@ void main() {
expect(trainHopper.currentTrain, animationPageTwo.parent); expect(trainHopper.currentTrain, animationPageTwo.parent);
// Pop page three while replacement push is ongoing. // Pop page three while replacement push is ongoing.
navigator.currentState.pop(); navigator.currentState!.pop();
await tester.pump(); await tester.pump();
expect(secondaryAnimationPageOne.parent, isA<TrainHoppingAnimation>()); expect(secondaryAnimationPageOne.parent, isA<TrainHoppingAnimation>());
final TrainHoppingAnimation trainHopper2 = secondaryAnimationPageOne.parent as TrainHoppingAnimation; final TrainHoppingAnimation trainHopper2 = secondaryAnimationPageOne.parent as TrainHoppingAnimation;
...@@ -902,8 +900,8 @@ void main() { ...@@ -902,8 +900,8 @@ void main() {
testWidgets('secondary animation is triggered when pop initial route', (WidgetTester tester) async { testWidgets('secondary animation is triggered when pop initial route', (WidgetTester tester) async {
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
Animation<double> secondaryAnimationOfRouteOne; late Animation<double> secondaryAnimationOfRouteOne;
Animation<double> primaryAnimationOfRouteTwo; late Animation<double> primaryAnimationOfRouteTwo;
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
navigatorKey: navigator, navigatorKey: navigator,
...@@ -927,7 +925,7 @@ void main() { ...@@ -927,7 +925,7 @@ void main() {
expect(secondaryAnimationOfRouteOne.value, 1.0); expect(secondaryAnimationOfRouteOne.value, 1.0);
expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo.value); expect(secondaryAnimationOfRouteOne.value, primaryAnimationOfRouteTwo.value);
// Pops the top most route and verifies two routes are still chained. // Pops the top most route and verifies two routes are still chained.
navigator.currentState.pop(); navigator.currentState!.pop();
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 30)); await tester.pump(const Duration(milliseconds: 30));
expect(secondaryAnimationOfRouteOne.value, 0.9); expect(secondaryAnimationOfRouteOne.value, 0.9);
...@@ -1127,7 +1125,7 @@ void main() { ...@@ -1127,7 +1125,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext innerContext) { builder: (BuildContext innerContext) {
return Container( return Container(
...@@ -1177,7 +1175,7 @@ void main() { ...@@ -1177,7 +1175,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
ModifiedReverseTransitionDurationRoute<void>( ModifiedReverseTransitionDurationRoute<void>(
builder: (BuildContext innerContext) { builder: (BuildContext innerContext) {
return Container( return Container(
...@@ -1236,7 +1234,7 @@ void main() { ...@@ -1236,7 +1234,7 @@ void main() {
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
ModifiedReverseTransitionDurationRoute<void>( ModifiedReverseTransitionDurationRoute<void>(
builder: (BuildContext innerContext) { builder: (BuildContext innerContext) {
return Container( return Container(
...@@ -1298,7 +1296,7 @@ void main() { ...@@ -1298,7 +1296,7 @@ void main() {
child: ElevatedButton( child: ElevatedButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
_TestDialogRouteWithCustomBarrierCurve<void>( _TestDialogRouteWithCustomBarrierCurve<void>(
child: const Text('Hello World'), child: const Text('Hello World'),
) )
...@@ -1360,7 +1358,7 @@ void main() { ...@@ -1360,7 +1358,7 @@ void main() {
child: ElevatedButton( child: ElevatedButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
_TestDialogRouteWithCustomBarrierCurve<void>( _TestDialogRouteWithCustomBarrierCurve<void>(
child: const Text('Hello World'), child: const Text('Hello World'),
barrierCurve: Curves.linear, barrierCurve: Curves.linear,
...@@ -1425,7 +1423,7 @@ void main() { ...@@ -1425,7 +1423,7 @@ void main() {
child: ElevatedButton( child: ElevatedButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context).push<void>( Navigator.of(context)!.push<void>(
_TestDialogRouteWithCustomBarrierCurve<void>( _TestDialogRouteWithCustomBarrierCurve<void>(
child: const Text('Hello World'), child: const Text('Hello World'),
barrierLabel: 'test label', barrierLabel: 'test label',
...@@ -1499,7 +1497,7 @@ void main() { ...@@ -1499,7 +1497,7 @@ void main() {
expect(focusNodeOnPageOne.hasFocus, isTrue); expect(focusNodeOnPageOne.hasFocus, isTrue);
// Pushes one page. // Pushes one page.
navigatorKey.currentState.push<void>( navigatorKey.currentState!.push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) => const Text('dummy2'), builder: (BuildContext context) => const Text('dummy2'),
) )
...@@ -1513,7 +1511,7 @@ void main() { ...@@ -1513,7 +1511,7 @@ void main() {
expect(focusNodeOnPageTwo.hasFocus, isTrue); expect(focusNodeOnPageTwo.hasFocus, isTrue);
// Pushes another page. // Pushes another page.
navigatorKey.currentState.push<void>( navigatorKey.currentState!.push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) => const Text('dummy3'), builder: (BuildContext context) => const Text('dummy3'),
) )
...@@ -1527,7 +1525,7 @@ void main() { ...@@ -1527,7 +1525,7 @@ void main() {
expect(focusNodeOnPageThree.hasFocus, isTrue); expect(focusNodeOnPageThree.hasFocus, isTrue);
// Pops two pages simultaneously. // Pops two pages simultaneously.
navigatorKey.currentState.popUntil((Route<void> route) => route.isFirst); navigatorKey.currentState!.popUntil((Route<void> route) => route.isFirst);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// It should refocus page one after pops. // It should refocus page one after pops.
expect(focusNodeOnPageOne.hasFocus, isTrue); expect(focusNodeOnPageOne.hasFocus, isTrue);
...@@ -1545,7 +1543,7 @@ void main() { ...@@ -1545,7 +1543,7 @@ void main() {
expect(focusNodeOnPageOne.hasFocus, isTrue); expect(focusNodeOnPageOne.hasFocus, isTrue);
// Pushes one page. // Pushes one page.
navigatorKey.currentState.push<void>( navigatorKey.currentState!.push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) => const Material(child: TextField()), builder: (BuildContext context) => const Material(child: TextField()),
) )
...@@ -1565,7 +1563,7 @@ void main() { ...@@ -1565,7 +1563,7 @@ void main() {
expect(focusNodeOnPageTwo.hasPrimaryFocus, isFalse); expect(focusNodeOnPageTwo.hasPrimaryFocus, isFalse);
// Pushes another page. // Pushes another page.
navigatorKey.currentState.push<void>( navigatorKey.currentState!.push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) => const Text('dummy3'), builder: (BuildContext context) => const Text('dummy3'),
) )
...@@ -1579,7 +1577,7 @@ void main() { ...@@ -1579,7 +1577,7 @@ void main() {
expect(focusNodeOnPageThree.hasFocus, isTrue); expect(focusNodeOnPageThree.hasFocus, isTrue);
// Pops two pages simultaneously. // Pops two pages simultaneously.
navigatorKey.currentState.popUntil((Route<void> route) => route.isFirst); navigatorKey.currentState!.popUntil((Route<void> route) => route.isFirst);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// It should refocus page one after pops. // It should refocus page one after pops.
expect(focusNodeOnPageOne.hasFocus, isTrue); expect(focusNodeOnPageOne.hasFocus, isTrue);
...@@ -1629,6 +1627,28 @@ void main() { ...@@ -1629,6 +1627,28 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('dialog1'), findsNothing); expect(find.text('dialog1'), findsNothing);
}); });
testWidgets('ModalRoute.of works for void routes', (WidgetTester tester) async {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(MaterialApp(
navigatorKey: navigatorKey,
home: const Text('home'),
));
expect(find.text('page2'), findsNothing);
navigatorKey.currentState!.push<void>(MaterialPageRoute<void>(
builder: (BuildContext context) {
return const Text('page2');
}
));
await tester.pumpAndSettle();
expect(find.text('page2'), findsOneWidget);
final ModalRoute<void>? parentRoute = ModalRoute.of<void>(tester.element(find.text('page2')));
expect(parentRoute, isNotNull);
expect(parentRoute, isA<MaterialPageRoute<void>>());
});
} }
double _getOpacity(GlobalKey key, WidgetTester tester) { double _getOpacity(GlobalKey key, WidgetTester tester) {
...@@ -1644,9 +1664,9 @@ double _getOpacity(GlobalKey key, WidgetTester tester) { ...@@ -1644,9 +1664,9 @@ double _getOpacity(GlobalKey key, WidgetTester tester) {
class ModifiedReverseTransitionDurationRoute<T> extends MaterialPageRoute<T> { class ModifiedReverseTransitionDurationRoute<T> extends MaterialPageRoute<T> {
ModifiedReverseTransitionDurationRoute({ ModifiedReverseTransitionDurationRoute({
@required WidgetBuilder builder, required WidgetBuilder builder,
RouteSettings settings, RouteSettings? settings,
this.reverseTransitionDuration, required this.reverseTransitionDuration,
bool fullscreenDialog = false, bool fullscreenDialog = false,
}) : super( }) : super(
builder: builder, builder: builder,
...@@ -1690,7 +1710,7 @@ class MockRouteAware extends Fake implements RouteAware { ...@@ -1690,7 +1710,7 @@ class MockRouteAware extends Fake implements RouteAware {
} }
class TestPageRouteBuilder extends PageRouteBuilder<void> { class TestPageRouteBuilder extends PageRouteBuilder<void> {
TestPageRouteBuilder({RoutePageBuilder pageBuilder}) : super(pageBuilder: pageBuilder); TestPageRouteBuilder({required RoutePageBuilder pageBuilder}) : super(pageBuilder: pageBuilder);
@override @override
Animation<double> createAnimation() { Animation<double> createAnimation() {
...@@ -1703,7 +1723,7 @@ class DialogObserver extends NavigatorObserver { ...@@ -1703,7 +1723,7 @@ class DialogObserver extends NavigatorObserver {
int dialogCount = 0; int dialogCount = 0;
@override @override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (route.toString().contains('_DialogRoute')) { if (route.toString().contains('_DialogRoute')) {
dialogRoutes.add(route as ModalRoute<dynamic>); dialogRoutes.add(route as ModalRoute<dynamic>);
dialogCount++; dialogCount++;
...@@ -1712,7 +1732,7 @@ class DialogObserver extends NavigatorObserver { ...@@ -1712,7 +1732,7 @@ class DialogObserver extends NavigatorObserver {
} }
@override @override
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) { void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
if (route.toString().contains('_DialogRoute')) { if (route.toString().contains('_DialogRoute')) {
dialogRoutes.removeLast(); dialogRoutes.removeLast();
dialogCount--; dialogCount--;
...@@ -1723,9 +1743,9 @@ class DialogObserver extends NavigatorObserver { ...@@ -1723,9 +1743,9 @@ class DialogObserver extends NavigatorObserver {
class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> { class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> {
_TestDialogRouteWithCustomBarrierCurve({ _TestDialogRouteWithCustomBarrierCurve({
@required Widget child, required Widget child,
this.barrierLabel, this.barrierLabel,
Curve barrierCurve, Curve? barrierCurve,
}) : _barrierCurve = barrierCurve, }) : _barrierCurve = barrierCurve,
_child = child; _child = child;
...@@ -1735,7 +1755,7 @@ class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> { ...@@ -1735,7 +1755,7 @@ class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> {
bool get barrierDismissible => true; bool get barrierDismissible => true;
@override @override
final String barrierLabel; final String? barrierLabel;
@override @override
Color get barrierColor => Colors.black; // easier value to test against Color get barrierColor => Colors.black; // easier value to test against
...@@ -1745,9 +1765,9 @@ class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> { ...@@ -1745,9 +1765,9 @@ class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> {
if (_barrierCurve == null) { if (_barrierCurve == null) {
return super.barrierCurve; return super.barrierCurve;
} }
return _barrierCurve; return _barrierCurve!;
} }
final Curve _barrierCurve; final Curve? _barrierCurve;
@override @override
Duration get transitionDuration => const Duration(milliseconds: 100); // easier value to test against Duration get transitionDuration => const Duration(milliseconds: 100); // easier value to test against
...@@ -1768,10 +1788,10 @@ class WidgetWithLocalHistory extends StatefulWidget { ...@@ -1768,10 +1788,10 @@ class WidgetWithLocalHistory extends StatefulWidget {
} }
class WidgetWithLocalHistoryState extends State<WidgetWithLocalHistory> { class WidgetWithLocalHistoryState extends State<WidgetWithLocalHistory> {
LocalHistoryEntry _localHistory; late LocalHistoryEntry _localHistory;
void addLocalHistory() { void addLocalHistory() {
final ModalRoute<dynamic> route = ModalRoute.of(context); final ModalRoute<dynamic> route = ModalRoute.of(context)!;
_localHistory = LocalHistoryEntry(); _localHistory = LocalHistoryEntry();
route.addLocalHistoryEntry(_localHistory); route.addLocalHistoryEntry(_localHistory);
} }
...@@ -1792,9 +1812,9 @@ class TransitionDetector extends DefaultTransitionDelegate<void> { ...@@ -1792,9 +1812,9 @@ class TransitionDetector extends DefaultTransitionDelegate<void> {
bool hasTransition = false; bool hasTransition = false;
@override @override
Iterable<RouteTransitionRecord> resolve({ Iterable<RouteTransitionRecord> resolve({
List<RouteTransitionRecord> newPageRouteHistory, required List<RouteTransitionRecord> newPageRouteHistory,
Map<RouteTransitionRecord, RouteTransitionRecord> locationToExitingPageRoute, required Map<RouteTransitionRecord?, RouteTransitionRecord> locationToExitingPageRoute,
Map<RouteTransitionRecord, List<RouteTransitionRecord>> pageRouteToPagelessRoutes required Map<RouteTransitionRecord?, List<RouteTransitionRecord>> pageRouteToPagelessRoutes
}) { }) {
hasTransition = true; hasTransition = true;
return super.resolve( return super.resolve(
...@@ -1806,13 +1826,13 @@ class TransitionDetector extends DefaultTransitionDelegate<void> { ...@@ -1806,13 +1826,13 @@ class TransitionDetector extends DefaultTransitionDelegate<void> {
} }
Widget buildNavigator({ Widget buildNavigator({
List<Page<dynamic>> pages, required List<Page<dynamic>> pages,
PopPageCallback onPopPage, required PopPageCallback onPopPage,
GlobalKey<NavigatorState> key, GlobalKey<NavigatorState>? key,
TransitionDelegate<dynamic> transitionDelegate TransitionDelegate<dynamic>? transitionDelegate
}) { }) {
return MediaQuery( return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window), data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window),
child: Localizations( child: Localizations(
locale: const Locale('en', 'US'), locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[ delegates: const <LocalizationsDelegate<dynamic>>[
......
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