flutter - 颤振中的底部导航栏问题:
问题描述
我想在登录前和登录后创建带有 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"),
),
);
}
}
解决方案
推荐阅读
- c++ - 有没有办法追溯原始源代码中内存崩溃地址所指的位置?
- c++ - Poco SocketAddress 不喜欢定义了预处理器宏的 IPv4 地址
- android - xamarin - 避免在 android 标记上打开 InfoWindow
- eclipse - maven deployin 从命令行工作,但不在 Eclipse 中
- vue.js - Vue CLI 3 vue.config.js 编译“未知单词”错误
- spring-boot - GCP Stackdriver Logging 中的平面应用程序日志视图(springboot 应用程序)
- angular - 一个没有共享和实例化参数的 Angular 服务
- parameters - Ada:在过程调用后检查 OUT 参数是否已更改(从 NULL)
- java - java代码从access_log文件中提取请求到sql数据库
- kinvey - kinvey loginwithMIC 方法无法在移动设备中打开 webview