-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[framework] create animation from value listenable #108644
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
[framework] create animation from value listenable #108644
Conversation
The idea with this is that instead of:
You can do:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Seems like a useful API.
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove blank line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/// | ||
/// The returned animation will always have an animations status of | ||
/// [AnimationStatus.forward]. The value of the provided listenable can | ||
/// be optionally transformed using the [transformer] function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonus points if you add the example from this comment here to showcase the API and how it can simplify things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the bonus points: 🌟🌟🌟🌟🌟
/// }, | ||
/// child: Container( | ||
/// child: Text('Hello, Animation'), | ||
/// ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the analyzer will hopefully tell you, but I think this is missing a closing )
for the ValueListenableBuilder?
/// }) | ||
/// child: Container( | ||
/// child: Text('Hello, Animation'), | ||
/// ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
I've noticed a number of patterns in a certain customer app, where there is a desire to animate some part of the UI (opacity for example) based on something that is available via a value listenable (scroll position). Because there is no easy way to create an animation from a value listenable, I see a lot of ValueListenableBuilders used to animate things that could be FadeTransitions. This has the distinct disadvantage of bypassing the repaint boundary mechanisms introduced into animated opacities.