flutter-bloc-stream-tracking

Track real-time streams in Flutter Bloc with emit.forEach and connection states.

Updated May 16, 2026
One-click install
npx skills add https://github.com/abdallhMoukdad/flutter-bloc-skills --skill flutter-bloc-stream-tracking
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flutter-bloc-stream-tracking
Source: https://github.com/abdallhMoukdad/flutter-bloc-skills/tree/main/skills/flutter-bloc-stream-tracking
Command: npx skills add https://github.com/abdallhMoukdad/flutter-bloc-skills --skill flutter-bloc-stream-tracking

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the challenge of wiring server-pushed real-time events into a Flutter Bloc without leaking subscriptions or creating confusing state transitions.

Core Features & Use Cases

  • Stream-to-state wiring with emit.forEach: Subscribes inside an event handler so the subscription lifetime is tied to the handler and Bloc close lifecycle.
  • Explicit connection lifecycle states: Separates Connecting, Connected, Reconnecting, Disconnected, and a terminal Closed state for UI correctness.
  • Repository-owned transport and reconnection: Keeps retry/backoff/transport details in the Repository while the Bloc focuses on state flow.
  • Disconnect done safely: Stops tracking by closing the upstream stream via the Repository rather than trying to terminate another handler’s work.

Quick Start

Ask the AI to generate the Bloc event handlers, freezed states, and view wiring for a real-time order tracking screen using emit.forEach with restartable connect and a Closed terminal state.

Frequently Asked Questions about flutter-bloc-stream-tracking

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle real-time websocket streams in a Flutter Bloc without leaking subscriptions?

To handle real-time websocket streams in a Flutter Bloc without leaking subscriptions, use emit.forEach inside an event handler. This ties the stream subscription lifetime directly to the handler and Bloc close lifecycle, preventing memory leaks and confusing state transitions.

What is the best way to manage connection states for a live tracking feature in Flutter?

The best way to manage connection states for live tracking in Flutter is defining explicit state variants. Separate your connection lifecycle into Connecting, Connected, Reconnecting, Disconnected, and a terminal Closed state to ensure UI correctness during server-pushed event streams.

How do I safely disconnect a WebSocket stream from a Flutter Bloc?

To safely disconnect a WebSocket stream from a Flutter Bloc, close the upstream stream via the Repository. The Repository should own the transport and stream lifetime, stopping tracking cleanly rather than trying to terminate another handler’s work directly.

Where should I put retry and backoff logic for a Flutter real-time chat application?

Retry and backoff logic for a Flutter real-time chat application belongs in the Repository. The Repository owns transport and reconnection details, keeping the Bloc focused purely on state flow while the Repository handles complex retry mechanisms.

Why does my Flutter Bloc stream subscription cause duplicate state updates when reconnecting?

Duplicate state updates during reconnection often happen when stream subscriptions are not tied to the handler lifecycle. Using emit.forEach within a restartable ConnectRequested handler ensures the previous subscription is properly canceled before starting a new one.