Flutter SDKFlushbarRemote.dispose

FlushbarRemote.dispose

Closes the SSE connection, cancels the reconnection timer, and removes the WidgetsBindingObserver registered by init.

Call this in the dispose method of the same widget that called init.

dart
@override
void dispose() {
  FlushbarRemote.dispose();
  super.dispose();
}

When to call it

In practice, the root widget of a Flutter app is almost never disposed — it lives until the process exits. However, you should still call dispose defensively so the SDK cleans up properly if the widget tree is ever torn down (e.g. in tests, or if you wrap your app in a restart widget).

What it does internally

  1. Closes the SSE EventSource — sends a close signal on the underlying HTTP connection.
  2. Cancels the reconnection timer — stops any pending exponential backoff retry.
  3. Removes the WidgetsBindingObserver — stops reacting to app lifecycle changes.
  4. Resets internal state — allows init to be called again cleanly.

Example

dart
class _RootState extends State<RootWidget> {
  @override
  void initState() {
    super.initState();
    FlushbarRemote.init(
      apiKey: const String.fromEnvironment('FLUSHKIT_API_KEY'),
      context: context,
    );
  }

  @override
  void dispose() {
    FlushbarRemote.dispose(); // Always before super.dispose()
    super.dispose();
  }
}

Calling dispose when the SDK has not been initialised is a no-op — it will not throw.