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

How to tween between two strings? #72

Closed
lordtottuu opened this issue May 3, 2021 · 5 comments
Closed

How to tween between two strings? #72

lordtottuu opened this issue May 3, 2021 · 5 comments

Comments

@lordtottuu
Copy link

I'm trying to reimplement this checkbox (https://felixblaschke.medium.com/custom-animated-control-elements-with-flutter-8c0d352d7136) with the latest version of the library. Mostly it's been painless but I'm drawing a blank on how to tween between the on and off strings. Is there a recommended way to do this? Thanks in advance!

@felixblaschke
Copy link
Owner

felixblaschke commented May 3, 2021 via email

@lordtottuu
Copy link
Author

lordtottuu commented May 4, 2021

I'm sorry if it's a daft question but I still don't understand how it fits into a scene. Is there a snippet out there that can show me how to integrate a text change into a timeline tween? This is my current code, which doesn't work as the text is stuck on OFF all the time. Feels like my understanding of ConstantTween is below par as, honestly, I wasn't sure how it worked in the earlier version of the library too. If there's a page detailing ConstantTween, feel free to just chuck it in my direction instead. Thank you.

final _tween = TimelineTween<AniProps>()
    ..addScene(
            begin: Duration(milliseconds: 0),
            end: Duration(milliseconds: animDuration))
        .animate(AniProps.paddingLeft, tween: Tween(begin: 1.0, end: 39.0))
        .animate(AniProps.color,
            tween: ColorTween(begin: UI.redNice, end: UI.greenPop))
        .animate(AniProps.rotation, tween: Tween(begin: -2 * pi, end: 0.0))
    ..addScene(
            begin: Duration(milliseconds: animDuration/2),
            end: Duration(milliseconds: animDuration))
        .animate(AniProps.text, tween: ConstantTween(T["co-off"]))
        .animate(AniProps.text, tween: ConstantTween(T["co-on"]));

@felixblaschke
Copy link
Owner

You need to split it into two scenes, here pseudocode:

.addScene(begin: 0, end: 0.5).animate(text, ConstantTween("off")) // prop text is 'off' for first half
.addScene(begin: 0.5, end: 1).animate(text, ConstantTween("on")) // prop text is 'on' for second half

@lordtottuu
Copy link
Author

This is exactly what I needed. Thank you! And thank you for the clear explanation. It has now really clicked in my head how all of this fits together.

Are you accepting PRs for documentation/examples?

@felixblaschke
Copy link
Owner

Sure you can PR doc/example, if they improve and match the overall style.
Keep in mind that all MD files are generated from the /tool/ directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants