Flutter SDKEvents stream

Events stream

FlushbarRemote.events exposes a StreamController<FlushbarRemoteEvent> that emits every notification event received from the server — before the Flushbar overlay is displayed.

Use this to run side effects such as analytics tracking, in-app badges, or custom notification logic.

Listening to events

dart
FlushbarRemote.events.stream.listen(
  (event) {
    debugPrint('Received: ${event.message}');

    // Log to analytics
    analytics.track('notification_received', {
      'title': event.title,
      'message': event.message,
      'backgroundColor': event.backgroundColor.value.toRadixString(16),
    });
  },
  onError: (error) {
    // Connection errors surface here
    // The SDK will auto-reconnect
    debugPrint('FlushKit stream error: $error');
  },
);

FlushbarRemoteEvent fields

ParameterTypeRequiredDescription
titleString?optionalOptional notification title shown above the message. Null if no title was provided when sending.
messageStringrequiredThe notification message body. Always present.
backgroundColorColorrequiredBackground color of the Flushbar, parsed from the hex value provided in the notify request.
durationSecondsintrequiredHow long to display the Flushbar in seconds. 0 means the notification persists until dismissed by the user.
positionFlushbarPositionrequiredEither FlushbarPosition.TOP or FlushbarPosition.BOTTOM.

Setting up the listener before init

Subscribe to the stream before calling FlushbarRemote.init to ensure you don't miss the first event:

dart
@override
void initState() {
  super.initState();

  // Subscribe first
  FlushbarRemote.events.stream.listen((event) {
    ref.read(notificationCountProvider.notifier).increment();
  });

  // Then init
  FlushbarRemote.init(
    apiKey: const String.fromEnvironment('FLUSHKIT_API_KEY'),
    context: context,
  );
}

The stream is a broadcast stream — you can attach multiple listeners. Each listener will receive every event independently.