didChangeAppLifecycleState method

  1. @override
void didChangeAppLifecycleState(
  1. AppLifecycleState state
)
override

Pauses or resumes the SSE connection in response to app lifecycle events.

The connection is closed when the app is backgrounded (AppLifecycleState.paused) and re-established when it returns to the foreground (AppLifecycleState.resumed), preventing unnecessary battery drain.

Implementation

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
  switch (state) {
    case AppLifecycleState.resumed:
      _connect();
      break;
    case AppLifecycleState.paused:
      _disconnect();
      break;
    default:
      break;
  }
}