I would like to condition the sign out action depending If I have already or not sign in. I just tried with an "If" before everything but it show a "expected identifier" and "expected )". I would like to learn abut this part
I tried with an "If" conditional before PopUp menu.
appBar: AppBar(
title: Text("Categoria"),
backgroundColor: Color.fromARGB(150, 255, 0, 0),
actions: [
if (FirebaseAuth.instance.signInWithEmailAndPassword(email: "usu", password: "cla")==true){
PopupMenuButton(
onSelected: (Menu item) {
setState(() {
if (item == Menu.logout) {
FirebaseAuth.instance.signOut();
Navigator.push(context, MaterialPageRoute(
builder: (context) => Login()));
}
});
},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<Menu>>[
PopupMenuItem(value: Menu.logout,
child: Text("Cerrar sesión")
)
],
)
}
],
2
Answers
You can check the current auth state:
put the above the line of PopupMenuButton
you can use if clause only like that after return part:
or you can use ? and :