Une*_*loy 9 android router ios dart flutter
我正在使用底部导航器创建一个应用程序。我使用了一个,ShellRoute
但我们的要求是隐藏屏幕上的底部导航器例如:当我转到另一个屏幕(例如用户个人资料页面)时,主页可以有底部导航器我必须隐藏底部导航器,但我ShellRoute
在同一个屏幕中使用子路线ShellRoute
,它不会隐藏底部导航器。
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) {
return MainScreen(child: child);
},
routes: [
GoRoute(
path: '/$dashboardRouteName',
name: dashboardRouteName,
pageBuilder: (context, state) => CustomPageRouteBuilder.route(
key: UniqueKey(),
child: const DashboardScreen(),
),
routes: [
GoRoute(
path: leaveRequestRouteName,
name: '$dashboardRouteName/$leaveRequestRouteName',
pageBuilder: (context, state) => CustomPageRouteBuilder.route(
key: state.pageKey,
child: const LeaveRequestScreen(),
),
),
GoRoute(
path: switchHolidayRouteName,
name: '$dashboardRouteName/$switchHolidayRouteName',
pageBuilder: (context, state) => CustomPageRouteBuilder.route(
key: state.pageKey,
child: const SwitchHolidayScreen(),
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
之后,我将子路线分成一般路线,如下所示:
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (context, state, child) {
return MainScreen(child: child);
},
routes: [
GoRoute(
path: '/$dashboardRouteName',
name: dashboardRouteName,
pageBuilder: (context, state) => CustomPageRouteBuilder.route(
key: UniqueKey(),
child: const DashboardScreen(),
),
),
....
GoRoute(
path: '/$switchHolidayRouteName',
name: switchHolidayRouteName,
pageBuilder: (context, state) => CustomPageRouteBuilder.route(
key: state.pageKey,
child: const SwitchHolidayScreen(),
),
),
GoRoute(
path: '/$leaveRequestRouteName',
name: leaveRequestRouteName,
pageBuilder: (context, state) => CustomPageRouteBuilder.route(
key: state.pageKey,
child: const LeaveRequestScreen(),
),
),
Run Code Online (Sandbox Code Playgroud)
我使用它context.go()
,它可以工作,但我无法返回到上一个屏幕context.pop()
。
有人有什么想法吗?
在定义导航栏的主屏幕内,使用 检查您的当前位置GoRouter.of(context).location
。如果您的位置不是 BottomNavigationBar 应该显示的位置,则返回 Sizedbox 或 null ,否则返回您的 BottomNavigationBar。
@override
Widget build(BuildContext context) {
final location = GoRouter.of(context).location;
print('goRouter Location $location');
return Scaffold(
body: widget.child,
bottomNavigationBar: location != '/home' ? null : BottomNavigationBar(),
);
}
Run Code Online (Sandbox Code Playgroud)