GetX转到新的布局/屏幕,然后隐藏底部导航栏。当我得到时,底部的导航仍然出现。

发布于 2025-02-08 12:12:59 字数 2797 浏览 2 评论 0原文

我的底部导航栏在下面看起来像这样,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开浅夏 2025-02-15 12:12:59

使用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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文