Flutter 3.16中WillPopScope过期了,需要使用PopScope来代替。
PopScope的canPop为true,则一切正常,同时会调用onPopInvoked方法,参数didTop为true。 当canPop为false,则执行系统返回时会被拦截,并且调用onPopInvoked方法,同时didPop为false,此时进行逻辑判断,如果需要返回则执行Navigator.of(context).pop(); 。注意此时onPopInvoked又会被调用,并且didPop为true。
参考Demo: github.com
展开
2