✅ Solved: [Flutter] Unable to stop embedded audio in .riv animation after widget removal or contr...

I'm developing a Flutter app where I use .riv animations that include embedded audio tracks (e.g., sound effects tied to animation states). The issue I'm facing is:

When I exit the screen (via onCardExit() in Flutter) and remove the RiveAnimation.network widget from the widget tree using setState(() => _showRive = false), the animation disappears as expected, but the embedded audio continues to play in the background.

Here’s a summary of what I’m doing in onCardExit():

  • Remove Rive widget from tree with setState(() => _showRive = false)

  • Call dispose() on all StateMachineController instances via a custom RiveControllerManager

Despite all of the above, the sound that was embedded directly in the .riv file continues to play for several seconds after the animation widget is removed.