Open navaronbracke opened 1 week ago
I believe a lot of the conversation from https://github.com/flutter/flutter/pull/153056 is relevant here—this would make MenuController objects a bit "heavier", and we'd also suddenly need to start calling dispose()
.
It's technically not a breaking change by itself, since looking at the ChangeNotifier.dispose()
docs, disposing isn't necessary if you never add any listeners.
But inevitably we'll start taking advantage of the API within the menu anchor library, which means that projects prior to this change will start having memory leaks unless they update their code.
My personal opinion: maybe we could see how the code looks with a ValueListenable controller and compare it to the easiest workaround; if the workaround is significantly more ugly then this is probably worth pursuing.
I do agree with your point. What if we introduce a subclass ListenableMenuController
, that uses a ValueNotifier
internally and implements the ValueListenable
interface?
That way, people that don't need it can keep using the regular controller, while if you do need it, you can use the other one.
And if we intend to deprecate the ListenableMenuController
, we could perhaps use a typedef? (like how we did for MaterialStateProperty)
And if we intend to deprecate the
ListenableMenuController
Apologies; I'm having a bit of trouble following this.
My best guess is: after we introduce ListenableMenuController
, we eventually move the listenable logic into MenuController
and deprecate ListenableMenuController
with a typedef. Is that right?
Yes that's exactly what I'm thinking of.
Ah, okay. I will respond in the PR so we aren't splitting one conversation into 2 threads 😄
Use case
Users that want to observe the
isOpen
state of aMenuController
, for example when providing an animated icon for the child of the menu anchor.Proposal
The
MenuController
should be aValueListenable<bool>
or similar so that consumers get notified whenisOpen
changes.Note for triage: I think I remember there being discussion about this feature in the past, but I'm not sure if someone filed a bug for it. I can't find the relevant issue at least.