Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

AnimationController says the named parameter 'vsync' is wrong or missing

ErrorThe named parameter 'vsync' isn't defined.

Short answer

An AnimationController needs a TickerProvider passed as vsync. Normally the State object plays that role: add SingleTickerProviderStateMixin to the State class and pass vsync: this. A State that creates several controllers over its life needs TickerProviderStateMixin instead.

  • Applies to Flutter 3.x stable, Dart 3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place a controller is built and see which class it sits in. The class must be a State with a ticker mixin.

    grep -rn "AnimationController(" lib/
  2. 2Match what you see, then jump to its fix

    1. 1vsync: this is rejected because the State is not a TickerProviderThe State class has no ticker mixinFix
    2. 2The mixin is there, but a second AnimationController in the same State fails at run timeOne State owns several controllers, or recreates themFix

What does the error look like?

  • The named parameter 'vsync' isn't defined.
  • AnimationController(vsync: this) is rejected inside a State class

Cause 1 of 2

The State class has no ticker mixin

1Check

Look at the class declaration that contains the controller. A plain State<MyWidget> is not a TickerProvider.

grep -n "extends State<" lib/my_widget.dart

2Fix

Add the mixin to the State class and pass this as vsync. Create the controller where it can use this, and dispose it.

class _MyWidgetState extends State<MyWidget>
    with SingleTickerProviderStateMixin {
  late final AnimationController _controller = AnimationController(
    vsync: this,
    duration: const Duration(milliseconds: 300),
  );

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}

3Verify

The analyzer reports no error on the vsync line.

flutter analyze lib/my_widget.dart

Confirmed by api.flutter.dev

Did this fix it?

Cause 2 of 2

One State owns several controllers, or recreates them

1Check

SingleTickerProviderStateMixin vends only one ticker. Count the controllers created in the State over its lifetime.

grep -c "AnimationController(" lib/my_widget.dart

2Fix

Swap the mixin for TickerProviderStateMixin, which is meant for a State that may have several controllers.

class _MyWidgetState extends State<MyWidget>
    with TickerProviderStateMixin {
  // several AnimationController(vsync: this, ...) are fine here
}

3Verify

Hot restart the screen and run both animations.

flutter run

Confirmed by api.flutter.dev

Did this fix it?

How do I stop it coming back?

  • Dispose every controller in State.dispose.
  • Use one controller per animation concern and keep it in the State that shows it.
  • Prefer an implicit animation widget (AnimatedContainer and similar) when you only need a simple transition.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.