AnimationController not disposed properly

AnimationController.dispose() called more than once.

Quick Answer

An AnimationController was disposed multiple times or used after disposal.

Why This Happens

In Flutter, an AnimationController must be disposed exactly once in the dispose() method. Double disposal or using the controller after dispose throws an error. Ensure dispose is called once and no animations continue after the widget is removed.

The Problem

class _MyState extends State<MyWidget>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  void onButtonPressed() {
    _controller.dispose(); // Don't dispose here!
    _controller.forward(); // Used after dispose!
  }
}

The Fix

class _MyState extends State<MyWidget>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  void onButtonPressed() {
    _controller.reset();
    _controller.forward();
  }

  @override
  void dispose() {
    _controller.dispose(); // Dispose only here
    super.dispose();
  }
}

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error about AnimationController disposal. This means the controller was disposed incorrectly.

  2. 2

    Find the cause

    Check if dispose() is called manually outside the widget's dispose method, or if the controller is used after disposal.

  3. 3

    Apply the fix

    Only dispose the AnimationController in the widget's dispose() method, and use reset() or stop() for other lifecycle events.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free