Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popping context pops current screen not alert #33

Closed
abhay-s-rawat opened this issue Apr 27, 2024 · 3 comments
Closed

Popping context pops current screen not alert #33

abhay-s-rawat opened this issue Apr 27, 2024 · 3 comments

Comments

@abhay-s-rawat
Copy link

abhay-s-rawat commented Apr 27, 2024

This is the 3rd time I am reporting this issue and 2 times I have given pull request for same but I don't know why this issue is always supressed.

The issue is so intermittent that it's very hard to catch.
The context we are passing and the context we are popping is same which pops screen behind the alert.
I gave solution to simply return context alert is using in onConfirmBtnTap function . onConfirmBtnTap(context)

We are always popping parent context in onConfirmBtnTap if we are defining that function , if function is null it pops context that alert widget has defined (child context of what we have passed)

see quickalert_buttons.dart

// quickalert_buttons.dart
@override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 10.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          cancelBtn(context),
          okayBtn(context), // the alert context not the parent which was passed
        ],
      ),
    );
  }

  Widget okayBtn(context) { // the alert context not the parent which was passed
    if (!options!.showConfirmBtn!) {
      return const SizedBox();
    }
    final showCancelBtn = options!.type == QuickAlertType.confirm
        ? true
        : options!.showCancelBtn!;

    final okayBtn = buildButton(
        context: context,
        isOkayBtn: true,
        text: options!.confirmBtnText!,
        onTap: () {
          options!.timer?.cancel();
// the alert context not the parent which was passed
// if options!.onConfirmBtnTap != null then user will use the parent context to pop which will pop current screen not alert
          options!.onConfirmBtnTap != null
              ? options!.onConfirmBtnTap!()
              : Navigator.pop(context);
        });

    if (showCancelBtn) {
      return Expanded(child: okayBtn);
    } else {
      return okayBtn;
    }
  }
var res = await QuickAlert.show(
      context: context,
      width: width,
      type: QuickAlertType.error,
      title: 'Delete record',
      widget: const Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            'Are you sure to remove this ?',
            textAlign: TextAlign.center,
            style: TextStyle(
              color: Colors.grey,
              fontSize: 13,
            ),
          ),
        ],
      ),
      showCancelBtn: true,
      showConfirmBtn: true,
      onConfirmBtnTap: () {
        Navigator.pop(context);
      },
    );
@abhay-s-rawat
Copy link
Author

some of the package are already using that approach see below
https://pub.dev/packages/kumi_popup_window

//both sowPopupWindow and createPopupWindow
showPopupWindow(
  context,
  gravity: KumiPopupGravity.rightBottom,
  //curve: Curves.elasticOut,
  bgColor: Colors.grey.withOpacity(0.5),
  clickOutDismiss: true,
  clickBackDismiss: true,
  customAnimation: false,
  customPop: false,
  customPage: false,
  //targetRenderBox: (btnKey.currentContext.findRenderObject() as RenderBox),
  //needSafeDisplay: true,
  underStatusBar: false,
  underAppBar: true,
  offsetX: 0,
  offsetY: 0,
  duration: Duration(milliseconds: 200),
  onShowStart: (pop) {
    print("showStart");
  },
  onShowFinish: (pop) {
    print("showFinish");
  },
  onDismissStart: (pop) {
    print("dismissStart");
  },
  onDismissFinish: (pop) {
    print("dismissFinish");
  },
  onClickOut: (pop){
    print("onClickOut");
  },
  onClickBack: (pop){ 
    print("onClickBack");
  },
  childFun: (pop) {
    return Container(
      key: GlobalKey(),
      padding: EdgeInsets.all(10),
      height: 100,
      width: 100,
      color: Colors.redAccent,
    );
  },
);

@abhay-s-rawat
Copy link
Author

surprisingly this only happens in macos

@abhay-s-rawat
Copy link
Author

Unforunately I have to create own package for this. Thanks for your time
https://pub.dev/packages/simple_alert_dialog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant