![](/img/trans.png)
[英]How to deactivate or override the arrow back button in the appBar in flutter?
[英]how to detect appbar back and footer back button in flutter?
如果您想检测用户何时单击手机上的后退按钮以及何时单击 appBar 按钮,那么您只需将 WillScope 添加到页面并在 AppBar 上引导您想要的按钮类型和逻辑你想要,如下所示:
class Example extends StatefulWidget {
const Example({Key key}) : super(key: key);
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
Future<bool> _onWillPop() async {
print("detect back button");
return true;
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop:_onWillPop,
child: Scaffold(
appBar: AppBar(
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
print("AppBar back button");
}),
),
));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.