flutter-async-at-the-edge
Skill1 starsChanged 27 days agoBSD-3-ClauseView on GitHub
Keeps Flutter async work at a Service or Repository edge so views render synchronous sealed state. Use whenever a Flutter screen loads network, Firestore, stream or sensor data. Use for FutureBuilder or StreamBuilder in build(), refetching rebuilds, spinner storms or tests stuck on pumpAndSettle.
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-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-stream-architectureSkill
- 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
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 83
Do not add BlocSignal (package:bloc_signals, Randal Schwartz's BLoC-on-signals library) or package:signals just for this.
- Very specific: line 85
If the project already uses signals, futureSignal is an acceptable edge wrapper.
≈ “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 async at the edge
App state does not live in widgets. Services talk to the network. Repositories retry, cache, and map. ViewModels expose synchronous sealed UI state. Views only switch on that state.
Classify first
- Ephemeral view state (tab index, text field, animation) stays in the widget.
- App state (user, list, subscription, scores) does not.
Ban this
Widget build(BuildContext context) {
return FutureBuilder(
future: api.fetchProfile(id), // new Future every rebuild
builder: ...
);
}Creating the Future in GoRoute.builder has the same refetch bug. Caching the Future in initState plus FutureBuilder still collapses layers and traps data in State.
Official rule: do not create the Future in build(). Community "never use FutureBuilder" is stronger than the docs; follow the architecture below instead of arguing about the widget.
Service at the edge
One class per API. Returns Future/Stream. Holds no cache.
class UserApi {
UserApi(this._client);
final http.Client _client;
Future<UserDto> fetchProfile(String id) =>
_client.get(Uri.parse('$base/users/$id')).then(parse);
}Repository: retry + cache + mapping
final _profileCache = AsyncCache<User>(const Duration(minutes: 5));
Future<User> profile(String id) => _profileCache.fetch(() {
return retry(
() => _api.fetchProfile(id).timeout(const Duration(seconds: 5)),
retryIf: (e) => e is SocketException || e is TimeoutException,
).then(User.fromDto);
});AsyncCacheis frompackage:async, notdart:async.AsyncCache.ephemeral()de-dupes in-flight calls without time-caching.retryIfmust stay false for 401/403/404 or you hammer a dead endpoint.- Catch
Exception, notError.
ViewModel emits sealed state
Load in the constructor / init, not in build. refresh() invalidates the cache then re-fetches.
sealed class ProfileUi { const ProfileUi(); }
class ProfileLoading extends ProfileUi { const ProfileLoading(); }
class ProfileData extends ProfileUi { const ProfileData(this.user); final User user; }
class ProfileError extends ProfileUi { const ProfileError(this.message); final String message; }The View switches on that state only. Zero ConnectionState, zero snapshot.hasError, zero HTTP.
Coordinate a screen with one ViewModel. Do not give each card its own FutureBuilder (spinner storm / layout shift).
Tests
Inject a fake repository that returns User synchronously. Assert widgets on frame 1. Do not mock HTTP in widget tests.
Do not add BlocSignal (package:bloc_signals, Randal Schwartz's BLoC-on-signals library) or package:signals just for this.
Official Views + ViewModels + Repositories is enough.
If the project already uses signals, futureSignal is an acceptable edge wrapper.
Sources
- https://docs.flutter.dev/app-architecture/guide
- https://pub.dev/packages/retry
- https://pub.dev/documentation/async/latest/async/AsyncCache-class.html
- https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html
- https://pub.dev/packages/bloc_signals
- https://github.com/RandalSchwartz/BlocSignal
- https://pub.dev/packages/signals
- https://pub.dev/documentation/signals/latest/signals/futureSignal.html
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.

