Search packages, repositories and app categories

Package detailsv2.0.3

flutter_client_sse

Dart package to help consume SSE API. It consumes server sent events by returning parsed model of the event, id, and the data

AndroidiOSWebmacOSWindowsLinux
30-day downloads
45.3K
Likes
110
Pub points
150

Install package

flutter pub add flutter_client_sse

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Dart package designed to simplify consumption of Server-Sent Events (SSE) APIs in Flutter applications. It streams event data from a server, parsing each event into structured components such as the event type, ID, and payload. Ideal for real-time updates like live notifications, stock prices, or chat messages, it supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux. The package abstracts low-level HTTP handling, providing a clean interface for developers to react to incoming events.

Use cases

  • Real-time notifications
  • Live data streaming
  • Chat applications
  • Stock price updates
  • Status monitoring
  • Event-driven UIs

Key features

  • Parses event ID, type, and data
  • Supports cross-platform deployment
  • Stream-based event handling
  • Simple API integration
  • Automatic reconnection attempts
  • Model-based response parsing

Suitable for

  • Real-time app development
  • Backend-to-frontend event communication
  • Apps requiring live updates
  • Developers using SSE APIs
  • Cross-platform projects with live data

Considerations

  • Requires server-side SSE support
  • Limited to one-way server-to-client communication
  • May need custom error handling
  • Not suitable for bidirectional communication
  • Depends on stable network connection

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Flutter Client SSE

Dart package to help consume Server Sent Events

Features:
  • Consumes server sent events
  • Returns parsed model of the event, id and the data

Getting Started

Import

Add the following import in the pubspec.yaml file

client_sse:
    git:
      url: https://github.com/pratikbaid3/flutter_client_sse
      path:
Example
///GET REQUEST
SSEClient.subscribeToSSE(
    method: SSERequestType.GET,
    url:
    'http://192.168.1.2:3000/api/activity-stream?historySnapshot=FIVE_MINUTE',
    header: {
        "Cookie":
        'jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2NDMyMTAyMzEsImV4cCI6MTY0MzgxNTAzMX0.U0aCAM2fKE1OVnGFbgAU_UVBvNwOMMquvPY8QaLD138; Path=/; Expires=Wed, 02 Feb 2022 15:17:11 GMT; HttpOnly; SameSite=Strict',
        "Accept": "text/event-stream",
        "Cache-Control": "no-cache",
    }).listen((event) {
        print('Id: ' + event.id!);
        print('Event: ' + event.event!);
        print('Data: ' + event.data!);
    },
);

///POST REQUEST
SSEClient.subscribeToSSE(
    method: SSERequestType.POST,
    url:
    'http://192.168.1.2:3000/api/activity-stream?historySnapshot=FIVE_MINUTE',
    header: {
        "Cookie":
        'jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2NDMyMTAyMzEsImV4cCI6MTY0MzgxNTAzMX0.U0aCAM2fKE1OVnGFbgAU_UVBvNwOMMquvPY8QaLD138; Path=/; Expires=Wed, 02 Feb 2022 15:17:11 GMT; HttpOnly; SameSite=Strict',
        "Accept": "text/event-stream",
        "Cache-Control": "no-cache",
    },
    body: {
        "name": "Hello",
        "customerInfo": {"age": 25, "height": 168}
    }).listen((event) {
            print('Id: ' + event.id!);
            print('Event: ' + event.event!);
            print('Data: ' + event.data!);
    },
);

Running Sample Backend

Nest The backend is in NestJS serving a single SSE api.

Installation

$ yarn install

Running the app

# development
$ yarn run start

# watch mode
$ yarn run start:dev

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.