I currently have a password reset page on my app.
The widget call a password reset function when the button is pressed. I have the reset button inside a Builder. I have test a snackbar inside the onPressed and it woks fine . But I want to be able to use the Firebase auth error inside the snackbar if the password has an error. but when trying to call the snackbar is still get a scaffold context error. my code is below. i am not putting the full widget tree as it is quite long but have put down what i think are the important part. The code to update the password runs fine, so I don't think there is any blocker there.
class _PasswordBuyerState extends State<PasswordBuyer> { final newpassword = TextEditingController(); final confirmpassword = TextEditingController(); final _PasswordformKey = GlobalKey<FormState>(); void SubmitBuyerPassword(password) async{ var user = await FirebaseAuth.instance.currentUser(); user.updatePassword(password).then((_){ print("Succesfully changed password"); final snackbar = SnackBar(content: Text("Password changes Successfully")); Scaffold.of(context).showSnackBar(snackbar); // this is not showing Navigator.push(context,MaterialPageRoute(builder: (context) => EditProfileBuyer())); }).catchError((error){ final snackbar = SnackBar(content: Text("Password can't be changed" + error.toString())); Scaffold.of(context).showSnackBar(snackbar); // If the form is valid, display a Snackbar. // this is not showing print("Password can't be changed" + error.toString()); }); } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( Further down in the code is the Builder with the button:
child:Builder( builder: (context) => RaisedButton( onPressed: (){ if (_PasswordformKey.currentState.validate()) { if(newpassword.text == confirmpassword.text){ print('matching'); setState(() { final snackbar = SnackBar(content: Text('password changing')); Scaffold.of(context).showSnackBar(snackbar); // the above snackbar works when tested SubmitBuyerPassword(newpassword.text.toString()); }); } else if(newpassword.text != confirmpassword.text){ print('not matching'); } }; }, color: Colors.blue[500], child: Text('Submit',textAlign: TextAlign.center,style: TextStyle(color:Colors.white),), ), ),