how to detect appbar back and footer back button in flutter?
How to detect AppBar Back Button in flutter?
how to detected android phone footer back button detect in flutter? I am trying to catch/detect my below source code. my trying source code:
WillPopScope(
onWillPop: (){
print("detect back button");
},
)
If you want to detect when the user clicked the Back button on the phone and when clicked the appBar Button, then you only have to add the WillScope to the page and leading on the AppBar with the type of button that you want and the logic that you want, like below:
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");
}),
),
));
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.