How to properly manage AntSDK WebSocket connections in Flutter when navigating away from a page
Issue
I'm developing a Flutter app using AntSDK and encountering an issue with WebSocket connection management:
- When I initiate an AntSDK connection on a page and navigate away before the WebSocket connection completes
- The AntSDK continues attempting to connect in the background
- When the connection eventually completes, the Ant audio gets stuck in the app
- If I return to the original page, there's an audio overlap issue, as if both old and new Ant instances are running simultaneously
What I need:
-
Terminate the WebSocket connection when navigating away from the page
-
Completely clear the Ant instance when not in use
-
Stop all AntSDK-related processes when not on that page
What I've tried
dart
@OverRide
void dispose() {
// I've tried using the standard dispose method but it doesn't solve the issue
super.dispose();
}
Questions
- What is the correct way to disconnect AntSDK and stop all processes when navigating away from a page?
- Is there a specific method needed to directly close the WebSocket connection?
- Are there any best practices for managing the lifecycle of AntSDK in a Flutter app?
Thank you!