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.
In this repository52 other files it gives its agents.
- academic-research-assistantSkill
- answer-sheetSkill
- app-graphicsSkill
- app-landing-pageSkill
- app-screenshotsSkill
- break-uiSkill
- consumer-app-from-behaviorSkill
- cross-language-safetySkill
- dart-tool-scriptsSkill
- decision-sweepSkill
- engineering-diarySkill
- figma-review-loopSkill
- flutter-app-size-auditSkill
- flutter-async-at-the-edgeSkill
- flutter-async-cubit-safetySkill
- flutter-bloc-clean-architectureSkill
- flutter-clean-architecture-tddSkill
- flutter-cubit-smart-cachingSkill
- flutter-error-logging-conventionsSkill
- flutter-observability-instrumentationSkill
- flutter-paywall-and-review-timingSkill
- flutter-precommit-cleanupSkill
- flutter-router-decisionSkill
- flutter-runtime-safetySkill
- flutter-shorebird-otaSkill
- flutter-strict-analysisSkill
- flutter-web-first-paintSkill
- forced-pivot-15-daySkill
- gplay-consoleSkill
- ios-distribution-feature-flagsSkill
- launch-readinessSkill
- launch-watchSkill
- locale-expert-reviewSkill
- market-pulseSkill
- mobile-ui-referenceSkill
- moscow-prioritizationSkill
- orchestrate-agentic-engineeringSkill
- parallel-agent-inboxSkill
- paywall-conversion-flowSkill
- paywall-transparencySkill
- proactive-crash-repair-loopSkill
- promise-auditSkill
- pr-preview-shippingSkill
- ship-first-dollar-appSkill
- slim-ios-simulator-fleetSkill
- spec-sql-harnessSkill
- store-launch-mastermindSkill
- sync-contextSkill
- task-blitzSkill
- techdebtSkill
- vendor-decisionSkill
- web-interface-reviewSkill
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
- Very specific: line 15
Factory pattern (bad at scale): every repo.watchUser() call returns a new stream → N consumers = N upstream pipelines.
- Very specific: line 32
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 …
- Very specific: line 37
When you have "local search vs remote search" or "free vs paid pipeline," encode the variation as a SearchStrategy interface with two …
- Distinctive: line 41
When the domain is still forming, repetition is cheaper than false generality.
≈ “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.
Files
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:
buildWhenonBlocBuilder— only rebuild when the relevant slice changes. Stops 10x redundant rebuilds during typing/scrolling.listenWhenonBlocListener— 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 havebuildWhen. - All
BlocListeners havelistenWhen. - Search/autocomplete flows use a
Blocwithrestartable(). - No more than one
if (isPro)in any single file.
Sources
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
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.

