Reputation: 259
Is there a way to handle the android device's physical back button, what I mean is that I'm not using an AppBar in the application so there's no back button the only back button there is the device physical back button and I want to handle the click on it.
this is the button I'm talking about
how can I do that??
Upvotes: 0
Views: 635
Reputation: 81
But what if, I want to perform another function or call my function when this back button is pressed.
I am not able to call it there in WillPopScope because it only takes boolean value.
For Example :
return WillPopScope(
onWillPop: () async {
Navigator.of(context).pop(true);
},
I am getting this kind of error
The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr', is a potentially non-nullable type.
Upvotes: 0
Reputation: 27137
You can use WillPopScope widget to do so.
following code may help you more.
WillPopScope(
onWillPop: () async => false,
child: Scaffold(
appBar: AppBar(
title: Text("Second Screen"),
),
Upvotes: 1