sse_channel
0.2.2, released a year ago by jamiewest.dev
Wraps Server‑Sent Events as a StreamChannel for Dart IO and web
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.
- eventflux
A Server-Sent Events client for Dart and Flutter with auto-reconnection.
83Compare - http_multi_server
A dart:io HttpServer wrapper that handles requests from multiple servers.
90Compare - web_socket_channel
Cross‑platform WebSocket channel wrapper for Dart
83Compare - flutter_http_sse
Flutter client library for receiving Server-Sent Events (SSE) over HTTP.
51Compare
Works with
Packages commonly used together with sse_channel: ones it builds on, ones built on it, and its own family.
- uuidsse_channel depends on itGenerates and parses RFC‑4122/9562 UUIDs (v1‑v8) for Dart.
- poolsse_channel depends on itManage a finite pool of resources to control concurrent operations.
- websse_channel depends on itLightweight bindings for browser APIs via JS interop
- asyncsse_channel depends on itUtility classes and helpers that extend Dart's async library.
- loggingsse_channel depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- stream_channelsse_channel depends on itAn abstraction for two-way communication channels based on the Dart Stream class.
- ssesse_channel depends on itBidirectional Server Sent Events client and server for Dart.
- signalr_netcoreBuilt on sse_channelFlutter client for ASP.NET Core SignalR supporting WebSocket, SSE, LongPolling and MessagePack.