0

i try to make flutter program which contain 2 buttomNavigationBar which is adminTabs and 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",
    ),
  ];

i try to connect it into the firebase which if the the type in users collection is '1' so it will return adminTabs and 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;
              });
            }
          }
        });
      }
    });
  }

but i seem to only gave the userTabs since i set the bool _isAdmin = false;. it seem like it do not fecth any data from the firebase and use only the variable. how can i fix it?

zahid
  • 13
  • 3

1 Answers1

1

Assuming you have successfully integrated Firebase in your App and able to fetch data without any issue.

Replace your code

String userType = doc.get('type');

with

String userType = doc['type']; // Assuming the field name in document is 'type'