0

Basically I have a button(GestureDetector) which to call Future function in the same file. The thing is the widget in that function does not appear as it should but the background process is successfully running.

The trigger:

showDialog(
context: context,
builder: (context) {
AlertDialog(
  /// Below the button to call function *resetPassword*
  GestureDetector(
   child: Text("Yes"),
   onTap: () async {
   Navigator.of(context).pop();
   resetPassword('manan@gmail.com')}))})

The widget function:

Future<Widget> resetPassword(email) async {
try{
await FirebaseAuth.instance.sendPasswordResetEmail(email: email)
return AlertDialog(
///the content of dialog)
}on FirebaseAuthException catch (e) {
return AlertDialog(
///the content of dialog)
}}

Surprisingly the email of reset password was successfully sent.
Disclaimer: I am new to Flutter, hopefully sifus can considerate it.

Mohamad Aiman
  • 43
  • 1
  • 11

1 Answers1

0

When you're working with dialogs in general you have to wrap it with showDialog() method, like:

  await showDialog(
   context: context,
   builder: (BuildContext context) {
    return AlertDialog(
      title: Center(child: Text('Reset password')),
      content: Builder(
        builder: (context) {
          return Container(child: ForgotPasswordForm());
        },
      ),
    );
  },
);

Secondly, I see that you have nested Alert Dialog widgets and I think you should restructure this.

Yozmo
  • 521
  • 2
  • 10
  • Actually I've wrapped the dialog with showDialog, may be I have to reedit back my question. – Mohamad Aiman Jun 28 '21 at 06:20
  • I still believe that the problem is because you're returning AlertDialog widget inside of an another AlertDialog – Yozmo Jun 28 '21 at 06:25
  • Yes, but I try another approach by replacing Future. It works. By the way, thanks for helping because I have not wrapped showDialog for the latter AlertDialog yet. – Mohamad Aiman Jun 28 '21 at 06:41