Skip to content
pubscout

sse_channel

0.2.2, released a year ago by jamiewest.dev

Wraps Server‑Sent Events as a StreamChannel for Dart IO and web

WASM-ready
$ flutter pub add sse_channel
Source repository

What it does

Provides a spec‑aligned SSE client that exposes events as MessageEvent objects and a unified StreamChannel API. It handles reconnection, retry hints, and Last‑Event‑ID automatically.

AI-written summary of version 0.2.2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to consume an SSE endpoint in a Flutter or Dart app
  • You want event metadata (id, event name) in addition to payload
  • You need a testable, mockable SSE client
  • You prefer a single API for both VM and web platforms

Skip it when

  • You only need simple HTTP requests or WebSocket communication
  • Your server uses a different push protocol (e.g., MQTT, gRPC)

Strengths

  • Spec‑compliant IO implementation with automatic reconnection
  • Unified StreamChannel API for both VM and web
  • Built‑in test support via HtmlSseChannel.test and injectable IO channel
  • Rich event objects with data, event name, and id

Weaknesses

  • Only supports SSE, not other push protocols
  • Requires awaiting channel.ready before use
  • No custom header configuration exposed

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
8
import 'dart:convert';
import 'package:sse_channel/sse_channel.dart';

Future<void> main() async {
  final channel = SseChannel.connect(Uri.parse('https://sse.dev/test'));
  await channel.ready;
  channel.stream.listen((event) {
    print('[${event.event}] ${event.data} (id: ${event.id})');
  });
  channel.sink.add(jsonEncode({'type': 'ping'}));
  await channel.sink.close();
}

Alternatives

Packages that do the same job and could replace sse_channel.

Works with

Packages commonly used together with sse_channel: ones it builds on, ones built on it, and its own family.