PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 19, 2022

[FIXED] How can i set admin button for admins in flutter

 October 19, 2022     admin, dart, firebase, flutter, google-cloud-firestore     No comments   

Issue

I want to show floatactionbutton for only admins in my app, but how can i do this i do not know. Could you help me? By the way, when i login my app, my informations update what they are. I tried boolean isAdmin (and also lots of ways int etc.) and after this i set manually, but after that it update false or it deleted auto. again...

I just want to if i admin, then only i can use this button that's it.

my codes :

return Scaffold(
        floatingActionButton: provider.isAdmin == 1 ? CreateNewShop() : Container(),

        body: HomePageBody());

and also google sign in codes:

 Future login() async {
    isSigningIn = true;

    final user = await googleSignIn.signIn();
    if (user == null) {
      isSigningIn = false;
      return;
    } else {
      final googleAuth = await user.authentication;

      final credential = GoogleAuthProvider.credential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );
      await FirebaseAuth.instance.signInWithCredential(credential);
      final existingUserDocs = await FirebaseFirestore.instance
          .collection('Users')
          .where('uid', isEqualTo: user.id)
          .get();
      final uid = FirebaseAuth.instance.currentUser.uid;
      if (existingUserDocs.docs.isEmpty) {
        FirebaseFirestore.instance.collection('Users').doc(uid).set({
          'email': user.email,
          'username': user.displayName,
          'uid': uid,
          'userPhotoUrl': user.photoUrl,
          
        });
      } else {
        return null;
      }

      isSigningIn = false;
    }
  }

Solution

Use Visibility Widget to make hide and visible of a Widget

For more information visit Flutter Visibility class

floatingActionButton: Visibility(
          visible: provider.isAdmin == 1,
          child: FloatingActionButton(
            onPressed: (){},
            child: Icon(Icons.add),
          ),
        ),


Answered By - Saiful Islam
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing