agentleFS
mikezamayiasmikezamayias/agent-skills/skills/flutter-stream-architecture/SKILL.md

flutter-stream-architecture

Skill1 starsChanged 26 days agoBSD-3-ClauseView on GitHub

Designs Flutter/Bloc stream layers that scale. Use when seeing duplicate API calls, redundant rebuilds, or when reviewing repository/cubit boundaries.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Factory pattern (bad at scale): every repo.watchUser() call returns a new stream → N consumers = N upstream pipelines.

    line 15
  2. Very specific:

    If a flow stays a Cubit, give the method that owns the debounce Timer one shared timer field, cancel it on every immediate path and in …

    line 32
  3. Very specific:

    When you have "local search vs remote search" or "free vs paid pipeline," encode the variation as a SearchStrategy interface with two …

    line 37
  4. Distinctive:

    When the domain is still forming, repetition is cheaper than false generality.

    line 41

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Flutter Stream Architecture

Architectures that scale treat streams as infrastructure, not factories. The mistake most teams make is creating a fresh stream per consumer — a "factory" — which silently triggers duplicate upstream pipelines (DB queries, websockets, API polls).

The shift

  • Factory pattern (bad at scale): every repo.watchUser() call returns a new stream → N consumers = N upstream pipelines.
  • Multicast pattern (good): repository owns one upstream stream and broadcasts to all consumers via BehaviorSubject / StreamController.broadcast() / rxdart.

Wrap the upstream once. Cache the latest value. Replay it to new subscribers.

Rebuild discipline

In Bloc/Cubit, two flags matter:

  • buildWhen on BlocBuilder — only rebuild when the relevant slice changes. Stops 10x redundant rebuilds during typing/scrolling.
  • listenWhen on BlocListener — only fire side effects on transitions, not every state change.

Pair with the restartable() event transformer from bloc_concurrency for search/typing flows so a new event abandons the running handler and its later emit calls are dropped. restartable() is switchMap from stream_transform, and it does not abort the repository request itself (inference from the source), so only the newest result reaches the state. bloc_concurrency has no debounce transformer, so add one from stream_transform (debounce) in the event transformer for typing events. droppable() does the opposite: it ignores new events while one is processing. Event transformers apply to Bloc only, so use a Bloc rather than a Cubit for these flows. If a flow stays a Cubit, give the method that owns the debounce Timer one shared timer field, cancel it on every immediate path and in close(), and add a sequence number so only the latest awaited search emits (see flutter-async-cubit-safety). Say in the code that this is the price of keeping a Cubit.

Strategy pattern over conditionals

When you have "local search vs remote search" or "free vs paid pipeline," encode the variation as a SearchStrategy interface with two implementations. Don't grow if (isPro) branches inside the cubit — that's where bugs live.

Don't abstract too early

When the domain is still forming, repetition is cheaper than false generality. Wait until you have 3 concrete examples before extracting an abstraction. Premature interfaces create the wrong contract and have to be torn out anyway.

Review checklist

  • No repository.watchX() returns a fresh stream per call.
  • All BlocBuilders have buildWhen.
  • All BlocListeners have listenWhen.
  • Search/autocomplete flows use a Bloc with restartable().
  • No more than one if (isPro) in any single file.

Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.