我使用persistent_bottom_nav_bar package作为我的导航栏,我想从另一个屏幕自动导航到导航栏的标签。
class MyBottomNavBar extends StatelessWidget {
PersistentTabController controller = PersistentTabController(initialIndex: 0);
MyBottomNavBar({super.key, required this.controller});
@override
Widget build(BuildContext context) {
return PersistentTabView(
context,
controller: controller,
screens: _buildScreens(),
items: _navBarsItems(),
confineInSafeArea: true,
backgroundColor: Colors.white, // Default is Colors.white.
handleAndroidBackButtonPress: true, // Default is true.
resizeToAvoidBottomInset:
true, // This needs to be true if you want to move up the screen when keyboard appears. Default is true.
stateManagement: true, // Default is true.
hideNavigationBarWhenKeyboardShows:
true, // Recommended to set 'resizeToAvoidBottomInset' as true while using this argument. Default is true.
decoration: NavBarDecoration(
borderRadius: BorderRadius.circular(10.0),
colorBehindNavBar: Colors.white,
),
popAllScreensOnTapOfSelectedTab: true,
popActionScreens: PopActionScreensType.all,
itemAnimationProperties: const ItemAnimationProperties(
// Navigation Bar's items animation properties.
duration: Duration(milliseconds: 200),
curve: Curves.ease,
),
screenTransitionAnimation: const ScreenTransitionAnimation(
// Screen transition animation on change of selected tab.
animateTabTransition: true,
curve: Curves.ease,
duration: Duration(milliseconds: 200),
),
navBarStyle:
NavBarStyle.style10, // Choose the nav bar style with this property.
);
}
List<Widget> _buildScreens() {
return [
const ZekrCounterScreen(),
const ZekrListScreen(),
const AddZekrScreen(),
const Center(child: Text('آمار')),
const Center(child: Text('تنظیمات')),
];
}
List<PersistentBottomNavBarItem> _navBarsItems() {
return [
PersistentBottomNavBarItem(
icon: const Icon(CupertinoIcons.cube),
title: ("ذکر شمار"),
activeColorPrimary: CupertinoColors.activeBlue,
inactiveColorPrimary: CupertinoColors.systemGrey,
activeColorSecondary: Colors.white,
),
PersistentBottomNavBarItem(
icon: const Icon(CupertinoIcons.list_bullet),
title: ("لیست اذکار"),
activeColorPrimary: CupertinoColors.activeGreen,
inactiveColorPrimary: CupertinoColors.systemGrey,
activeColorSecondary: Colors.white,
routeAndNavigatorSettings: RouteAndNavigatorSettings(
initialRoute: "/",
routes: {
"/list": (final context) => const ZekrListScreen(),
"/add": (final context) => const AddZekrScreen(),
"/chart": (final context) => const Center(child: Text('آمار')),
"/settings": (final context) =>
const Center(child: Text('تنظیمات')),
},
),
),
PersistentBottomNavBarItem(
icon: const Icon(CupertinoIcons.add),
title: ("افزودن ذکر"),
activeColorPrimary: Colors.blue.shade300,
inactiveColorPrimary: CupertinoColors.systemGrey,
activeColorSecondary: Colors.white,
routeAndNavigatorSettings: RouteAndNavigatorSettings(
initialRoute: "/",
routes: {
"/list": (final context) => const ZekrListScreen(),
"/add": (final context) => const AddZekrScreen(),
"/chart": (final context) => const Center(child: Text('آمار')),
"/settings": (final context) =>
const Center(child: Text('تنظیمات')),
},
),
),
PersistentBottomNavBarItem(
icon: const Icon(CupertinoIcons.chart_pie),
title: ("آمار"),
activeColorPrimary: Colors.deepOrange,
inactiveColorPrimary: CupertinoColors.systemGrey,
activeColorSecondary: Colors.white,
routeAndNavigatorSettings: RouteAndNavigatorSettings(
initialRoute: "/",
routes: {
"/list": (final context) => const ZekrListScreen(),
"/add": (final context) => const AddZekrScreen(),
"/chart": (final context) => const Center(child: Text('آمار')),
"/settings": (final context) =>
const Center(child: Text('تنظیمات')),
},
),
),
PersistentBottomNavBarItem(
icon: const Icon(CupertinoIcons.settings),
title: ("تنظیمات"),
activeColorPrimary: Colors.deepPurple,
inactiveColorPrimary: CupertinoColors.systemGrey,
activeColorSecondary: Colors.white,
routeAndNavigatorSettings: RouteAndNavigatorSettings(
initialRoute: "/",
routes: {
"/list": (final context) => const ZekrListScreen(),
"/add": (final context) => const AddZekrScreen(),
"/chart": (final context) => const Center(child: Text('آمار')),
"/settings": (final context) =>
const Center(child: Text('تنظیمات')),
},
),
),
];
}
}
我想改变底部导航栏的状态也,我认为我可以访问控制器在标签屏幕。任何建议或想法是接受的。
1条答案
按热度按时间2q5ifsrm1#
您可以使用一些状态管理包,如:
1.或者使用StatefulWidget主页来控制
PersistentTabController
并自动更改您的:index
类似于:持久化选项卡控制器(索引:值)