-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
The current wording on the TickerProviderStateMixin docs just says that
If you only have a single Ticker (for example only a single AnimationController) for the lifetime of your State, then using a SingleTickerProviderStateMixin is more efficient. This is the common case.
It is not clear how large this performance cost is, and I assumed that using one TickerProviderStateMixin three times is more expensive than using threeSingleTickerProviderStateMixins once. Based on a discussion on the Flutter Discord with chunhtai, that may not be the case. I had changed my code to avoid using TickerProviderStateMixin like so:
_animationController = AnimationController.unbounded(vsync: this)
..addListener(() {
_updateScale(_animationController.value);
});
//could have just set `vsync` to `this` if using `TickerProviderStateMixin`
WidgetsBinding.instance.addPostFrameCallback((_) {
_verticalAnimationController =
AnimationController.unbounded(vsync: _verticalController.position.context.vsync)
..addListener(() {
_verticalController.jumpTo(_verticalAnimationController.value);
});
_horizontalAnimationController =
AnimationController.unbounded(vsync: _horizontalController.position.context.vsync)
..addListener(() {
_horizontalController.jumpTo(_horizontalAnimationController.value);
});
});
Instead of just:
_animationController = AnimationController.unbounded(vsync: this)
..addListener(() {
_updateScale(_animationController.value);
});
_verticalAnimationController = AnimationController.unbounded(vsync: this)
..addListener(() {
_verticalController.jumpTo(_verticalAnimationController.value);
});
_horizontalAnimationController = AnimationController.unbounded(vsync: this)
..addListener(() {
_horizontalController.jumpTo(_horizontalAnimationController.value);
});
If the above has less or equal performance than using TickerProviderStateMixin, then that could be made more clear in the docs.