Flutter SDKFlushbarRemote.init

FlushbarRemote.init

Initialises the FlushKit SDK, establishes the SSE connection, and starts listening for incoming notifications.

Call this once in the initState of your root widget — the widget that remains mounted for the entire lifecycle of your app.

dart
FlushbarRemote.init(
  apiKey: const String.fromEnvironment('FLUSHKIT_API_KEY'),
  context: context,
);

Parameters

ParameterTypeRequiredDescription
apiKeyStringrequiredYour FlushKit project API key. Starts with fk_live_. You can find it in the API keys tab of your project dashboard.
contextBuildContextrequiredA BuildContext used to display the Flushbar overlay. Must belong to a widget that stays mounted for the lifetime of your app — typically the State of your root MaterialApp widget.
baseUrlString?optionalOverride the API base URL. Defaults to https://api.flushkit.dev. Useful when self-hosting or pointing at a staging environment.
onEventvoid Function(FlushbarRemoteEvent)?optionalCallback fired on each received event before the Flushbar is shown. Receives a FlushbarRemoteEvent. Use this to log analytics or conditionally suppress a notification.

Lifecycle behaviour

The SDK registers a WidgetsBindingObserver to track app lifecycle changes:

  • AppLifecycleState.resumed — the SSE connection is (re)established.
  • AppLifecycleState.paused — the SSE connection is closed to conserve battery and network resources.

The SDK will never maintain a background connection. Notifications sent while the app is paused are queued and delivered when the app resumes (Starter plan and above).

Example

dart
class _RootState extends State<RootWidget> {
  @override
  void initState() {
    super.initState();
    FlushbarRemote.init(
      apiKey: const String.fromEnvironment('FLUSHKIT_API_KEY'),
      context: context,
      onEvent: (event) {
        // Log to your analytics before showing
        analytics.track('notification_received', {
          'title': event.title ?? '',
          'message': event.message,
        });
      },
    );
  }

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

Calling init more than once without calling dispose first will throw a StateError. The SDK is designed as a singleton — one connection per app instance.