简体   繁体   中英

Flutter: go_router 6.0.1 KEYCODE_BACK throw null safety error in ShellRoute

In my application I have ShellRoute, which I use for BottomNavigation. If I use the system back button or gesture on the selected tab, I get a null safety error and I don't know how to get rid of it.

在此处输入图像描述 在此处输入图像描述

The error occurs in delegate.dart in class GoRouterDelegate.

在此处输入图像描述

WillPopScope didn't work for me because the error was raised earlier.

The solution to my question was to redo the bottom navigation as shown here in example:

https://github.com/flutter/packages/blob/main/packages/go_router/example/lib/shell_route.dart

   ShellRoute(
    navigatorKey: _shellNavigatorKey,
    builder: (BuildContext context, GoRouterState state, Widget child) {
      return ScaffoldWithNavBar(child: child);
    },
   ....

It is necessary to pass a child inside the ShellRoute, it is not enough to solve it inside otherwise the context is not passed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM