我用过
WillPopScope
WillPopScope(
onWillPop: () => willPopScopeWid(),
child:Container(
//SomeCode
)),
willPopScopeWid() {
setState(() {
onTapOfVideo = false;
});
return Navigator.pop(context);
}
=>
还有其他方法可以摆脱已弃用的 Widget 吗?
是的,
WillPopScope
小部件已被弃用,并被 PopScope
取代,以下是如何使用 PopScope
:
PopScope(
canPop: false,
onPopInvoked: (bool didPop) async {
// when pressing back button this is a callback for
},
child: YourWidget()
)