I have following code that updates the data on firebase but due to some reasons, it does not show me message which was triggered by snackbar.
var user = FirebaseFirestore.instance
.collection("tblusers")
.doc(currentUser.uid)
.update({
"first_name": "Test"
}).then((value) => () {
final snackBar = SnackBar(
content: Text("Saved successfully"));
Scaffold.of(context).showSnackBar(snackBar);
});
Below is the full source code. First name is being updated successfully. But, the promise part is not executing due to some reasons. Am I missing anything?
Class 1st in separate file
class AccountSettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Body(),
);
}
}
Class 2nd in separate file
class Body extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Center(
child: SingleChildScrollView(
child: Column(children: <Widget>[
AccountForm()
]))));
}
}
Class 3rd in separate file
class AccountForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Form(
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(children: <Widget>[
Container(
child: Column(children: [
TextFormField(),
ElevatedButton(
onPressed: () {
var currentUser = FirebaseAuth.instance.currentUser;
if (currentUser != null) {
var user = FirebaseFirestore.instance
.collection("tblusers")
.doc(currentUser.uid)
.update({
"first_name": "Test A"
}).then((value) => () {
final snackBar = SnackBar(
content: Text("Saved successfully"));
Scaffold.of(context).showSnackBar(snackBar);
});
}
},
child: Text("Submit"))
]))
]));
}
}
question from:
https://stackoverflow.com/questions/65844166/snackbar-message-does-not-pop-up 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…