![](/img/trans.png)
[英]How can you navigate to a specific screen in flutter with the bottom navigation bar
[英]Flutter: How can I Navigate to new screen in Persistent Bottom Navigation Bar package
我正在使用persistent_bottom_nav_bar package。 誰能告訴我如何使用
Navigator.pushReplacementNamed(context)
而不是使用pushNewScreen()
。 這主要是因為我想在用戶選擇新的底部項目時重新加載整個屏幕。 我猜pushNewScreen()
不會彈出舊屏幕,只是將其添加到堆棧中。
持久導航條碼:
PersistentTabView(
context,
backgroundColor: darkThemeColour,
confineInSafeArea: true,
screenTransitionAnimation: ScreenTransitionAnimation(
// Screen transition animation on change of selected tab.
animateTabTransition: true,
curve: Curves.ease,
duration: Duration(milliseconds: 200),
),
// context: context,
navBarStyle: NavBarStyle.style12,
controller: _controller,
items: [
PersistentBottomNavBarItem(
activeColorPrimary: iconColour,
inactiveColorPrimary: Colors.grey,
inactiveIcon: Icon(
Icons.home_outlined,
size: iconSize,
),
icon: Icon(
Icons.home,
size: iconSize,
),
routeAndNavigatorSettings: RouteAndNavigatorSettings(
// initialRoute: '/',
routes: {
RestaurantOverview.routeName: (context) => RestaurantOverview(),
// RestaurantDetailsScreen.routeName: (context) =>
// RestaurantDetailsScreen(),
},
),
),
PersistentBottomNavBarItem(
activeColorPrimary: iconColour,
inactiveColorPrimary: Colors.grey,
inactiveIcon: Icon(
Icons.shopping_cart_outlined,
size: iconSize,
),
icon: Icon(
Icons.shopping_cart,
size: iconSize,
),
routeAndNavigatorSettings: RouteAndNavigatorSettings(
// initialRoute: '/',
routes: {
MealCartScreen.routeName: (context) => MealCartScreen(),
// CartDetailsScreen.routeName: (context) => CartDetailsScreen(),
},
),
),
PersistentBottomNavBarItem(
activeColorPrimary: iconColour,
inactiveColorPrimary: Colors.grey,
inactiveIcon: Icon(
Icons.account_circle_outlined,
size: iconSize,
),
icon: Icon(
Icons.account_circle_rounded,
size: iconSize,
),
routeAndNavigatorSettings: RouteAndNavigatorSettings(
// initialRoute: '/',
routes: {
'/first': (context) => OrderScreen(),
},
),
),
],
screens: [
RestaurantOverview(),
// RestaurantDetailsScreen(),
MealCartScreen(),
// CartDetailsScreen(),
OrderScreen(),
],
);
pushNewScreen 代碼:
pushNewScreen(
context,
screen: CartDetailsScreen(cartItems[i]),
withNavBar: true,
);
請有人可以幫我解決這個問題
PersistenTabView 中有一個名為stateManagement的選項,將其設置為 false。 那會成功的。
return PersistentTabView(
...
statemanagement: false,
...
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.