Unverified Commit de884f1a authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Remove the `nullOk` parameter from `Navigator.of` and add `Navigator.maybeOf` (#70726)

Adds Navigator.maybeOf to replace calling Navigator.of(context, nullOk: true), and removes the nullOk parameter. Also changes Navigator.of to return a non-nullable value, and removes many (120!) instances of the ! operator, reducing the possible places where a null dereference could occur.
parent 05dadb01
...@@ -117,7 +117,7 @@ class ExitButton extends StatelessWidget { ...@@ -117,7 +117,7 @@ class ExitButton extends StatelessWidget {
), ),
onPressed: () { onPressed: () {
// The demo is on the root navigator. // The demo is on the root navigator.
Navigator.of(context, rootNavigator: true)!.pop(); Navigator.of(context, rootNavigator: true).pop();
}, },
); );
} }
...@@ -202,7 +202,7 @@ class Tab1RowItem extends StatelessWidget { ...@@ -202,7 +202,7 @@ class Tab1RowItem extends StatelessWidget {
final Widget row = GestureDetector( final Widget row = GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
Navigator.of(context)!.push(CupertinoPageRoute<void>( Navigator.of(context).push(CupertinoPageRoute<void>(
title: colorName, title: colorName,
builder: (BuildContext context) => Tab1ItemPage( builder: (BuildContext context) => Tab1ItemPage(
color: color, color: color,
...@@ -752,7 +752,7 @@ class CupertinoDemoTab3 extends StatelessWidget { ...@@ -752,7 +752,7 @@ class CupertinoDemoTab3 extends StatelessWidget {
const Padding(padding: EdgeInsets.only(top: 32.0)), const Padding(padding: EdgeInsets.only(top: 32.0)),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
Navigator.of(context, rootNavigator: true)!.push( Navigator.of(context, rootNavigator: true).push(
CupertinoPageRoute<bool>( CupertinoPageRoute<bool>(
fullscreenDialog: true, fullscreenDialog: true,
builder: (BuildContext context) => Tab3Dialog(), builder: (BuildContext context) => Tab3Dialog(),
...@@ -800,7 +800,7 @@ class Tab3Dialog extends StatelessWidget { ...@@ -800,7 +800,7 @@ class Tab3Dialog extends StatelessWidget {
child: const Text('Cancel'), child: const Text('Cancel'),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(false); Navigator.of(context).pop(false);
}, },
), ),
), ),
......
...@@ -126,13 +126,13 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> { ...@@ -126,13 +126,13 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
TextButton( TextButton(
child: const Text('CANCEL'), child: const Text('CANCEL'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(false); // Pops the confirmation dialog but not the page. Navigator.of(context).pop(false); // Pops the confirmation dialog but not the page.
}, },
), ),
TextButton( TextButton(
child: const Text('DISCARD'), child: const Text('DISCARD'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(true); // Returning true to _onWillPop will pop again. Navigator.of(context).pop(true); // Returning true to _onWillPop will pop again.
}, },
), ),
], ],
......
...@@ -98,7 +98,7 @@ class _SearchDemoState extends State<SearchDemo> { ...@@ -98,7 +98,7 @@ class _SearchDemoState extends State<SearchDemo> {
floatingActionButton: FloatingActionButton.extended( floatingActionButton: FloatingActionButton.extended(
tooltip: 'Back', // Tests depend on this label to exit the demo. tooltip: 'Back', // Tests depend on this label to exit the demo.
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
label: const Text('Close demo'), label: const Text('Close demo'),
icon: const Icon(Icons.close), icon: const Icon(Icons.close),
......
...@@ -151,11 +151,11 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> { ...@@ -151,11 +151,11 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
actions: <Widget> [ actions: <Widget> [
TextButton( TextButton(
child: const Text('YES'), child: const Text('YES'),
onPressed: () { Navigator.of(context)!.pop(true); }, onPressed: () { Navigator.of(context).pop(true); },
), ),
TextButton( TextButton(
child: const Text('NO'), child: const Text('NO'),
onPressed: () { Navigator.of(context)!.pop(false); }, onPressed: () { Navigator.of(context).pop(false); },
), ),
], ],
); );
......
...@@ -35,7 +35,7 @@ class _LoginPageState extends State<LoginPage> { ...@@ -35,7 +35,7 @@ class _LoginPageState extends State<LoginPage> {
// The login screen is immediately displayed on top of the Shrine // The login screen is immediately displayed on top of the Shrine
// home screen using onGenerateRoute and so rootNavigator must be // home screen using onGenerateRoute and so rootNavigator must be
// set to true in order to get out of Shrine completely. // set to true in order to get out of Shrine completely.
Navigator.of(context, rootNavigator: true)!.pop(); Navigator.of(context, rootNavigator: true).pop();
}, },
), ),
), ),
...@@ -95,7 +95,7 @@ class _LoginPageState extends State<LoginPage> { ...@@ -95,7 +95,7 @@ class _LoginPageState extends State<LoginPage> {
// the Shrine home screen using onGenerateRoute and so // the Shrine home screen using onGenerateRoute and so
// rootNavigator must be set to true in order to get out // rootNavigator must be set to true in order to get out
// of Shrine completely. // of Shrine completely.
Navigator.of(context, rootNavigator: true)!.pop(); Navigator.of(context, rootNavigator: true).pop();
}, },
child: const Text('CANCEL'), child: const Text('CANCEL'),
), ),
......
...@@ -107,7 +107,7 @@ class _TransformationsDemoState extends State<TransformationsDemo> { ...@@ -107,7 +107,7 @@ class _TransformationsDemoState extends State<TransformationsDemo> {
TextButton( TextButton(
child: const Text('OK'), child: const Text('OK'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
), ),
], ],
......
...@@ -70,7 +70,7 @@ class VideoCard extends StatelessWidget { ...@@ -70,7 +70,7 @@ class VideoCard extends StatelessWidget {
}); });
controller!.setVolume(1.0); controller!.setVolume(1.0);
Navigator.of(context)!.push(route); Navigator.of(context).push(route);
} }
return SafeArea( return SafeArea(
......
...@@ -292,7 +292,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker ...@@ -292,7 +292,7 @@ class _CupertinoContextMenuState extends State<CupertinoContextMenu> with Ticker
return widget.previewBuilder!(context, animation, widget.child); return widget.previewBuilder!(context, animation, widget.child);
}, },
); );
Navigator.of(context, rootNavigator: true)!.push<void>(_route!); Navigator.of(context, rootNavigator: true).push<void>(_route!);
_route!.animation!.addStatusListener(_routeAnimationStatusListener); _route!.animation!.addStatusListener(_routeAnimationStatusListener);
} }
...@@ -686,7 +686,7 @@ class _ContextMenuRoute<T> extends PopupRoute<T> { ...@@ -686,7 +686,7 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
parent: animation!, parent: animation!,
curve: const Interval(0.9, 1.0), curve: const Interval(0.9, 1.0),
)); ));
Navigator.of(context)!.pop(); Navigator.of(context).pop();
} }
// Take measurements on the child and _ContextMenuSheet and update the // Take measurements on the child and _ContextMenuSheet and update the
......
...@@ -1060,7 +1060,7 @@ Future<T?> showCupertinoModalPopup<T>({ ...@@ -1060,7 +1060,7 @@ Future<T?> showCupertinoModalPopup<T>({
RouteSettings? routeSettings, RouteSettings? routeSettings,
}) { }) {
assert(useRootNavigator != null); assert(useRootNavigator != null);
return Navigator.of(context, rootNavigator: useRootNavigator)!.push( return Navigator.of(context, rootNavigator: useRootNavigator).push(
_CupertinoModalPopupRoute<T>( _CupertinoModalPopupRoute<T>(
barrierColor: CupertinoDynamicColor.resolve(barrierColor, context), barrierColor: CupertinoDynamicColor.resolve(barrierColor, context),
barrierDismissible: barrierDismissible, barrierDismissible: barrierDismissible,
......
...@@ -292,7 +292,7 @@ void showLicensePage({ ...@@ -292,7 +292,7 @@ void showLicensePage({
}) { }) {
assert(context != null); assert(context != null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
Navigator.of(context, rootNavigator: useRootNavigator)!.push(MaterialPageRoute<void>( Navigator.of(context, rootNavigator: useRootNavigator).push(MaterialPageRoute<void>(
builder: (BuildContext context) => LicensePage( builder: (BuildContext context) => LicensePage(
applicationName: applicationName, applicationName: applicationName,
applicationVersion: applicationVersion, applicationVersion: applicationVersion,
...@@ -1342,8 +1342,8 @@ class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOp ...@@ -1342,8 +1342,8 @@ class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOp
? widget.masterPageBuilder!(c, false) ? widget.masterPageBuilder!(c, false)
: _MasterPage( : _MasterPage(
leading: widget.leading ?? leading: widget.leading ??
(widget.automaticallyImplyLeading && Navigator.of(context)!.canPop() (widget.automaticallyImplyLeading && Navigator.of(context).canPop()
? BackButton(onPressed: () => Navigator.of(context)!.pop()) ? BackButton(onPressed: () => Navigator.of(context).pop())
: null), : null),
title: widget.title, title: widget.title,
centerTitle: widget.centerTitle, centerTitle: widget.centerTitle,
...@@ -1364,7 +1364,7 @@ class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOp ...@@ -1364,7 +1364,7 @@ class _MasterDetailFlowState extends State<_MasterDetailFlow> implements _PageOp
onWillPop: () async { onWillPop: () async {
// No need for setState() as rebuild happens on navigation pop. // No need for setState() as rebuild happens on navigation pop.
focus = _Focus.master; focus = _Focus.master;
Navigator.of(context)!.pop(); Navigator.of(context).pop();
return false; return false;
}, },
child: BlockSemantics(child: widget.detailPageBuilder(context, arguments, null)), child: BlockSemantics(child: widget.detailPageBuilder(context, arguments, null)),
......
...@@ -669,7 +669,7 @@ Future<T?> showModalBottomSheet<T>({ ...@@ -669,7 +669,7 @@ Future<T?> showModalBottomSheet<T>({
assert(debugCheckHasMediaQuery(context)); assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator)!; final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator);
return navigator.push(_ModalBottomSheetRoute<T>( return navigator.push(_ModalBottomSheetRoute<T>(
builder: builder, builder: builder,
capturedThemes: InheritedTheme.capture(from: context, to: navigator.context), capturedThemes: InheritedTheme.capture(from: context, to: navigator.context),
......
...@@ -978,7 +978,7 @@ Future<T?> showDialog<T>({ ...@@ -978,7 +978,7 @@ Future<T?> showDialog<T>({
assert(useRootNavigator != null); assert(useRootNavigator != null);
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
final CapturedThemes themes = InheritedTheme.capture(from: context, to: Navigator.of(context, rootNavigator: useRootNavigator)!.context); final CapturedThemes themes = InheritedTheme.capture(from: context, to: Navigator.of(context, rootNavigator: useRootNavigator).context);
return showGeneralDialog( return showGeneralDialog(
context: context, context: context,
pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) { pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
......
...@@ -1206,7 +1206,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -1206,7 +1206,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
) )
]; ];
final NavigatorState navigator = Navigator.of(context)!; final NavigatorState navigator = Navigator.of(context);
assert(_dropdownRoute == null); assert(_dropdownRoute == null);
_dropdownRoute = _DropdownRoute<T>( _dropdownRoute = _DropdownRoute<T>(
items: menuItems, items: menuItems,
......
...@@ -842,7 +842,7 @@ Future<T?> showMenu<T>({ ...@@ -842,7 +842,7 @@ Future<T?> showMenu<T>({
semanticLabel ??= MaterialLocalizations.of(context).popupMenuLabel; semanticLabel ??= MaterialLocalizations.of(context).popupMenuLabel;
} }
final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator)!; final NavigatorState navigator = Navigator.of(context, rootNavigator: useRootNavigator);
return navigator.push(_PopupMenuRoute<T>( return navigator.push(_PopupMenuRoute<T>(
position: position, position: position,
items: items, items: items,
...@@ -1060,7 +1060,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> { ...@@ -1060,7 +1060,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
void showButtonMenu() { void showButtonMenu() {
final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
final RenderBox button = context.findRenderObject()! as RenderBox; final RenderBox button = context.findRenderObject()! as RenderBox;
final RenderBox overlay = Navigator.of(context)!.overlay!.context.findRenderObject()! as RenderBox; final RenderBox overlay = Navigator.of(context).overlay!.context.findRenderObject()! as RenderBox;
final RelativeRect position = RelativeRect.fromRect( final RelativeRect position = RelativeRect.fromRect(
Rect.fromPoints( Rect.fromPoints(
button.localToGlobal(widget.offset, ancestor: overlay), button.localToGlobal(widget.offset, ancestor: overlay),
......
...@@ -60,7 +60,7 @@ Future<T?> showSearch<T>({ ...@@ -60,7 +60,7 @@ Future<T?> showSearch<T>({
assert(context != null); assert(context != null);
delegate.query = query ?? delegate.query; delegate.query = query ?? delegate.query;
delegate._currentBody = _SearchBody.suggestions; delegate._currentBody = _SearchBody.suggestions;
return Navigator.of(context)!.push(_SearchPageRoute<T>( return Navigator.of(context).push(_SearchPageRoute<T>(
delegate: delegate, delegate: delegate,
)); ));
} }
...@@ -294,7 +294,7 @@ abstract class SearchDelegate<T> { ...@@ -294,7 +294,7 @@ abstract class SearchDelegate<T> {
void close(BuildContext context, T result) { void close(BuildContext context, T result) {
_currentBody = null; _currentBody = null;
_focusNode?.unfocus(); _focusNode?.unfocus();
Navigator.of(context)! Navigator.of(context)
..popUntil((Route<dynamic> route) => route == _route) ..popUntil((Route<dynamic> route) => route == _route)
..pop(result); ..pop(result);
} }
......
...@@ -664,7 +664,7 @@ class _DismissModalAction extends DismissAction { ...@@ -664,7 +664,7 @@ class _DismissModalAction extends DismissAction {
@override @override
Object invoke(DismissIntent intent) { Object invoke(DismissIntent intent) {
return Navigator.of(context)!.maybePop(); return Navigator.of(context).maybePop();
} }
} }
...@@ -1849,7 +1849,7 @@ Future<T?> showGeneralDialog<T extends Object?>({ ...@@ -1849,7 +1849,7 @@ Future<T?> showGeneralDialog<T extends Object?>({
assert(pageBuilder != null); assert(pageBuilder != null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
assert(!barrierDismissible || barrierLabel != null); assert(!barrierDismissible || barrierLabel != null);
return Navigator.of(context, rootNavigator: useRootNavigator)!.push<T>(_DialogRoute<T>( return Navigator.of(context, rootNavigator: useRootNavigator).push<T>(_DialogRoute<T>(
pageBuilder: pageBuilder, pageBuilder: pageBuilder,
barrierDismissible: barrierDismissible, barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel, barrierLabel: barrierLabel,
......
...@@ -1652,7 +1652,7 @@ void main() { ...@@ -1652,7 +1652,7 @@ void main() {
return RaisedButton( return RaisedButton(
child: const Text('Home'), child: const Text('Home'),
onPressed: () { onPressed: () {
navigator = Navigator.of(context)!; navigator = Navigator.of(context);
assert(navigator != null); assert(navigator != null);
navigator.push<void>(r); navigator.push<void>(r);
}, },
......
...@@ -322,7 +322,7 @@ void main() { ...@@ -322,7 +322,7 @@ void main() {
child: CupertinoButton( child: CupertinoButton(
child: const Text('Next'), child: const Text('Next'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push( Navigator.of(context).push(
CupertinoPageRoute<void>( CupertinoPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
...@@ -333,7 +333,7 @@ void main() { ...@@ -333,7 +333,7 @@ void main() {
child: CupertinoButton( child: CupertinoButton(
child: const Text('Back'), child: const Text('Back'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
), ),
), ),
......
...@@ -40,7 +40,7 @@ void main() { ...@@ -40,7 +40,7 @@ void main() {
return CupertinoButton( return CupertinoButton(
child: const Text('go to second page'), child: const Text('go to second page'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pushNamed('/2'); Navigator.of(context).pushNamed('/2');
}, },
); );
}, },
...@@ -131,7 +131,7 @@ void main() { ...@@ -131,7 +131,7 @@ void main() {
return CupertinoButton( return CupertinoButton(
child: const Text('go to second page'), child: const Text('go to second page'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pushNamed('/2'); Navigator.of(context).pushNamed('/2');
}, },
); );
}, },
...@@ -156,7 +156,7 @@ void main() { ...@@ -156,7 +156,7 @@ void main() {
return CupertinoButton( return CupertinoButton(
child: const Text('go to second page'), child: const Text('go to second page'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pushNamed('/2'); Navigator.of(context).pushNamed('/2');
}, },
); );
}, },
...@@ -245,7 +245,7 @@ void main() { ...@@ -245,7 +245,7 @@ void main() {
builder: (BuildContext context) => CupertinoButton( builder: (BuildContext context) => CupertinoButton(
child: const Text('home'), child: const Text('home'),
onPressed: () { onPressed: () {
Navigator.of(context)!.restorablePushNamed('/2'); Navigator.of(context).restorablePushNamed('/2');
}, },
), ),
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
...@@ -269,7 +269,7 @@ void main() { ...@@ -269,7 +269,7 @@ void main() {
expect(find.text('home'), findsNothing); expect(find.text('home'), findsNothing);
expect(find.text('second route'), findsOneWidget); expect(find.text('second route'), findsOneWidget);
Navigator.of(tester.element(find.text('second route')))!.pop(); Navigator.of(tester.element(find.text('second route'))).pop();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('home'), findsOneWidget); expect(find.text('home'), findsOneWidget);
...@@ -280,7 +280,7 @@ void main() { ...@@ -280,7 +280,7 @@ void main() {
expect(find.text('home'), findsNothing); expect(find.text('home'), findsNothing);
expect(find.text('second route'), findsOneWidget); expect(find.text('second route'), findsOneWidget);
Navigator.of(tester.element(find.text('second route')))!.pop(); Navigator.of(tester.element(find.text('second route'))).pop();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('home'), findsOneWidget); expect(find.text('home'), findsOneWidget);
......
...@@ -100,7 +100,7 @@ void main() { ...@@ -100,7 +100,7 @@ void main() {
return Material( return Material(
child: ElevatedButton( child: ElevatedButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { Navigator.of(context)!.pushNamed('/next'); }, onPressed: () { Navigator.of(context).pushNamed('/next'); },
), ),
); );
} }
...@@ -258,7 +258,7 @@ void main() { ...@@ -258,7 +258,7 @@ void main() {
child: ElevatedButton( child: ElevatedButton(
child: const Text('X'), child: const Text('X'),
onPressed: () async { onPressed: () async {
result = Navigator.of(context)!.pushNamed<Object?>('/a'); result = Navigator.of(context).pushNamed<Object?>('/a');
}, },
), ),
); );
...@@ -270,7 +270,7 @@ void main() { ...@@ -270,7 +270,7 @@ void main() {
child: ElevatedButton( child: ElevatedButton(
child: const Text('Y'), child: const Text('Y'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pop('all done'); Navigator.of(context).pop('all done');
}, },
), ),
); );
......
...@@ -1813,7 +1813,7 @@ void main() { ...@@ -1813,7 +1813,7 @@ void main() {
SimpleDialogOption( SimpleDialogOption(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
), ),
], ],
......
...@@ -41,7 +41,7 @@ void main() { ...@@ -41,7 +41,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The primaryBox will see the default Theme when built. // The primaryBox will see the default Theme when built.
builder: (BuildContext _) => primaryBox, builder: (BuildContext _) => primaryBox,
...@@ -52,7 +52,7 @@ void main() { ...@@ -52,7 +52,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow Theme. // Capture the shadow Theme.
builder: (BuildContext _) => InheritedTheme.captureAll(context, primaryBox), builder: (BuildContext _) => InheritedTheme.captureAll(context, primaryBox),
...@@ -84,7 +84,7 @@ void main() { ...@@ -84,7 +84,7 @@ void main() {
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
expect(containerColor(), primaryColor); expect(containerColor(), primaryColor);
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
// Show the route which contains primaryBox // Show the route which contains primaryBox
...@@ -181,7 +181,7 @@ void main() { ...@@ -181,7 +181,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The Banner will see the default BannerTheme when built. // The Banner will see the default BannerTheme when built.
builder: (BuildContext _) => banner, builder: (BuildContext _) => banner,
...@@ -192,7 +192,7 @@ void main() { ...@@ -192,7 +192,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow BannerTheme. // Capture the shadow BannerTheme.
builder: (BuildContext _) => InheritedTheme.captureAll(context, banner), builder: (BuildContext _) => InheritedTheme.captureAll(context, banner),
...@@ -234,7 +234,7 @@ void main() { ...@@ -234,7 +234,7 @@ void main() {
expect(getTextStyle('hello').fontSize, bannerFontSize); expect(getTextStyle('hello').fontSize, bannerFontSize);
expect(getTextStyle('hello').color, bannerTextColor); expect(getTextStyle('hello').color, bannerTextColor);
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
...@@ -271,7 +271,7 @@ void main() { ...@@ -271,7 +271,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The Banner will see the default BannerTheme when built. // The Banner will see the default BannerTheme when built.
builder: (BuildContext _) => divider, builder: (BuildContext _) => divider,
...@@ -282,7 +282,7 @@ void main() { ...@@ -282,7 +282,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow BannerTheme. // Capture the shadow BannerTheme.
builder: (BuildContext _) => InheritedTheme.captureAll(context, divider), builder: (BuildContext _) => InheritedTheme.captureAll(context, divider),
...@@ -316,7 +316,7 @@ void main() { ...@@ -316,7 +316,7 @@ void main() {
expect(dividerBorder().color, dividerColor); expect(dividerBorder().color, dividerColor);
expect(dividerBorder().width, dividerThickness); expect(dividerBorder().width, dividerThickness);
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
...@@ -375,7 +375,7 @@ void main() { ...@@ -375,7 +375,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The Banner will see the default BannerTheme when built. // The Banner will see the default BannerTheme when built.
builder: (BuildContext _) => listTiles, builder: (BuildContext _) => listTiles,
...@@ -386,7 +386,7 @@ void main() { ...@@ -386,7 +386,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow BannerTheme. // Capture the shadow BannerTheme.
builder: (BuildContext _) => InheritedTheme.captureAll(context, listTiles), builder: (BuildContext _) => InheritedTheme.captureAll(context, listTiles),
...@@ -429,7 +429,7 @@ void main() { ...@@ -429,7 +429,7 @@ void main() {
expect(getIconStyle(selectedIconKey).color, tileSelectedColor); expect(getIconStyle(selectedIconKey).color, tileSelectedColor);
expect(getIconStyle(unselectedIconKey).color, tileIconColor); expect(getIconStyle(unselectedIconKey).color, tileIconColor);
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
...@@ -475,7 +475,7 @@ void main() { ...@@ -475,7 +475,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The slider will see the default SliderTheme when built. // The slider will see the default SliderTheme when built.
builder: (BuildContext _) => slider, builder: (BuildContext _) => slider,
...@@ -486,7 +486,7 @@ void main() { ...@@ -486,7 +486,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow SliderTheme. // Capture the shadow SliderTheme.
builder: (BuildContext _) => InheritedTheme.captureAll(context, slider), builder: (BuildContext _) => InheritedTheme.captureAll(context, slider),
...@@ -513,7 +513,7 @@ void main() { ...@@ -513,7 +513,7 @@ void main() {
expect(sliderBox, paints..rrect(color: activeTrackColor)..rrect(color: inactiveTrackColor)); expect(sliderBox, paints..rrect(color: activeTrackColor)..rrect(color: inactiveTrackColor));
expect(sliderBox, paints..circle(color: thumbColor)); expect(sliderBox, paints..circle(color: thumbColor));
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
...@@ -560,7 +560,7 @@ void main() { ...@@ -560,7 +560,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The slider will see the default ToggleButtonsTheme when built. // The slider will see the default ToggleButtonsTheme when built.
builder: (BuildContext _) => toggleButtons, builder: (BuildContext _) => toggleButtons,
...@@ -571,7 +571,7 @@ void main() { ...@@ -571,7 +571,7 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow toggleButtons. // Capture the shadow toggleButtons.
builder: (BuildContext _) => InheritedTheme.captureAll(context, toggleButtons), builder: (BuildContext _) => InheritedTheme.captureAll(context, toggleButtons),
...@@ -603,7 +603,7 @@ void main() { ...@@ -603,7 +603,7 @@ void main() {
expect(getTextColor('selected'), selectedButtonColor); expect(getTextColor('selected'), selectedButtonColor);
expect(getTextColor('unselected'), buttonColor); expect(getTextColor('unselected'), buttonColor);
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
...@@ -649,7 +649,7 @@ void main() { ...@@ -649,7 +649,7 @@ void main() {
RaisedButton( RaisedButton(
child: const Text('push unwrapped'), child: const Text('push unwrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// The slider will see the default ButtonTheme when built. // The slider will see the default ButtonTheme when built.
builder: (BuildContext _) => buttons, builder: (BuildContext _) => buttons,
...@@ -660,7 +660,7 @@ void main() { ...@@ -660,7 +660,7 @@ void main() {
RaisedButton( RaisedButton(
child: const Text('push wrapped'), child: const Text('push wrapped'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
// Capture the shadow toggleButtons. // Capture the shadow toggleButtons.
builder: (BuildContext _) => InheritedTheme.captureAll(context, buttons), builder: (BuildContext _) => InheritedTheme.captureAll(context, buttons),
...@@ -695,7 +695,7 @@ void main() { ...@@ -695,7 +695,7 @@ void main() {
expect(getButtonColor('disabled'), disabledButtonColor); expect(getButtonColor('disabled'), disabledButtonColor);
expect(getButtonColor('enabled'), buttonColor); expect(getButtonColor('enabled'), buttonColor);
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route animation await tester.pumpAndSettle(); // route animation
await tester.tap(find.text('push unwrapped')); await tester.tap(find.text('push unwrapped'));
......
...@@ -282,7 +282,7 @@ void main() { ...@@ -282,7 +282,7 @@ void main() {
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: TextButton( child: TextButton(
child: const Text('PUSH'), child: const Text('PUSH'),
onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, onPressed: () { Navigator.of(context).pushNamed('/b'); },
), ),
), ),
'/b': (BuildContext context) => Container(child: const Text('HELLO')), '/b': (BuildContext context) => Container(child: const Text('HELLO')),
...@@ -737,7 +737,7 @@ void main() { ...@@ -737,7 +737,7 @@ void main() {
expect(homeTapCount, 1); expect(homeTapCount, 1);
expect(pageTapCount, 0); expect(pageTapCount, 0);
final ValueNotifier<bool> notifier = Navigator.of(homeScaffoldKey.currentContext!)!.userGestureInProgressNotifier; final ValueNotifier<bool> notifier = Navigator.of(homeScaffoldKey.currentContext!).userGestureInProgressNotifier;
expect(notifier.value, false); expect(notifier.value, false);
Navigator.push<void>(homeScaffoldKey.currentContext!, MaterialPageRoute<void>( Navigator.push<void>(homeScaffoldKey.currentContext!, MaterialPageRoute<void>(
......
...@@ -26,7 +26,7 @@ void main() { ...@@ -26,7 +26,7 @@ void main() {
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: TextButton( child: TextButton(
child: const Text('push'), child: const Text('push'),
onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, onPressed: () { Navigator.of(context).pushNamed('/b'); },
), ),
), ),
'/b': (BuildContext context) => const Text('page b'), '/b': (BuildContext context) => const Text('page b'),
...@@ -52,7 +52,7 @@ void main() { ...@@ -52,7 +52,7 @@ void main() {
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: TextButton( child: TextButton(
child: const Text('push'), child: const Text('push'),
onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, onPressed: () { Navigator.of(context).pushNamed('/b'); },
), ),
), ),
'/b': (BuildContext context) => const Text('page b'), '/b': (BuildContext context) => const Text('page b'),
...@@ -85,7 +85,7 @@ void main() { ...@@ -85,7 +85,7 @@ void main() {
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: TextButton( child: TextButton(
child: const Text('push'), child: const Text('push'),
onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, onPressed: () { Navigator.of(context).pushNamed('/b'); },
), ),
), ),
'/b': (BuildContext context) => const Text('page b'), '/b': (BuildContext context) => const Text('page b'),
...@@ -125,7 +125,7 @@ void main() { ...@@ -125,7 +125,7 @@ void main() {
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: TextButton( child: TextButton(
child: const Text('push'), child: const Text('push'),
onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, onPressed: () { Navigator.of(context).pushNamed('/b'); },
), ),
), ),
'/b': (BuildContext context) => const Text('page b'), '/b': (BuildContext context) => const Text('page b'),
...@@ -169,7 +169,7 @@ void main() { ...@@ -169,7 +169,7 @@ void main() {
'/': (BuildContext context) => Material( '/': (BuildContext context) => Material(
child: TextButton( child: TextButton(
child: const Text('push'), child: const Text('push'),
onPressed: () { Navigator.of(context)!.pushNamed('/b'); }, onPressed: () { Navigator.of(context).pushNamed('/b'); },
), ),
), ),
'/b': (BuildContext context) => StatefulBuilder( '/b': (BuildContext context) => StatefulBuilder(
......
...@@ -124,7 +124,7 @@ void main() { ...@@ -124,7 +124,7 @@ void main() {
await tester.tap(find.byKey(withCallbackKey)); await tester.tap(find.byKey(withCallbackKey));
await tester.pump(); await tester.pump();
await tester.pump(const Duration(seconds: 1)); await tester.pump(const Duration(seconds: 1));
Navigator.of(popupContext)!.pop(); Navigator.of(popupContext).pop();
await tester.pump(); await tester.pump();
expect(cancels, equals(2)); expect(cancels, equals(2));
}); });
......
...@@ -1372,12 +1372,12 @@ void main() { ...@@ -1372,12 +1372,12 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('Next'), child: const Text('Next'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pushReplacement( Navigator.of(context).pushReplacement(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
child: const Text('Inner page'), child: const Text('Inner page'),
onPressed: () { Navigator.of(context)!.pop(); }, onPressed: () { Navigator.of(context).pop(); },
); );
}, },
), ),
......
...@@ -2086,12 +2086,12 @@ void main() { ...@@ -2086,12 +2086,12 @@ void main() {
ElevatedButton( ElevatedButton(
child: const Text('Next'), child: const Text('Next'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pushReplacement( Navigator.of(context).pushReplacement(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
child: const Text('Inner page'), child: const Text('Inner page'),
onPressed: () { Navigator.of(context)!.pop(); }, onPressed: () { Navigator.of(context).pop(); },
); );
}, },
), ),
......
...@@ -2035,7 +2035,7 @@ void main() { ...@@ -2035,7 +2035,7 @@ void main() {
key: transitionTarget, key: transitionTarget,
child: const Text('PUSH'), child: const Text('PUSH'),
onPressed: () { onPressed: () {
Navigator.of(context)!.pushNamed('/second'); Navigator.of(context).pushNamed('/second');
}, },
), ),
), ),
......
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
expect(tester.testTextInput.isVisible, isFalse); expect(tester.testTextInput.isVisible, isFalse);
Navigator.of(tester.element(find.text('Dialog')))!.pop(); Navigator.of(tester.element(find.text('Dialog'))).pop();
await tester.pump(); await tester.pump();
expect(focusNode.hasPrimaryFocus, isTrue); expect(focusNode.hasPrimaryFocus, isTrue);
......
...@@ -139,7 +139,7 @@ void main() { ...@@ -139,7 +139,7 @@ void main() {
child: TextButton( child: TextButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push(MaterialPageRoute<void>( Navigator.of(context).push(MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return SampleForm( return SampleForm(
callback: () => Future<bool>.value(willPopValue), callback: () => Future<bool>.value(willPopValue),
...@@ -178,7 +178,7 @@ void main() { ...@@ -178,7 +178,7 @@ void main() {
child: TextButton( child: TextButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push(MaterialPageRoute<void>( Navigator.of(context).push(MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return SampleForm( return SampleForm(
callback: () => Future<bool>.value(willPopValue), callback: () => Future<bool>.value(willPopValue),
...@@ -230,11 +230,11 @@ void main() { ...@@ -230,11 +230,11 @@ void main() {
actions: <Widget> [ actions: <Widget> [
TextButton( TextButton(
child: const Text('YES'), child: const Text('YES'),
onPressed: () { Navigator.of(context)!.pop(true); }, onPressed: () { Navigator.of(context).pop(true); },
), ),
TextButton( TextButton(
child: const Text('NO'), child: const Text('NO'),
onPressed: () { Navigator.of(context)!.pop(false); }, onPressed: () { Navigator.of(context).pop(false); },
), ),
], ],
); );
...@@ -252,7 +252,7 @@ void main() { ...@@ -252,7 +252,7 @@ void main() {
child: TextButton( child: TextButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push(MaterialPageRoute<void>( Navigator.of(context).push(MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return SampleForm( return SampleForm(
callback: () => showYesNoAlert(context), callback: () => showYesNoAlert(context),
...@@ -338,7 +338,7 @@ void main() { ...@@ -338,7 +338,7 @@ void main() {
child: TextButton( child: TextButton(
child: const Text('X'), child: const Text('X'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push(route); Navigator.of(context).push(route);
}, },
), ),
); );
......
...@@ -349,7 +349,7 @@ void main() { ...@@ -349,7 +349,7 @@ void main() {
focusNode: testNode1, focusNode: testNode1,
autofocus: true, autofocus: true,
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return Center( return Center(
...@@ -358,7 +358,7 @@ void main() { ...@@ -358,7 +358,7 @@ void main() {
focusNode: testNode2, focusNode: testNode2,
autofocus: true, autofocus: true,
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
child: const Text('Go Back'), child: const Text('Go Back'),
), ),
...@@ -1148,7 +1148,7 @@ void main() { ...@@ -1148,7 +1148,7 @@ void main() {
focusNode: testNode1, focusNode: testNode1,
autofocus: true, autofocus: true,
onPressed: () { onPressed: () {
Navigator.of(context)!.push<void>( Navigator.of(context).push<void>(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return Center( return Center(
...@@ -1159,7 +1159,7 @@ void main() { ...@@ -1159,7 +1159,7 @@ void main() {
focusNode: testNode2, focusNode: testNode2,
autofocus: true, autofocus: true,
onPressed: () { onPressed: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
child: const Text('Go Back'), child: const Text('Go Back'),
), ),
......
...@@ -59,7 +59,7 @@ void main() { ...@@ -59,7 +59,7 @@ void main() {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
navigatorContext = context; navigatorContext = context;
Navigator.of(context)!.push( Navigator.of(context).push(
TestRoute( TestRoute(
useCaptureAll useCaptureAll
? InheritedTheme.captureAll(context, const IconTextBox('Hello')) ? InheritedTheme.captureAll(context, const IconTextBox('Hello'))
...@@ -121,7 +121,7 @@ void main() { ...@@ -121,7 +121,7 @@ void main() {
// Return to the home route // Return to the home route
useCaptureAll = true; useCaptureAll = true;
Navigator.of(navigatorContext)!.pop(); Navigator.of(navigatorContext).pop();
await tester.pumpAndSettle(); // route transition await tester.pumpAndSettle(); // route transition
// Verify that all is the same as it was when the test started // Verify that all is the same as it was when the test started
......
...@@ -204,13 +204,13 @@ void main() { ...@@ -204,13 +204,13 @@ void main() {
return ElevatedButton( return ElevatedButton(
child: const Text('Next'), child: const Text('Next'),
onPressed: () { onPressed: () {
Navigator.of(context)!.push( Navigator.of(context).push(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return ElevatedButton( return ElevatedButton(
child: const Text('Inner page'), child: const Text('Inner page'),
onPressed: () { onPressed: () {
Navigator.of(context, rootNavigator: true)!.push( Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (BuildContext context) { builder: (BuildContext context) {
return const Text('Dialog'); return const Text('Dialog');
...@@ -783,8 +783,8 @@ void main() { ...@@ -783,8 +783,8 @@ void main() {
'/A/B': (BuildContext context) => OnTapPage( '/A/B': (BuildContext context) => OnTapPage(
id: 'B', id: 'B',
onTap: (){ onTap: (){
Navigator.of(context)!.popUntil((Route<dynamic> route) => route.isFirst); Navigator.of(context).popUntil((Route<dynamic> route) => route.isFirst);
Navigator.of(context)!.pushReplacementNamed('/C'); Navigator.of(context).pushReplacementNamed('/C');
}, },
), ),
'/C': (BuildContext context) => const OnTapPage(id: 'C', '/C': (BuildContext context) => const OnTapPage(id: 'C',
...@@ -851,7 +851,7 @@ void main() { ...@@ -851,7 +851,7 @@ void main() {
id: 'B', id: 'B',
onTap: (){ onTap: (){
// Pops all routes with bad predicate. // Pops all routes with bad predicate.
Navigator.of(context)!.popUntil((Route<dynamic> route) => false); Navigator.of(context).popUntil((Route<dynamic> route) => false);
}, },
), ),
}; };
...@@ -929,7 +929,7 @@ void main() { ...@@ -929,7 +929,7 @@ void main() {
'/A/B': (BuildContext context) => OnTapPage( '/A/B': (BuildContext context) => OnTapPage(
id: 'B', id: 'B',
onTap: () { onTap: () {
Navigator.of(context)!.pushNamedAndRemoveUntil('/D', ModalRoute.withName('/A')); Navigator.of(context).pushNamedAndRemoveUntil('/D', ModalRoute.withName('/A'));
}, },
), ),
'/D': (BuildContext context) => const Text('page D'), '/D': (BuildContext context) => const Text('page D'),
...@@ -1597,7 +1597,7 @@ void main() { ...@@ -1597,7 +1597,7 @@ void main() {
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/' : (BuildContext context) => OnTapPage(id: '/', onTap: () { '/' : (BuildContext context) => OnTapPage(id: '/', onTap: () {
Navigator.pushNamed(context, '/A'); Navigator.pushNamed(context, '/A');
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}), }),
'/A': (BuildContext context) => OnTapPage(id: 'A', onTap: () { Navigator.pop(context); }), '/A': (BuildContext context) => OnTapPage(id: 'A', onTap: () { Navigator.pop(context); }),
}; };
...@@ -1825,12 +1825,12 @@ void main() { ...@@ -1825,12 +1825,12 @@ void main() {
}); });
testWidgets('initial routes below opaque route are offstage', (WidgetTester tester) async { testWidgets('initial routes below opaque route are offstage', (WidgetTester tester) async {
final GlobalKey<NavigatorState> g = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> testKey = GlobalKey<NavigatorState>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Navigator( child: Navigator(
key: g, key: testKey,
initialRoute: '/a/b', initialRoute: '/a/b',
onGenerateRoute: (RouteSettings s) { onGenerateRoute: (RouteSettings s) {
return MaterialPageRoute<void>( return MaterialPageRoute<void>(
...@@ -1850,7 +1850,7 @@ void main() { ...@@ -1850,7 +1850,7 @@ void main() {
expect(find.text('+/a+', skipOffstage: false), findsOneWidget); expect(find.text('+/a+', skipOffstage: false), findsOneWidget);
expect(find.text('+/a/b+'), findsOneWidget); expect(find.text('+/a/b+'), findsOneWidget);
g.currentState!.pop(); testKey.currentState!.pop();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('+/+'), findsNothing); expect(find.text('+/+'), findsNothing);
...@@ -1858,7 +1858,7 @@ void main() { ...@@ -1858,7 +1858,7 @@ void main() {
expect(find.text('+/a+'), findsOneWidget); expect(find.text('+/a+'), findsOneWidget);
expect(find.text('+/a/b+'), findsNothing); expect(find.text('+/a/b+'), findsNothing);
g.currentState!.pop(); testKey.currentState!.pop();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('+/+'), findsOneWidget); expect(find.text('+/+'), findsOneWidget);
...@@ -1868,12 +1868,12 @@ void main() { ...@@ -1868,12 +1868,12 @@ void main() {
testWidgets('Can provide custom onGenerateInitialRoutes', (WidgetTester tester) async { testWidgets('Can provide custom onGenerateInitialRoutes', (WidgetTester tester) async {
bool onGenerateInitialRoutesCalled = false; bool onGenerateInitialRoutesCalled = false;
final GlobalKey<NavigatorState> g = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> testKey = GlobalKey<NavigatorState>();
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Navigator( child: Navigator(
key: g, key: testKey,
initialRoute: 'Hello World', initialRoute: 'Hello World',
onGenerateInitialRoutes: (NavigatorState navigator, String initialRoute) { onGenerateInitialRoutes: (NavigatorState navigator, String initialRoute) {
onGenerateInitialRoutesCalled = true; onGenerateInitialRoutesCalled = true;
...@@ -1893,7 +1893,7 @@ void main() { ...@@ -1893,7 +1893,7 @@ void main() {
expect(find.text('Hello'), findsNothing); expect(find.text('Hello'), findsNothing);
expect(find.text('World'), findsOneWidget); expect(find.text('World'), findsOneWidget);
g.currentState!.pop(); testKey.currentState!.pop();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Hello'), findsOneWidget); expect(find.text('Hello'), findsOneWidget);
...@@ -1901,16 +1901,16 @@ void main() { ...@@ -1901,16 +1901,16 @@ void main() {
}); });
testWidgets('Navigator.of able to handle input context is a navigator context', (WidgetTester tester) async { testWidgets('Navigator.of able to handle input context is a navigator context', (WidgetTester tester) async {
final GlobalKey<NavigatorState> g = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> testKey = GlobalKey<NavigatorState>();
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
navigatorKey: g, navigatorKey: testKey,
home: const Text('home'), home: const Text('home'),
) )
); );
final NavigatorState state = Navigator.of(g.currentContext!)!; final NavigatorState state = Navigator.of(testKey.currentContext!);
expect(state, g.currentState); expect(state, testKey.currentState);
}); });
testWidgets('Navigator.of able to handle input context is a navigator context - root navigator', (WidgetTester tester) async { testWidgets('Navigator.of able to handle input context is a navigator context - root navigator', (WidgetTester tester) async {
...@@ -1931,7 +1931,61 @@ void main() { ...@@ -1931,7 +1931,61 @@ void main() {
) )
); );
final NavigatorState state = Navigator.of(sub.currentContext!, rootNavigator: true)!; final NavigatorState state = Navigator.of(sub.currentContext!, rootNavigator: true);
expect(state, root.currentState);
});
testWidgets('Navigator.maybeOf throws when there is no navigator', (WidgetTester tester) async {
final GlobalKey<NavigatorState> testKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(SizedBox(key: testKey));
expect(() async {
Navigator.of(testKey.currentContext!);
}, throwsFlutterError);
});
testWidgets('Navigator.maybeOf works when there is no navigator', (WidgetTester tester) async {
final GlobalKey<NavigatorState> testKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(SizedBox(key: testKey));
final NavigatorState? state = Navigator.maybeOf(testKey.currentContext!);
expect(state, isNull);
});
testWidgets('Navigator.maybeOf able to handle input context is a navigator context', (WidgetTester tester) async {
final GlobalKey<NavigatorState> testKey = GlobalKey<NavigatorState>();
await tester.pumpWidget(
MaterialApp(
navigatorKey: testKey,
home: const Text('home'),
)
);
final NavigatorState? state = Navigator.maybeOf(testKey.currentContext!);
expect(state, isNotNull);
expect(state, testKey.currentState);
});
testWidgets('Navigator.maybeOf able to handle input context is a navigator context - root navigator', (WidgetTester tester) async {
final GlobalKey<NavigatorState> root = GlobalKey<NavigatorState>();
final GlobalKey<NavigatorState> sub = GlobalKey<NavigatorState>();
await tester.pumpWidget(
MaterialApp(
navigatorKey: root,
home: Navigator(
key: sub,
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<void>(
settings: settings,
builder: (BuildContext context) => const Text('dummy'),
);
},
),
)
);
final NavigatorState? state = Navigator.maybeOf(sub.currentContext!, rootNavigator: true);
expect(state, isNotNull);
expect(state, root.currentState); expect(state, root.currentState);
}); });
......
...@@ -26,7 +26,7 @@ class HomePage extends StatefulWidget { ...@@ -26,7 +26,7 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> { class _HomePageState extends State<HomePage> {
void _presentModalPage() { void _presentModalPage() {
Navigator.of(context)!.push(PageRouteBuilder<void>( Navigator.of(context).push(PageRouteBuilder<void>(
transitionDuration: const Duration(milliseconds: 300), transitionDuration: const Duration(milliseconds: 300),
barrierColor: Colors.black54, barrierColor: Colors.black54,
opaque: false, opaque: false,
...@@ -62,7 +62,7 @@ class ModalPage extends StatelessWidget { ...@@ -62,7 +62,7 @@ class ModalPage extends StatelessWidget {
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
splashColor: Colors.transparent, splashColor: Colors.transparent,
onTap: () { onTap: () {
Navigator.of(context)!.pop(); Navigator.of(context).pop();
}, },
child: const SizedBox.expand(), child: const SizedBox.expand(),
), ),
......
...@@ -563,7 +563,7 @@ void main() { ...@@ -563,7 +563,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) {
...@@ -612,7 +612,7 @@ void main() { ...@@ -612,7 +612,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) {
...@@ -1138,7 +1138,7 @@ void main() { ...@@ -1138,7 +1138,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(
...@@ -1188,7 +1188,7 @@ void main() { ...@@ -1188,7 +1188,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(
...@@ -1247,7 +1247,7 @@ void main() { ...@@ -1247,7 +1247,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(
...@@ -1309,7 +1309,7 @@ void main() { ...@@ -1309,7 +1309,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'),
) )
...@@ -1371,7 +1371,7 @@ void main() { ...@@ -1371,7 +1371,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,
...@@ -1436,7 +1436,7 @@ void main() { ...@@ -1436,7 +1436,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',
......
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