-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add An Equivalent to AnimatedSwitcher
#119
Comments
I think you could probably get there with
Where it would run the outEffects on the outgoing child, then the inEffects on the incoming child. Maybe allow for an Feel free to take a stab at this as a PR. If not, I might look at it when I have a bit of time. |
I had no success in building this widget. Currently the first in effect works as well as the second inEffect for the contemplary widget. The out effects are not working and consecutive effects are also not working. I played around with different possibilities even with FutureBuilder instead of swap() but with no major success so far.
and the widget itself so far:
|
As a bit of quick guidance, the widget you swap in with swap completely replaces the prior target and it's Animate instance (well, not exactly, but it's the easiest way to conceptualize it), so you want something that looks more like this: Animate(child: oldChild, effects: outEffects).then().swap(
builder: (_, __) => Animate(child: newChild, effects: inEffects),
) Haven't tested that, but I think it should work. |
Unfortunately it is not fully working that way. With the snippet below the in and out effect for the first icon works as well as the in-effect for the alternate icon. From then on no effect is applied anymore. It seems like the animations are somewhat consumed and cannot be used anymore. The swap also needs to have the duration and delay setting at default. When setting 0 the animation is not working (better to say not visible) anymore.
|
Might be worth trying to add a key to the Animate instances. There's a decent chance that Flutter is just matching them as the same instance (same type, plus same child type), so it doesn't trigger playing. |
first tests were successful. Will do more tests tomorrow... |
I also need this feature to have what AnimatedSwitcher is doing. Wondering when will the PR from @mikes222 will be merged. |
Adding the key worked perfectly in my case and allows fadeIn->fadeOut smoothly even with multiple interactions. Attaching a short video to show the error-animation in action: error.mp4Here is the relevant code showing the use of the _ErrorView()
.animate(key: UniqueKey())
.fadeIn()
.then(delay: 2.seconds)
.fadeOut()
.toggle(
builder: (_, value, widget) =>
value ? widget : const SizedBox.shrink()), |
One of the things I love the most about
flutter_animate
is that I can use the extensions to visually separate (in my code) UI elements from the animation effects applied to them. This makes my code MASSIVELY more readable.The one place where I've struggled is I have a bunch of
AnimatedSwitchers
and I'm not quite sure how to migrate them. Here's one such example:I think what I've done above could be achieved via something like
toggleEffect
+flipEffect
, but it feels a bit messy so thus far I've just stuck withAnimatedSwitcher
while I migrated all my other animations toflutter_animate
.So, this isn't the highest pri, but here's what I'd like (and I may build a prototype myself):
a
SwitchEffect
that is as close toAnimatedSwitcher
as possible.This feels very close to just
return ToggleEffect( ... )
but as far as I can tell toggle effect is dependent on the animation, not on an external variable (like the widget child).I also just may be missing something in
flutter_animate
that already does this, if I have please let me know as I'd love to migrate all my vanilla fluttter animation logic into flutter_animate!The text was updated successfully, but these errors were encountered: