BilalShahid13 / PersistentBottomNavBar

A highly customizable persistent bottom navigation bar for Flutter
BSD 3-Clause "New" or "Revised" License
526 stars 394 forks source link

Using rflutter_alert package with PersistentBottomNavBar #112

Closed AkbarBakhshi closed 3 years ago

AkbarBakhshi commented 3 years ago

Hi, Thank you very much for this great package. I am using rflutter_alert from here with your package. However, for example let's say in your example code, if I replace a showmodalBootomSheet with the code below to show an alert, once I click on the dialog button to pop the alert, it pops the main screen instead. Am I doing something wrong? Or is this an issue with your package or the other package? Thank you!

Alert(
    context: context,
    type: AlertType.info,
    title: "RFLUTTER ALERT",
    desc: "Flutter is more awesome with RFlutter Alert.",
    buttons: [
           DialogButton(
                 child: Text(
                         "COOL",
                          style: TextStyle(color: Colors.white, fontSize: 20),
                  ),
                  onPressed: () => Navigator.pop(context),
                  color: Color.fromRGBO(0, 179, 134, 1.0),
                  radius: BorderRadius.circular(0.0),
           ),
        ],
).show();
BilalShahid13 commented 3 years ago

I tried running your code but seems like you are using your own widgets. But what I think the problem here is that context is not correct. When we use the rootNavigator property in showModalBootomSheet, it creates a new context out of scope of the previous one so we don't see the navigation bar. But if we don't use that property, we see the navigation bar because we are using the context of the selected screen of the navigation bar which is lower in the hierarchy compared to the navigation bar.

AkbarBakhshi commented 3 years ago

I just replaced the onPressed function of one of the buttons in your example with the code above and then the Navigator.pop(context) from the code above popped the tab screen instead of alert. I do agree with you that the problem is most probably the context. Can you think of a workaround or something for these two packages to work together?

BilalShahid13 commented 3 years ago

I guess you will have to modify this package. I did find the field useRootNavigator in its code but it is a constant value set to true.

  /// Displays defined alert window
  Future<bool> show() async {
    return await showGeneralDialog(
        context: context,
        pageBuilder: (BuildContext buildContext, Animation<double> animation,
            Animation<double> secondaryAnimation) {
          return _buildDialog();
        },
        barrierDismissible: style.isOverlayTapDismiss,
        barrierLabel:
            MaterialLocalizations.of(context).modalBarrierDismissLabel,
        barrierColor: style.overlayColor,
        useRootNavigator: true,
        transitionDuration: style.animationDuration,
        transitionBuilder: (
          BuildContext context,
          Animation<double> animation,
          Animation<double> secondaryAnimation,
          Widget child,
        ) =>
            alertAnimation == null
                ? _showAnimation(animation, secondaryAnimation, child)
                : alertAnimation(
                    context, animation, secondaryAnimation, child));
  }
BilalShahid13 commented 3 years ago

Another workaround that could possibly work (haven't tested it) is to pass the context from the first screen in the app and use that instead.

AkbarBakhshi commented 3 years ago

Another workaround that could possibly work (haven't tested it) is to pass the context from the first screen in the app and use that instead.

Yep.. When I pass menuScreenContext as the context of the Alert and then I pop the Alert using Navigator.of(menuScreenContext).pop(), it works. Thanks for the help!