agentleFS
mikezamayiasmikezamayias/agent-skills/skills/flutter-async-at-the-edge/SKILL.md

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.

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
  1. Very specific:

    Do not add BlocSignal (package:bloc_signals, Randal Schwartz's BLoC-on-signals library) or package:signals just for this.

    line 83
  2. Very specific:

    If the project already uses signals, futureSignal is an acceptable edge wrapper.

    line 85

≈ “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 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);
});
  • AsyncCache is from package:async, not dart:async.
  • AsyncCache.ephemeral() de-dupes in-flight calls without time-caching.
  • retryIf must stay false for 401/403/404 or you hammer a dead endpoint.
  • Catch Exception, not Error.

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

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.