flutter_cupertino_will_pop_scope icon indicating copy to clipboard operation
flutter_cupertino_will_pop_scope copied to clipboard

awaiting the dialog results in stuck state

Open Mikkelet opened this issue 1 year ago • 0 comments

If you modify the will pop scope function to await the result from the dialog and pop/stay based on the result, the page can get stuck in a stuck state.

Modify the example as such:

Future<bool> _onWillPop() async {
    if (_hasChanges) {
    // Show an alert before returning false
    final response = await showDialog(
        context: context,
        builder: (context) => _dialog(context),
      );
      print("response=$response");
      return response;
    }

    return true;
   }

and add this:

Widget _dialog(BuildContext context) {
    return Dialog(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          MaterialButton(
            onPressed: () {
              Navigator.of(context).pop(true);
            },
            child: Text("Pop"),
          ),
          MaterialButton(
            onPressed: () {
              Navigator.of(context).pop(false);
            },
            child: Text("Dont pop"),
          ),
        ],
      ),
    );
  }

The result returns fine, but the page does not respond. If you select "dont pop", the page can get stuck and you cannot swipe to go back

Mikkelet avatar Apr 30 '23 19:04 Mikkelet