GetX转到新的布局/屏幕,然后隐藏底部导航栏。当我得到时,底部的导航仍然出现。
我的底部导航栏在下面看起来像这样,
class BottomNavigationsBar extends StatefulWidget {
const BottomNavigationsBar({Key? key}) : super(key: key);
@override
State<BottomNavigationsBar> createState() => _BottomNavigationsBarState();
}
class _BottomNavigationsBarState extends State<BottomNavigationsBar> {
int currentIndex = 0;
final List _pages = [
EcoHomePageView(),
ChatCheckLogin(),
EcoNotificationPageView(),
UserCheckLogin(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pages[currentIndex],
bottomNavigationBar: BottomNavigationBar(
unselectedItemColor: Colors.grey.shade700,
selectedItemColor: Colors.red,
showSelectedLabels: true,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
onTap: ontap,
currentIndex: currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: "Home",
activeIcon: Icon(Icons.home)),
BottomNavigationBarItem(
icon: Icon(Icons.message_outlined),
label: "Chat",
activeIcon: Icon(Icons.message)),
BottomNavigationBarItem(
icon: Icon(Icons.notifications_outlined),
label: "Home",
activeIcon: Icon(Icons.notifications)),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: "User",
activeIcon: Icon(Icons.person)),
],
),
);
}
void ontap(int index) {
setState(() {
currentIndex = index;
});
}
}
直到需要使用下面的代码到新屏幕时,
onTap: () =>
Get.toNamed(Routes.UPLOAD_PRODUCT),
但是当我到达另一页时。底部导航栏仍然存在。我如何直接转到另一页,将底部导航栏留在后面?
这是主要代码
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await GetStorage.init();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final authC = Get.put(AuthController(), permanent: true);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MaterialApp(
home: Scaffold(
body: BottomNavigationsBar(),
),
);
}
return FutureBuilder(
future: authC.firstInitialized(),
builder: (context, snapshot) => SplashScreen(),
);
},
);
}
}
i having a bottom navigation bar that look like this below
class BottomNavigationsBar extends StatefulWidget {
const BottomNavigationsBar({Key? key}) : super(key: key);
@override
State<BottomNavigationsBar> createState() => _BottomNavigationsBarState();
}
class _BottomNavigationsBarState extends State<BottomNavigationsBar> {
int currentIndex = 0;
final List _pages = [
EcoHomePageView(),
ChatCheckLogin(),
EcoNotificationPageView(),
UserCheckLogin(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pages[currentIndex],
bottomNavigationBar: BottomNavigationBar(
unselectedItemColor: Colors.grey.shade700,
selectedItemColor: Colors.red,
showSelectedLabels: true,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
onTap: ontap,
currentIndex: currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home_outlined),
label: "Home",
activeIcon: Icon(Icons.home)),
BottomNavigationBarItem(
icon: Icon(Icons.message_outlined),
label: "Chat",
activeIcon: Icon(Icons.message)),
BottomNavigationBarItem(
icon: Icon(Icons.notifications_outlined),
label: "Home",
activeIcon: Icon(Icons.notifications)),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
label: "User",
activeIcon: Icon(Icons.person)),
],
),
);
}
void ontap(int index) {
setState(() {
currentIndex = index;
});
}
}
it works properly till when i need to go to new screen, using this code below
onTap: () =>
Get.toNamed(Routes.UPLOAD_PRODUCT),
but when i arrive at the other page. the bottom navigation bar still there. how can i directly go to other page leaving the bottom navigation bar behind??
this is the main.dart code
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await GetStorage.init();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final authC = Get.put(AuthController(), permanent: true);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return MaterialApp(
home: Scaffold(
body: BottomNavigationsBar(),
),
);
}
return FutureBuilder(
future: authC.firstInitialized(),
builder: (context, snapshot) => SplashScreen(),
);
},
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用Persistent_bottom_nav_bar将底部导航栏保持到所有屏幕。
https://pub.dev/packages/persistent_bottom_bottom_nav_bar
Use persistent_bottom_nav_bar for keep bottom navigation bar to all the screens.
https://pub.dev/packages/persistent_bottom_nav_bar