Comments (4)
Everything I saw on this page is about widgets. You cannot use the Get.context within widgets. Get was designed to be 100% stable, and cases like these that generate side effects, an exception will be thrown.
This is one of the few cases where you should keep something in your widget tree for the sake of your project's stability.
If a function needs context = use Get.context
If a widget needs context = provide the context.
Basically, when you open a screen, the build method is called, and it sends Get the current context. If you try to use the Get context in a widget that is being rendered by the build method, it will not have received the context yet and many inconsistencies can happen, so use the method build context, this is how things should happen.
As much as you are building widgets in a functional way, the real return is still from a widget, and it has the same behavior as the widget code _buildAddressTile(){} for example, was in the tree.
from getx.
In the last version I implemented the context of the current BuildContext. You can access the context of the last build method with Get.context.
This will work for 99% of things, but it won't work for everything, InheritedWidget is the only problem in that regard, I don't know what you're trying to do, but unless you are looking for an InheritedWidget context, everything will work normally, as it takes the context of the Screen that is currently open.
I also intend to add support for Widgets that use inherited in the future, this can change the way the framework is used today, and end the use of providers once and for all, but this is a second project that will probably be integrated into this one in the future, but still is undergoing internal testing.
Try Get.context and let me know if it works for you.
from getx.
Just tested it and it didn't work.
Here is the code if you want to have a look.
Unhandled Exception: Navigator operation requested with a context that does not include a Navigator.
E/flutter (15454): The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
from getx.
Ah ok, I understand now. Thanks for your help!
from getx.
Related Issues (20)
- Nested GetRouterOutlet not working as expected HOT 2
- UI Not Updating with Switch/Toggle in ListView using GetX Controller
- Back button in browser don't behave the same as Get.back()
- Reactive variable observation issues HOT 2
- 是否可以在 GetMiddleware 中拿到正确的 arguments 值
- The GetxController is not automatically deleted if it is the first child of GetMaterialApp HOT 3
- GetxController value change listen is called without widget init
- get.dialog is automatic dismiss when app lifecycle is background.
- Margin of The GetSnackBar is Blocking Clickable Widget Under the Snackbar
- any suggestions to support deferred for GetMaterialApp?
- Get.arguments coming Null for Unit test
- Add zh_Hans and zh_Hant when using multiple languages
- Null check operator used on a null value HOT 2
- Routing_issue
- iOS swipe back works with new PopScope widget and canPop: false HOT 2
- How to cancel execution request for GetConnect like Dio's CancelToken
- How to print request data
- Can you add a new folder name : "widgets" when every time we create new page or first time init get in new project
- Can you add a new folder name : "widgets"
- Caching data from api with Getconnect
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.