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

all popups/dialog initiated using a widget W's context should be disposed automatically when the W is disposed #58953

Open
GAM3RG33K opened this issue Jun 8, 2020 · 3 comments
Labels
c: proposal A detailed proposal for a change to Flutter f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team-design Owned by Design Languages team triaged-design Triaged by Design Languages team

Comments

@GAM3RG33K
Copy link

Use case

I am working on a flutter app that requires two separate widgets to be displayed on a specific orientation. To achieve that I have used an orientation builder widget and it works fine.

Both widgets are not interconnected at all and both have their own set of Option Menu Items [ in simple words 3-dots menu in android] and context menu items [displayed on long press].

What happens is when I change orientation while keeping Option Menu or Context Menu Open in flutter app, it manages to be live even when the underlying widget is disposed and replaced by another widget.

Let's call the currently visible widget as root widget.

I need to close these popups and dialogs that have been displayed using root's context.

I have also posted the same on stackoverflow.
I got an answer, which turns out to be working, but as a side effect, along with the dialog & popups that code also disposes of any screens that I have navigated to from the root.

That is because the answer code relies on rebuilds of a widget which can happen at any time even if the widget is in the background.

So, Basically what I want to do is close all popups and dialogs on dispose of the root.

This description might feel a bit abstract, so if more details are required just ask me. I will update more details in the future if I am able to find a way to express the same via app code or screenshots

Proposal

flutter should be able to remove all popup/dialogs rendered using the root's context on root gets disposed of.

I think The real problem is identifying only dialog/popup elements from the tree and removing them.

@GAM3RG33K GAM3RG33K changed the title all popups/dialog initiated using a widget[root]'s context should be disposed automatically when the root is disposed all popups/dialog initiated using a widget W's context should be disposed automatically when the W is disposed Jun 8, 2020
@TahaTesser TahaTesser added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: proposal A detailed proposal for a change to Flutter labels Jun 8, 2020
@Hixie
Copy link
Contributor

Hixie commented Jun 9, 2020

I'm not sure a general solution is necessarily required (for example, suppose you have a button that shows a message dialog (which it doesn't need to stay around for, so it doesn't mark itself as needing keepalive while the message is up), but that button is in a scrolling list, and the list is scrolling when you tap the button, such that the button is disposed, the dialog need not go away as well.

But, I do think it makes sense that if you have a popup menu button, its popup menu goes away if the button goes away, and similarly with other built-in widgets we have that shows routes like DropDownButton.

@GAM3RG33K
Copy link
Author

GAM3RG33K commented Jun 10, 2020

in the Button scenario, what I think we can do is some kind of helper method which we can use to dispose of dialogs/popups when desired.

Something like, disposePopupsAssociatedWith(context).

I don't know if this feasible or not, but if it can be done, it will give us control over when we can dispose of all the popups with just one call of this method.

Use case:
consider a scenario where we show that data fetching is failed in a dialog and the fetching task is scheduled to repeat in X seconds until successful. On top of that assume that the user has kept a popup menu open.

In that case, if the app is unable to reach the server for 3 or 4 X worth of time interval there will be 3 or 4 dialogs on top of each other which will not disappear until the user interacts with them.

In this case, we can just call the disposePopupsAssociatedWith(context) on every failure to make sure that the dialogs do no crowd the screen and also ensure that on failure we don't have any other popup which is not needed anymore.

This is just a scenario that is imaginary but I kind of partially experience part of it on a daily basis. Especially the one with dialogs opening on top of each other without disposing of the older one.

I think The real problem is identifying only dialog/popup elements from the tree and removing them.

This is what I think is the root of the problem with dialogs and popups.

@GAM3RG33K
Copy link
Author

GAM3RG33K commented Jul 13, 2020

@Hixie Can you tell me What is the priority of this task? I am very much in need for the solution of this issue😂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: proposal A detailed proposal for a change to Flutter f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team-design Owned by Design Languages team triaged-design Triaged by Design Languages team
Projects
None yet
Development

No branches or pull requests

4 participants