Skip to content

[Docs] Clarify performacne of SingleTickerProviderStateMixin vs TickerProviderStateMixin #164869

Closed

Description

@yakagami

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.

Activity

  1. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    d: api docsIssues with https://api.flutter.dev/
    and removed
    in triagePresently being triaged by the triage team
    on Mar 10, 2025
  2. added a commit that references this issue on Mar 11, 2025
    7bf8837
  3. github-actions commented on Mar 26, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Mar 26, 2025
  5. added a commit that references this issue on Aug 14, 2025
    b135a44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    d: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions