我想禁用或至少更改在网络浏览器上按下后退按钮时应用程序返回的页面,Willonscope 曾经可以工作,但现在它已被弃用,我尝试了 Popscope,但它没有检测到按下后退按钮。我使用 GETX 作为路由器和 flutter 3.16。谁能帮助我吗?
类
WillPopScope
在 v3.12.0-1.0.pre
之后被弃用,您可以使用 PopScope
代替。
PopScope(
// If canPop is false, then a system back gesture will not pop the route off of the enclosing Navigator.
// onPopInvoked will still be called, and didPop will be false.
// If canPop is true, then a system back gesture will cause the enclosing Navigator to receive a pop as usual.
// onPopInvoked will be called with didPop as true, unless the pop failed for reasons unrelated to PopScope, in which case it will be false.
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
return;
}
_showBackDialog();
},
child: TextButton(
onPressed: () {
_showBackDialog();
},
child: const Text('Go back'),
),
),
查看 PopScope Docs 了解更多具体信息。