Skip to content

fix: store controller listener for disposal and recreate ticker on restart#34

Open
FinSchuiling wants to merge 1 commit intoben-fornefeld:mainfrom
FinSchuiling:fix/listener-and-ticker-restart
Open

fix: store controller listener for disposal and recreate ticker on restart#34
FinSchuiling wants to merge 1 commit intoben-fornefeld:mainfrom
FinSchuiling:fix/listener-and-ticker-restart

Conversation

@FinSchuiling
Copy link
Copy Markdown

Summary

Two bugs fixed in AnimatedMeshGradient:

  • Stale listener on dispose: The anonymous closure added to controller.isAnimating was never removed in dispose(), causing stale callbacks (and potential setState-after-dispose crashes) when the widget is removed while the controller outlives it. Fix: store the listener reference in _controllerListener and remove it in dispose().

  • Ticker restart assertion: After calling _ticker.stop(), calling _ticker.start() again hits Flutter's "Ticker already started" assertion because a stopped Ticker cannot be restarted. Fix: when the controller requests animation to resume after a stop, create a fresh Ticker via _initTicker() instead of calling start() on the existing one.

Test plan

  • Verify widget disposes cleanly when a controller outlives the widget (no setState after dispose errors)
  • Verify stop → start cycle via controller works without assertion errors
  • Verify animation resumes correctly after stop/start cycle

🤖 Generated with Claude Code

…start

Two bugs fixed:

1. The anonymous closure added to controller.isAnimating was never removed
   in dispose(), causing stale callbacks (and potential setState-after-dispose
   crashes) when the widget is removed while the controller outlives it.

   Fix: store the listener reference in _controllerListener and remove it
   in dispose().

2. After calling _ticker.stop(), calling _ticker.start() again hits
   Flutter's "Ticker already started" assertion because a stopped Ticker
   cannot be restarted.

   Fix: when the controller requests animation to resume after a stop,
   create a fresh Ticker via _initTicker() instead of calling start() on
   the existing one.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant