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);
}

--

--

--

If you like my work or have question contact me.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

STATE AND LOCAL MODERNIZATION PROJECTS USING COTS/MOTS SOLUTIONS

How to Communicate Efficiently in a Distributed Team?

Distributed Team Exchange Practices at ENBISYS — Travel to Clients’ Locations and vice versa

How to know if a Linked List is Palindrome?

Laravel: Route Group Attributes

Working with Travis CI for your DDLC Mod

Java Packages and the Single Responsibility Principle

How to exchange metadata between WKC and other metadata repositories using Egeria.

Introduction To Python Part 5

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
Walter-Tscharf-Development

Walter-Tscharf-Development

If you like my work or have question contact me.

More from Medium

Why Flutter framework is Best App Development Platform in 2022

Why Flutter Framework is Best App Development Platform in 2022 — Krishang Technolab

What is the Difference Between pushReplacementNamed and popAndPushNamed in Flutter?

Using firebase cloud messaging to send notifications and data payloads

Easy Way to Create a Good Error-Handling in Flutter With Dartz