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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.