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
| Parameter | Type | Required | Description |
|---|---|---|---|
title | String? | optional | Optional notification title shown above the message. Null if no title was provided when sending. |
message | String | required | The notification message body. Always present. |
backgroundColor | Color | required | Background color of the Flushbar, parsed from the hex value provided in the notify request. |
durationSeconds | int | required | How long to display the Flushbar in seconds. 0 means the notification persists until dismissed by the user. |
position | FlushbarPosition | required | Either 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.