/flutter:data-export-and-restorefrom Flutter Skills
Governs user-facing data portability in offline-first apps: enforces strict separation between backup/restore (exact, round-trippable) and export/report (lossy, human-readable), versioned envelopes with checksums, staging-database restore, CSV/JSON/PDF output with formula-injection escaping, and round-trip tests.
Ships in Flutter Skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
In an app with no server, the export file is the only copy of a user's data that can
outlive the phone, and restore is the only recovery path they can invoke themselves.
Both are dangerous in opposite directions: a lossy export silently becomes someone's
backup, and a half-applied restore destroys the very database it was meant to protect.
This skill governs the portable artifacts; the on-device VACUUM INTO snapshot and
WAL rules belong to persistence-drift.
Depth lives in references/formats-and-encoding.md (CSV/JSON/PDF mechanics) and
references/restore-and-merge-policy.md (validation ladder, merge strategies).
formatVersion,
schemaVersion, appVersion, exportedAtUtc, a checksum over the payload, then the
payload. Restore verifies the checksum, refuses schemaVersion greater than the
app's with a plain message, and migrates an older payload through the same
forward-only path as the database (run-migration). WHY: an unversioned file cannot
be refused, only misread.١٢٫٥ and 12.5 and 12,5 are the same quantity and three different parses.updatedAtUtc) are different
promises; the confirmation names which one is about to happen and what will be lost.
WHY: "Restore" reads as "add my data back" to a user who is about to lose a week.IOSink
into the app's own temp directory and rename it into place only when the last byte
is flushed. WHY: a 100k-row export assembled in a String OOMs a cheap phone, and a
half-written file must never be shareable.ShareGateway/FileExportGateway
(service-boundary-and-native), faked in tests.=, +, -, @, tab or CR so a spreadsheet renders the text instead of
executing it. WHY: an unescaped cell is a code-execution vector in the recipient's
spreadsheet, and a lost row in yours.Result<ExportArtifact, ExportFailure> / Result<RestoreReport, RestoreFailure>
with a distinct failure per refusal reason (checksum, unsupported version,
malformed payload, no space, permission denied). WHY: "Restore failed" with no
reason is indistinguishable from data loss to the person reading it.release-and-store-shipping for claim wording)./// The only shape restore accepts. Version fields come FIRST so a truncated or
/// foreign file is rejected by the header rather than by a mid-parse exception.
({
int formatVersion, // this envelope's own shape — bump independently of the DB
int schemaVersion, // the DB schema the payload was written from
String appVersion, // provenance for support, never a compatibility check
DateTime exportedAtUtc, // UTC, from the injected Clock
String payloadSha256, // checksum over the payload bytes, verified before parsing
Map<String, Object?> payload,
});
formatVersion and schemaVersion are separate on purpose: the envelope can gain a
field without a database migration, and the database can migrate without changing the
file shape. A single "version" number conflates them and forces a false choice on the
next change. Complete, runnable shape: examples/backup_envelope.dart.
Future<Result<RestoreReport, RestoreFailure>> restore(File picked) async {
// 1. Header and integrity BEFORE anything is parsed or opened.
final envelope = readEnvelope(picked);
switch (envelope) {
case Err(:final failure): return Err(failure); // malformed / bad checksum
case Ok(:final value) when value.schemaVersion > kSchemaVersion:
return const Err(RestoreFailure.newerThanApp()); // refuse, never guess
case Ok():
break;
}
// 2. Import into a STAGING database — the live one is never touched yet.
final staging = await openStagingDatabase();
final imported = await staging.transaction(() => _importAll(envelope.value.payload));
if (imported case Err(:final failure)) {
await staging.close();
await deleteStagingFiles(); // user's data still intact
return Err(failure);
}
// 3. Migrate the staged copy forward through the SAME path as the app database.
// 4. Close every handle, then publish by rename, keeping the old file until the
// new one opens cleanly. See references/restore-and-merge-policy.md.
return publishStagedDatabase(staging);
}
The staging file, the migration path, and the rename ordering are the whole correctness argument — a restore that writes directly into the open app database has no failure mode that leaves the user where they started.
| Need | Format | Restorable? |
|---|---|---|
| Full-fidelity backup the app reads back | Envelope + JSON payload (or a copied DB file) | Yes — the only one |
| Rows for a spreadsheet or another tool | CSV, RFC 4180, canonical values | No |
| Something a human reads, prints, or files | PDF, fully localized and formatted | No |
Human-facing exports localize at the edge like any other rendering
(value-objects-money-and-units, i18n-rtl-l10n); machine formats never do. Copying
the live database file directly is a valid backup only through the WAL-safe primitive
in persistence-drift — never File.copy on an open database.
'test1'
survives everything and proves nothing.schemaVersion
one higher than the app, an older schemaVersion that must migrate, empty payload,
and a file that is not this format at all. Each asserts the typed failure and that
the live database is byte-unchanged.=cmd(), one containing a,b"c\nd, and an RTL
cell each survive a write→read round trip through a real parser.String/StringBuffer — fine for 100 rows, an OOM
crash at 100k, on the cheapest device you support.formatVersion, schemaVersion, appVersion,
exportedAtUtc, and a payload checksum, in that header-first order.schemaVersion, and migrates an
older payload through the same forward-only path as the database.Results with one failure per refusal reason.persistence-drift — the WAL-safe on-device snapshot primitive and the DAO layer the
importer writes through; never File.copy a live database.run-migration — the forward-only path an older payload is migrated through.error-handling-typed-results — the Result/Failure spine and the never-lose-data
guarantees this feature is the user-facing end of.value-objects-money-and-units — canonical storage (minor units, SI, UTC) that makes
a machine format round-trip.i18n-rtl-l10n — localize-at-render, and why localized numerals never enter a file.service-boundary-and-native — the ShareGateway/file-picker seam and its fake.release-and-store-shipping — the privacy claims an export feature must not break.testing-strategy — hostile fixtures, property/round-trip tests, injected Clock.dart:io IOSink, File.rename: https://api.dart.dev/stable/dart-io/File-class.htmlpath_provider — app directories: https://pub.dev/packages/path_providershare_plus — share sheet (incl. sharePositionOrigin): https://pub.dev/packages/share_plusfile_selector — save/open dialogs: https://pub.dev/packages/file_selectorcrypto — SHA-256 for the payload checksum: https://pub.dev/packages/cryptoWhat SKILL.md sets; muted values are Claude Code's defaults
40 skills in this plugin
/accessibility-as-codeEnforces accessibility as a correctness property authored into each widget — Semantics(button/label) or ExcludeSemantics on every node, a11y state read from MediaQuery not app state, never MediaQuery.withClampedTextScaling / textScaleFactor / FittedBox / TextOverflow.ellipsis to fit a label, non-color redundant channels (icon+label+shape+text) for every state, contrast against composited backgrounds (4.5:1 body / 3:1 large), 44px single-tap targets, OrdinalSortKey traversal, and honoring boldText / reduce-motion. Use when adding a GestureDetector/InkWell or any tap target, adding an Icon or Image, reaching for withClampedTextScaling/FittedBox/ellipsis/textScaleFactor to make text fit, encoding state via color, sizing type, ordering focus traversal, or reviewing any View for screen-reader/switch/low-vision support./adaptive-layoutEnforces adapting layout by available CONSTRAINTS/size, never device or platform checks — LayoutBuilder + MediaQuery.sizeOf/paddingOf/viewInsetsOf (not .of) for narrow rebuilds, Material 3 window size classes (compact <600, medium 600-840, expanded 840-1200, large >1200) as the breakpoint vocabulary, navigation affordance chosen by width (NavigationBar → NavigationRail → NavigationDrawer), list-detail single-pane-vs-two-pane, readable max-width via ConstrainedBox, Flexible/Expanded/FractionallySizedBox over fixed widths, SafeArea + display cutouts + keyboard insets, never lock orientation, foldable/hinge awareness via MediaQuery.displayFeatures, and golden-matrix verification across sizes. Use when building responsive or adaptive UI, tablet/desktop/foldable support, master-detail or two-pane screens, a NavigationRail-vs-BottomNav shell, breakpoints, LayoutBuilder, MediaQuery sizing, SafeArea/cutouts, or fixing overflow at large widths.npx claudepluginhub zakariaf/flutter-skills --plugin flutterOther plugins' skills for the same job