首页 > 解决方案 > 颤振中的底部导航栏问题:

问题描述

我想在登录前和登录后创建带有 2 个图标 [home - login] 的底栏,成为 3 个图标 [ home - notification - account] 但问题是登录页面采用与我登录时自动转到的通知页面相同的索引通知页面:我的枚举是:

enum SelectedTab { home, notification, account, login }

我的底栏

bottomNavigationBar: SalomonBottomBar(
    itemPadding: EdgeInsets.symmetric(horizontal: 13, vertical: 0),
    unselectedItemColor: Colors.black87,
    width: 5,
    currentIndex: SelectedTab.values.indexOf(_selectedTab),
    onTap: _handleIndexChanged,
    duration: Duration(milliseconds: 700),
    items: token == null
        ? [
            // Home
            SalomonBottomBarItem(
              icon: Padding(
                padding:
                    const EdgeInsets.symmetric(horizontal: 15, vertical: 7),
                child: Icon(Feather.home),
              ),
              title: Text(
                "",
              ),
              selectedColor: Color(MAIN_COLOR),
            ),
              // login
            SalomonBottomBarItem(
              icon: Padding(
                  padding: const EdgeInsets.symmetric(
                      horizontal: 17, vertical: 5),
                  child: token == null
                      ? Icon(Feather.log_in)
                      : Icon(Feather.user)),
              title: Text(
                "",
                textAlign: TextAlign.center,
              ),
              selectedColor: Color(MAIN_COLOR),
            ),
          ]
        : [
            // Home
            SalomonBottomBarItem(
              icon: Padding(
                padding:
                    const EdgeInsets.symmetric(horizontal: 15, vertical: 7),
                child: Icon(Feather.home),
              ),
              title: Text(
                "",
              ),
              selectedColor: Color(MAIN_COLOR),
            ),
            // Notifcation
            SalomonBottomBarItem(
              icon: Padding(
                padding:
                    const EdgeInsets.symmetric(horizontal: 15, vertical: 7),
                child: Icon(Feather.bell),
              ),
              title: Text(
                "",
                textAlign: TextAlign.center,
              ),
              selectedColor: Color(MAIN_COLOR),
            ),
            // login
            SalomonBottomBarItem(
              icon: Padding(
                  padding: const EdgeInsets.symmetric(
                      horizontal: 17, vertical: 5),
                  child: token == null
                      ? Icon(Feather.log_in)
                      : Icon(Feather.user)),
              title: Text(
                "",
                textAlign: TextAlign.center,
              ),
              selectedColor: Color(MAIN_COLOR),
            ),
          ],
  ),

我在屏幕之间切换:

Widget switchBetwwenScreens(BuildContext context) {

final tokenValue = Provider.of<Authent>(context, listen: true).token;
switch (_selectedTab) {
  case SelectedTab.home:
    return HomeView();
    break;
  // =====================================problem from here =======================================================
  case SelectedTab.notification:
    return tokenValue != null
        ? NotificationsScreen()
        : LoginScreen(
            newContext: context,
          );

    break;
  case SelectedTab.account:
    return Container(
      child: Center(
          child: tokenValue == null
              ? LoginScreen(
                  newContext: context,
                )
              : AccountView()),
    );
    break;

  default:
    return Container(
      child: Center(
        child: Text("home"),
      ),
    );
}
}

标签: flutterindexingenumsflutter-bottomnavigation

解决方案


推荐阅读