我试图使Flutter程序包含2 buttomNavigationBar这是adminTabs和userTabs
final userTabs = [
const RecipeHome(),
const UserSetting(),
const CommunityPage(),
];
final adminTabs = [
const RecipeHome(),
const HomeManagement(),
const CommunityPage(),
const UserSetting(),
];
final List<BottomNavigationBarItem> adminNavigationItems = const [
BottomNavigationBarItem(
icon: Icon(Icons.home_rounded),
label: "Home",
),
BottomNavigationBarItem(
icon: Icon(Icons.insert_chart),
label: "recipe management",
),
BottomNavigationBarItem(
icon: Icon(Icons.group),
label: "community page",
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: "User Setting",
),
];
final List<BottomNavigationBarItem> userNavigationItems = const [
BottomNavigationBarItem(
icon: Icon(Icons.home_rounded),
label: "Home",
),
BottomNavigationBarItem(
icon: Icon(Icons.group),
label: "community page",
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: "User Setting",
),
];
我尝试将其连接到firebase,如果users集合中的类型为'1',则它将返回adminTabs和adminNavigationItems。
void _getUserType() {
// Get the current user from Firebase Authentication
FirebaseAuth.instance.authStateChanges().listen((user) {
if (user != null) {
FirebaseFirestore.instance
.collection('users').doc(user.uid).get().then((doc) {
if (doc.exists) {
String userType = doc.get('type');
print('User type: $userType');
if (userType == '1') {
setState(() {
_isAdmin = true;
});
}
}
});
}
});
}
但我似乎只给了userTabs,因为我设置了bool _isAdmin = false;
.它似乎不fetth从firebase的任何数据,只使用变量.我怎么能修复它?
1条答案
按热度按时间t30tvxxf1#
假设您已经成功地将Firebase集成到您的应用程序中,并且能够毫无问题地获取数据。
替换您的代码
String userType = doc.get('type');
与