Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will you implement showSearch? #28

Closed
Setti7 opened this issue Apr 3, 2020 · 4 comments
Closed

Will you implement showSearch? #28

Setti7 opened this issue Apr 3, 2020 · 4 comments

Comments

@Setti7
Copy link

Setti7 commented Apr 3, 2020

I'm currently using your package to completely separate my UI from all the logic and I want to use the search delegate, but it needs the context to be called. Are you planning to implement this feature?

@jonataslaw
Copy link
Owner

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.

@Setti7
Copy link
Author

Setti7 commented Apr 3, 2020

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.

@jonataslaw
Copy link
Owner

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.

@Setti7
Copy link
Author

Setti7 commented Apr 3, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants