Closed aytunch closed 3 years ago
Was actually thinking this myself ! I'll definitely add something like this in the near future
@Nolence I also would like to add hiding the tooltip programatically. Let's say I want to show a tooltip for a fixed Duration.
After the duration is passed I want to hide it programatically without the user pressing the screen. This feature is very important for me :)
My main struggle with this is whether I want a controller or something more declarative. The declarative option would just involve properties on the tip like isVisible
and you would hold those properties on the state of the widget that has the tooltip or an ancestor.
If you could point me to a really intuitive API of a different tooltip package that has worked for you we'll in the past, I'd consider it. It might even be from the React/Vue world.
My main gripe against controllers is that it's another thing for the user to remember to dispose and I personally never liked the non-granular update process around ChnageNotifiers although that's not really the issue.
I understand your concern perfectly. Personally I would benefit from a controller architecture.
However for this issue, we can add optional isShown
and showAndHideFadeTransitionDuration
fields.
I'm a little dumb as to how this controller will work. I took a look at an old PR I think I wrote for super_tooltip
and I naively wrote an event based controller not at all hooked up to the actual widget. Not even sure it awaits the transition.
Do you know of any resources to find out how to cleanly wire a controller to a Widget? I looked at ScrollController and PageController and those are kinda chaotic. Their animateTo
's and stuff are also like one liners that don't make any sense to me.
One option I thought is to pass all of my widget callbacks to the controller and just call them in the controller. That might work but I've never seen anyone else do it
(i.e. pass in the method _showTooltip as a property to the controller and then inside the controller's showTooltip, i just call _showTooltip) https://github.com/Nolence/just_the_tooltip/blob/0ed778c4d698689f7720a5618c3c94f776c82397/lib/src/just_the_tooltip.dart#L169
controller code: https://github.com/Nolence/just_the_tooltip/blob/0ed778c4d698689f7720a5618c3c94f776c82397/lib/src/models/just_the_controller.dart#L3
I personally find this kind of a controller implementation easier: https://github.com/akshathjain/sliding_up_panel/blob/master/lib/src/panel.dart
It is a simple controller class which keeps the state class as a variable inside.
I really like how clean that panel solution is. One thing that concerns me though is that they don't dispose anything. It's just a class that holds a reference to state. I can imagine a situation where the controller can become out of date with the internal state. It looks like onDispose, they don't invalidate anything on the controller so I think you could get some weird results if this was used wrong.
I found this SO answer https://stackoverflow.com/questions/63954710/creating-a-custom-controller-in-flutter That kind of discusses what we're talking about here. Someone else seems to have done what I suggested here by passing in the functions to the class.
I agree with Schnodderbalken's answer though saying this might be an anti-pattern though. I would also like something closer to a ValueNotifier.
That said, in my case, it's a bit harder as I use just about every lifecycle, require a delegate to determine some state and have listeners I need to constantly worry about -- all of which were better off connected to a widget and not being passed through to a controller.
I'll mull this over some more. I think i'll need to make a large refactor to support controllers so I don't want to jump into something right away
This was whack. I tried every solution and the thing i finally landed on was pretty much a better implementation of the PR i made for super_tooltip like a year ago.
Anyways, the controller is just a ValueNotifier that looks like a redux action. Once it changes its action, I have a listener on it in the widget that will fire off the correct callback according to the action. This solution however correctly handles the animation time between showing/hiding tooltips unlike my old PR.
Let me know what you think ! The controller is really simple at the minute but it can be exanded.
I'll add full docs once it's been tested. To test, use
just_the_tooltip: 0.0.6-dev
and provide a controller like any other widget
final controller = JustTheController();
JustTheTooltip(
controller: controller,
// ...
)
await controller.showTooltip();
await controller.hideTooltip();
I haven't thought super hard about what would happen when there's competing events or other edge cases so it might be off. Let me know
Hi. I use showTooltip for show tooltip when change page on pageView and works, but sometimes tooltip is not shown. If I use debugger seems to enter on funcion every times, but sometimes tooltip is not shown. What can I do?
Forcing the child onTap to show the tooltip is not cool. It might be the default behavior but we should be able to decide when we want to show the tooltip in the app. Think of onboarding scenarios.