Git Product home page Git Product logo

Comments (4)

jonataslaw avatar jonataslaw commented on May 21, 2024 1

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.

jonataslaw avatar jonataslaw commented on May 21, 2024

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.

Setti7 avatar Setti7 commented on May 21, 2024

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.

Setti7 avatar Setti7 commented on May 21, 2024

Ah ok, I understand now. Thanks for your help!

from getx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.