agentleFS
mikezamayiasmikezamayias/agent-skills/skills/flutter-runtime-safety/SKILL.md

flutter-runtime-safety

Skill1 starsChanged 26 days agoBSD-3-ClauseView on GitHub

Catches the errors that escape try-catch and prevents stale-data crashes. Use when wiring crash reporting, hardening release builds, or debugging "impossible" production crashes.

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If the app should still survive a phone change, replace the silent restore with an explicit backup and restore screen, so the user chooses …

    line 57
  2. Distinctive:

    Before a restore replaces local data, save the current data first as its own restorable copy.

    line 60
  3. Very specific:

    When the app backgrounds, timers and streams keep running.

    line 65
  4. Distinctive:

    If the app offers its own backup and restore, test the round trip on a second device or after a reinstall: back up, wipe, restore, and …

    line 71

≈ “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 Runtime Safety

Three invisible bugs sink most production Flutter apps. Each takes 10 minutes to fix and prevents days of forensic debugging.

1. FlutterError.onError + PlatformDispatcher.onError - error boundary for the whole app

try/catch only catches synchronous errors and awaited futures. Fire-and-forget futures, microtasks, and timers escape. Flutter routes framework errors to FlutterError.onError and errors raised outside Flutter callbacks to PlatformDispatcher.instance.onError. SentryFlutter.init hooks both automatically on Flutter 3.3+, so start the app through appRunner instead of wrapping main() in runZonedGuarded:

Future<void> main() async {
  await SentryFlutter.init(
    (options) => options.dsn = const String.fromEnvironment('SENTRY_DSN'),
    appRunner: () => runApp(const App()),
  );
}

Without an SDK that installs the hooks, set both yourself:

FlutterError.onError = (details) {
  FlutterError.presentError(details);
  report(details.exception, details.stack);
};
PlatformDispatcher.instance.onError = (error, stack) {
  report(error, stack);
  return true;
};

Now any unhandled async error gets reported, not silently dropped.

2. android:allowBackup — the manifest line that resurrects bugs

By default, Android backs up SharedPreferences and local database files, such as drift or Hive, and restores them on a new install. Users hit a bug, uninstall, and reinstall, and the corrupt state comes back with them. Set in AndroidManifest.xml:

<application android:allowBackup="false" ...>

On Android 12+ some manufacturers still run device-to-device transfer when allowBackup="false", so also exclude the data in the <device-transfer> section of android:dataExtractionRules.

Or write a first-launch migration that clears stale keys.

  • If the app should still survive a phone change, replace the silent restore with an explicit backup and restore screen, so the user chooses what comes back. Android Auto Backup keeps one backup per app user, up to 25 MB, in a private Drive folder that the user and other apps cannot read, and each new backup replaces the last (Android Developers, "Back up user data with Auto Backup", read 2026-11-04). One indie habit app's announced Google Drive backup shows a different design: a visible backup list with the date, habit count and device, a "Back up now" button, an export to a file, and a restore dialog that states how many records will replace the current data (maker's promo video, not a shipped build, single report).
  • Before a restore replaces local data, save the current data first as its own restorable copy. The same promo's dialog does this, and it also warns that the saved copy may need repair if it already held damaged data, so do not promise that the safety copy is restorable.

3. WidgetsBindingObserver — pause heavy work in background

When the app backgrounds, timers and streams keep running. Battery drain, websocket reconnect storms, and "ghost" notifications follow. Implement the observer in your root state and pause cubits/streams on AppLifecycleState.paused.

Verification

  • Force an unhandled error in a Future.delayed callback → confirm Sentry receives it.
  • Install on a device with an old version that had a known bad state → confirm clean state on reinstall.
  • If the app offers its own backup and restore, test the round trip on a second device or after a reinstall: back up, wipe, restore, and compare the record counts. Also restore a backup that was made from a state you know is corrupt, and confirm the app either repairs it or refuses with a clear message instead of crashing.
  • Profile battery usage with the app backgrounded for 1 hour → no spikes.

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.