![](/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.