How can I make a dismissible alert in flutter?

Viewed 56

I can display an alert, but I can't close it. But why?

the code:

showGeneralDialog(
        barrierColor: Colors.red,
        context: context,
        barrierDismissible: true,
        barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
        transitionDuration: const Duration(milliseconds: 300),
        pageBuilder: (BuildContext buildContext, Animation animation,
            Animation secondaryAnimation) {
          if (shouldDismiss) {
            Future.delayed(const Duration(seconds: 3), () {
              Navigator.of(context, rootNavigator: true).pop(true);
            });
          }
          return SomeWidget();
2 Answers

replace this

 Navigator.of(context, rootNavigator: true).pop(true);

by this

 Navigator.of(buildContext, rootNavigator: true).pop(true);

Okay, so the problem was in the

SomeWidget()

There is a children inside it, called WillPopScope() and this widget have a parameter: onWillPop: () async => bool this boolean was false, that's why I could not close...

Related