带参数的 PopScope

问题描述 投票:0回答:1

我正在尝试从当前屏幕导航回上一个屏幕。 OnWillPop 已被弃用,因此我使用 PopScope 和以下代码

  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
flutter dart
1个回答
0
投票

以下是如何实现 PopScope 的示例:

return PopScope(
      canPop: false,
      onPopInvoked: (didPop) {
        if (didPop) {
          return;
        }

        _showDialog();
      },
      child: Scaffold(
        appBar: ArchiveTvAppBar(

在此示例中,我们在弹出之前打开一个对话框,但您可以执行任何您想要的操作。

自然地,在这个示例中,在 _showDialog 方法中,当用户验证对话框时,会执行弹出操作以真正弹出。

© www.soinside.com 2019 - 2024. All rights reserved.