Comments (7)
Wow, I was trying to go back (like you said) to a non-existant route. BUT, not because it got removed, I was just using a different name for it.
Sorry for wasting your time...
from getx.
Get.until could not bring any error in the snackbar, and if it does, placing the snackbar in the front can solve it (in some cases the animation of the snackbar can last longer than the animation of the route, and can cause problems, so I recommend inserting the snackbar always after the route in any case).
But I just can't reproduce your example. Everything works fine for me with your code.
void main() {
runApp(MaterialApp(
initialRoute: "/",
navigatorKey: Get.key,
onGenerateRoute: Router.generateRoute,
navigatorObservers: [
GetObserver(),
],
));
}
class Router {
static Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case '/':
return GetRoute(
page: First(),
settings: settings,
);
case '/second':
return GetRoute(settings: settings, page: Second());
case '/third':
return GetRoute(
settings: settings,
page: Third(),
popGesture: true,
transition: Transition.cupertino);
default:
return GetRoute(
settings: settings,
transition: Transition.fade,
page: Scaffold(
body:
Center(child: Text('No route defined for ${settings.name}')),
));
}
}
}
class First extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.add),
onPressed: () {
Get.snackbar("hi", "i am a modern snackbar");
},
),
title: Text('First Route counter'),
),
body: Center(
child: RaisedButton(
color: Colors.blue,
child: Text('Open route'),
onPressed: () {
Get.toNamed("/second");
},
),
),
);
}
}
class Second extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.add),
onPressed: () {
Get.snackbar("hi", "i am a modern snackbar");
},
),
title: Text('second Route'),
),
body: Center(
child: RaisedButton(
color: Colors.blue,
child: Text('Open route'),
onPressed: () {
Get.offNamed("/third");
},
),
),
);
}
}
class Third extends StatefulWidget {
@override
_ThirdState createState() => _ThirdState();
}
class _ThirdState extends State<Third> {
bool isCreatingPatient = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Third Route"),
),
body: Center(
child: RaisedButton(
color: Colors.blue,
onPressed: () {
// Get.close(2); // you can to use it
Get.snackbar(
'Patient ',
'Successfully added',
colorText: Colors.white,
);
Get.until('/', (Route route) {
setState(() {
isCreatingPatient =
false; // It does not make sense to change the state of a screen that will be closed, I think that this may be unnecessary.
}); //
return route.settings.name == '/';
});
},
child: Text('Go back!'),
),
),
);
}
}
It may be good to remember that there is Get.close(2); which does exactly the same thing as you did with Get.until, more clearly, perhaps.
In addition, although I am sure that this is not a problem with Get, I have the slight impression that you may have taken the first route you want to return to from the tree, if that happens, you will experience an error.
Navigator.popUntil/Get.until are sensitive to initialRoute, mixing named routes with common routes can cause errors; Try to see if your code in the MaterialApp has an initialRoute property or if you are not removing the route you want to return to.
from getx.
I can't use Get.close(2) because this same widget gets used in different scenarios, sometimes when there is 1 screen inbetween, but also when there are 2. That's why I was using Get.until.
The first route is definitely not removed.
My MaterialApp does have an initialRoute
though. Which is where I want the app to start. How does that get handled with onGenerateRoute
?
from getx.
Although your example also has initialRoute
, so that doesn't sound like the problem...
from getx.
Although your example also has
initialRoute
, so that doesn't sound like the problem...
Look for something that is using index in your code. In every lib, I don't use index on anything, and this error may be related to a widget that has lost its status in some way.
If the problem occurs in the web version, there is currently an issue related to onGenerateRoute returning null and missing the initial route.
from getx.
Which line of code is the error appearing on?
from getx.
Well, good news for you is that I can't replicate the problem on a new project.
Bad news for me is that I can't fix it on mine haha
Going to keep trying to do either and will get back to you
from getx.
Related Issues (20)
- Get 5.0.0 Nested Navigation duplicate routes HOT 5
- You need to call "Get.put(xx)" or "Get.lazyPut(()=>xx()) HOT 9
- Nested Navigation State Not Retained on Back to "Navigation" Tab HOT 3
- Unable to ecustomize `rootDelegate.pickPagesForRootNavigator` HOT 1
- Keyboard not appearing after swipe-back gesture when returning to a screen with TextField using GetX HOT 3
- A Controller's task continues to execute even after being deleted. HOT 1
- getx tree routing problem HOT 1
- An improper use of GetX has been detected when building PopupMenuButton in Obx
- [5.0.0-release-candidate-6] - PopScope not working in Flutter WEB HOT 1
- [5.0.0-release-candidate-6] - Get.back(result: true) or Get.close(result: true) does not return HOT 1
- GetResponsiveView not return the correct width when mobile orientation changes
- use GetX with routefly
- Flutter - get package: The getter 'backgroundColor' isn't defined for the class 'ThemeData' HOT 5
- get.dialog() animation HOT 1
- Prevent rebuild entire SliverGrid on LOAD more data
- Status problem after jumping to page using getx
- Transition.circularReveal error with Ipad Pro (12.9-inch)
- 为什么GetMaterialApp会有个白色背景?
- Error: Type 'GetLifeCycleBase' not found.
- RxList extends List,not recommended
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.