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

How to close the Drawer without Navigator.pop #44

Closed
Donk3ys opened this issue Apr 13, 2021 · 4 comments
Closed

How to close the Drawer without Navigator.pop #44

Donk3ys opened this issue Apr 13, 2021 · 4 comments

Comments

@Donk3ys
Copy link

Donk3ys commented Apr 13, 2021

Im building a web app that uses both drawer and endDrawer in the same page.
Therefore i cant use the function Scaffold.of(ctx).openEndDrawer() or scaffoldKey.currentState.openEndDrawer() to close the Drawer or vice versa.

Im trying to use Navigator.pop(ctx) to close the drawer, but its not closing the Drawer as it should.

@lulupointu
Copy link
Owner

lulupointu commented Apr 13, 2021

I dreaded this day will come.
I have no way of solving this right now. The drawer has a close method but it is not public.

I am going to look into this a bit more and see if I can finally solve this issue.

See the solution here

@Donk3ys
Copy link
Author

Donk3ys commented Apr 13, 2021

Thanks so much for the quick reply... You have build an awesome user friendly package here.
Its so strange to me that Flutter doesnt have a public method for closing drawers...

@lulupointu
Copy link
Owner

Oh I think I did find a solution !

Can you try this:

context.findRootAncestorStateOfType<DrawerControllerState>()?.close()

Disclaimer: findRootAncestorStateOfType should not be called a lot, it's ok for a button press but avoid calling it in a build method for example.

If this works I think you should use this. I have a lot of work right now so if that's ok for you I would rather not spend time fixing this right now.

@Donk3ys
Copy link
Author

Donk3ys commented Apr 13, 2021

You a legend,works perfectly.

@Donk3ys Donk3ys closed this as completed Apr 13, 2021
@lulupointu lulupointu changed the title Navigator.pop(ctx) not closing drawer How to close the Drawer without Navigator.pop Apr 13, 2021
@lulupointu lulupointu pinned this issue Apr 13, 2021
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