'AlertDialog is not showing any alert on the Screen

Once i press the rounded button, and if there is any error, i want flutter to show me the error in an alert window on my screen but it's not doing so.

RoundedButton(
                title: 'Register',
                onPressed: () async {
                  setState(() {
                    showSpinner = true;
                  });
                  try {
                    final newUser = await _auth.createUserWithEmailAndPassword(
                      email: email,
                      password: password,
                    );
                    Navigator.pushNamed(context, LoginScreen.id);
                    setState(() {
                      showSpinner = false;
                    });
                  } catch (e) {
                    build(context);
                    setState(() {
                      showSpinner = false;
                      
                    });
                    AlertWindow(
                      error: e.toString(),  // Here is the Alert window class
                    );
                  }
                },
                color: Colors.blueAccent,
              ),
class AlertWindow extends StatelessWidget {
  const AlertWindow({Key? key, required this.error}) : super(key: key);
  final String error;

  @override
  Widget build(BuildContext context) {
    return BackdropFilter(
      filter: ImageFilter.blur(sigmaX: 6, sigmaY: 6),
      child: AlertDialog(
        title: const Text('Alert'),
        content: Text(error),
      ),
    );
  }
}

If any error comes from firebase the spinner stops Spinning and nothing more happens. The alert window does not Pop up.



Solution 1:[1]

You should call showDialog function.

Sample:

 // show the dialog
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return   AlertWindow(error: e.toString());
    },
  );
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yasin Ege