AnimationController says the named parameter 'vsync' is wrong or missing
The 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.
Fix it fast
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/2Match what you see, then jump to its fix
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.dart2Fix
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.dartConfirmed by api.flutter.dev
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.dart2Fix
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 runConfirmed by api.flutter.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix