Comments (12)
The Solution =
- Show AlertDialog when user Press back Button and GoBack or Stay on the same Page According to User Action ( Yes or No ) [ Logic ] ⇒
@override
Widget build(BuildContext context) {
// Back Navigation Logic while using AlertDialog
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
// if true then return nothing
if (didPop) {
return;
}
// if false then return AlertDialog Widget
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: const Text('Do you want to Edit this ?'),
actions: [
OutlinedButton(
onPressed: () {
// if user click on Yes then,
// First close the Dialog
Get.back();
// Then close the current page and go back
Get.back();
},
child: const Text('Yes'),
),
OutlinedButton(
onPressed: () {
// if user click on No then,
// Just close the dialog
Get.back();
},
child: const Text('No'),
),
],
),
);
},
child: Scaffold();
======================================================================
Completely Tested on Production App.
It is Working Fine ! 👍
from getx.
yes, please! solutions?
from getx.
same problem
from getx.
I have the same problem.
When is it estimated that the issue can be resolved?
from getx.
+1 Any update?
from getx.
You can currently use BackButtonListener() as a temporary alternative, like this
BackButtonListener(
onBackButtonPressed: () {
var routePath = Get.currentRoute;
if (routePath == '/') {
if (_lastPressedAt == null ||
DateTime.now().difference(_lastPressedAt!) >
const Duration(seconds: 2)) {
_lastPressedAt = DateTime.now();
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text("Press again to exit the program"),
));
return Future.value(true);
}
} else {
Navigator.pop(context);
return Future.value(true);
}
SystemNavigator.pop();
return Future.value(false);
},
child:Text("Hello,World!")
)
from getx.
You can currently use BackButtonListener() as a temporary alternative, like this
BackButtonListener( onBackButtonPressed: () { var routePath = Get.currentRoute; if (routePath == '/') { if (_lastPressedAt == null || DateTime.now().difference(_lastPressedAt!) > const Duration(seconds: 2)) { _lastPressedAt = DateTime.now(); ScaffoldMessenger.of(context).showSnackBar(const SnackBar( content: Text("Press again to exit the program"), )); return Future.value(true); } } else { Navigator.pop(context); return Future.value(true); } SystemNavigator.pop(); return Future.value(false); }, child:Text("Hello,World!") )
The BackButtonListener adds more problem when you have two of them.
Eg.
Your home screen has BottomNavigationBar, so you put a BackButtonListener to check if the user is on the 1st tab, if yes, then exit, else change the current tab to 1st one.
This works, however, if you have a popup open which needs to block the back button, you cannot rely on BackButtonListener as both the listeners will be triggered.
The idea of supporting the PopScope
is to have the support for Predictive Back Gesture in Android 13+
You can currently enable this feature from the Developer Options in Android 13+
from getx.
I've also had this problem after popScope, but I'm currently not using two BackButtonListeners. This is indeed a problem.
from getx.
Same problem here.
from getx.
Related to flutter/flutter#138614
from getx.
Related to flutter/flutter#138614
Thanks for your time to look into the issue.
However, even if the WillPopScope
is retained, can we fix the PopScope
in some way ? 🫣
This can be the low priority issue as I understand you are highly occupied with the new GetX update.
from getx.
GetX 4.6.6 does not seem to have this problem and PopScope
can be used correctly
from getx.
Related Issues (20)
- Can you add a new folder name : "widgets"
- Caching data from api with Getconnect
- preventDuplicates error
- When the iOS app is in the background, calling Dart code results in the prompt "Unhandled Exception: 'XXXXXController' not found."
- About the WebSocket issue HOT 2
- FullLifeCycleMixin的回调方法没有执行,找不到原因! HOT 1
- Getx fails to clear the arguments of the previous screen from memory.
- Flutter Web App With Getx Don't Work in Some hosting Like Firebase Hosting HOT 1
- Release version 5 Finally, it's been years HOT 5
- When using a project with Getx, get.context is checked for null. HOT 1
- Arguments always return null in GetMiddleware. How to use it right way? HOT 4
- about GetMiddleware issue
- alteast update dependencies bump version for get version 4.x.x HOT 2
- Null check operator used on a null value when deep linking added HOT 7
- Get.defaultDialog custom property never used in code. HOT 1
- Dialogs not closing when Get.back() HOT 1
- How to refresh the previous page when Get.back and Get.until HOT 6
- Navigation is not storing browser history HOT 4
- “Getx Controller Error: ‘AppClient?’ not found in Flutter” HOT 1
- Get.toNamed preventDuplicates: false has no effect HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from getx.