stargazing-dino / just_the_tooltip

A directional tooltip for flutter projects
https://pub.dev/packages/just_the_tooltip
MIT License
56 stars 55 forks source link

Make callbacks fire before future #49

Open caseycrogers opened 2 years ago

caseycrogers commented 2 years ago

Currently, the onShow and the onDismiss callbacks fire when their respective actions are completed, not when the actions start. This PR makes them fire on start.

This is preferable because developers often want to trigger behavior on start (eg to play an animation in-step with the tooltip's show animation). They can't do this with the current design because their callback runs too late.

If developers want to trigger behavior when the tooltip animations finish, they can simply add a delay of the same duration as their animations to their callback:

  onShow: () async {
    await Future.delayed(milliseconds: 150);
    doStuffAfterToolTipIsShown();
  }
stargazing-dino commented 2 years ago

I won't really get to this until after the holiday but what do you think about the onShow getting passed the state the tooltip is in?

Something like:

onShow: (state) {
  switch (state) {
    case TooltipState.start:
      //
    case TooltipState.end:
      //
  }
}

That or we could even pass through the controller state as it's a value notifier with the state anyways.

Another option would be to just add two more callbacks of onShowEnd or similar.

I'm open to the onShow being on the leading end like you say and just awaiting the same duration but I think both cases are common enough that a user wouldn't mind both cases being easily handled

Thank you for the PR too !

caseycrogers commented 2 years ago

All these options seem good, a lot of the Flutter first party widgets will have a simple onShow for convenience and then a more complex change notifier and/or notification system for when you want more control. I'll update this PR to pass state to onShow and have it called both on start and end.

(also obviously no rush on this, I actually ended up cutting the feature in my app that required tool tips anyway)

P.S. happy holidays!