Flutter(Dart) physical back button disable or custom action/event.

  @override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async => false,
child: new Scaffold(
appBar: new AppBar(
title: new Text("data"),
leading: new IconButton(
icon: new Icon(Icons.ac_unit),
onPressed: () => Navigator.of(context).pop(),
),
),
),
);
}
class OverwriteBackButtonWidget extends StatefulWidget {
const OverwriteBackButtonWidget({
Key key,
this.width,
this.height,
}) : super(key: key);
final double width;
final double height;
@override
_OverwriteBackButtonWidgetState createState() =>
_OverwriteBackButtonWidgetState();
}
class _OverwriteBackButtonWidgetState extends State<OverwriteBackButtonWidget> {
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async => false,
child: new Scaffold(
appBar: new AppBar(
title: new Text("data"),
leading: new IconButton(
icon: new Icon(Icons.ac_unit),
onPressed: () => Navigator.of(context).pop(),
),
),
),
);
}
}
Navigator.pushNamedAndRemoveUntil(context, "/login", (Route<dynamic> route) => false);
import '../view_report_list/view_report_list_widget.dart';
...
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
ViewReportListWidget()),
(Route<dynamic> route) => false);
import '../view_report_list/view_report_list_widget.dart';Future resetBackButton(BuildContext context) async {
/* Navigator
.pushNamedAndRemoveUntil(context,
"/login",
(Route<dynamic> route) => false
);
*/
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
ViewReportListWidget()),
(Route<dynamic> route) => false);
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store