skip to Main Content

I am trying to navigate back to a previous screen from my current screen.
OnWillPop was deprecated thus I am using PopScope with the following code

  canPop: true,
  onPopInvoked: (didPop)
  {
    Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder:(context)=>
    StepperScreen(param1: widget.param1, param2: widget.param2)),(Route<dynamic>route)=>false);
  },
  child: Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(....  ``` 

On the back button for the IOS it works perfectly but not on the PopScope

```  Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder:(context)=>
    StepperScreen(param1: widget.param1, param2: widget.param2)),(Route<dynamic>route)=>false); ```

Is there something I miss or should I use a different routing call.

I get the following response from the editor

``` I/ViewRootImpl@1beec50[MainActivity](28298): ViewPostIme key 0
I/ViewRootImpl@1beec50[MainActivity](28298): ViewPostIme key 1
D/Activity(28298): onKeyDown(KEYCODE_BACK)
D/Activity(28298): onKeyUp(KEYCODE_BACK) isTracking()=true isCanceled()=false hasCallback=false  ```  

Then the entire apps back navigation is broken and not even the back button in the app bar wants to work

2

Answers


  1. Here is an example of how to implement PopScope:

    return PopScope(
          canPop: false,
          onPopInvoked: (didPop) {
            if (didPop) {
              return;
            }
    
            _showDialog();
          },
          child: Scaffold(
            appBar: ArchiveTvAppBar(
    

    With this example we open a dialog before poping, but you can do whatever else you want.

    Naturally in this example, in he _showDialog method, a pop is done for really poping when the user validate the dialog.

    Login or Signup to reply.
  2.   @override
      Widget build(BuildContext context) {
        return PopScope(
         canPop: false,
         onPopInvoked : (didPop){
          // logic
         },
         child: Scaffold()
       );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search