WillPopScope 已弃用,不应使用。请改用 PopScope。颤动

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

我收到此警告。我已阅读文档。但我的代码在某些条件下返回 true 或 false 值。我该如何迁移这个?

WillPopScope(
            onWillPop: () async {
              if (_actionIcon.icon == Icons.search) {
                return true;
              } else {
                setState(() {
                  _actionIcon = const Icon(
                    Icons.search,
                    color: Colors.white,
                  );
                  _appBarTitle = Text('Heading',
                  _managePayrollBloc.add(_getSearch(""));
                });
                return false;
              }
            },
            child: SomeChild()
flutter
1个回答
0
投票

你可以像这样替换它:

PopScope(
  canPop: _myPopDisableEnableLogic(), // set it true according your app logic
  onPopInvoked: (bool didPop) async {
    // put if/ else condition part of your code here
  },
)
© www.soinside.com 2019 - 2024. All rights reserved.