agentleFS
MADTeacherMADTeacher/mad-agents-skills/flutter-drift/SKILL.md

flutter-drift

Skill106 starsChanged 7 months agoMITView on GitHub

Implement, fix, review, migrate, test, or debug Drift persistence in Flutter apps using SQLite, drift_flutter, type-safe Dart queries, generated tables, StreamBuilder or Riverpod StreamProvider UI, write operations, transactions, schema migrations, web assets, isolate sharing, and local database testing. Use when a Flutter task mentions drift, local database storage, SQLite, reactive database streams, CRUD, schemaVersion, build_runner, drift_dev make-migrations, migration tests, or Flutter-specific database setup across mobile, web, or desktop.

The file

Show its rules and text

We split this skill into the rules it gives an agent

34 rules. About 0 are common, 14 are distinctive, and 20 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 20

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Use this skill to add or repair Drift-based local persistence in Flutter apps.

    line 11
  2. Very specific:

    Check pubspec.yaml, existing database files, build.yaml, state management package, target platforms, and tests.

    line 16
  3. Distinctive:

    Prefer the app's current architecture and naming over the examples in this skill.

    line 17
  4. Distinctive:

    Add or verify dependencies with package commands instead of hardcoding versions:

    line 18
  5. Very specific:

    Add provider or flutter_riverpod only when the app already uses it or the user asks for that integration.

    line 20
  6. Distinctive:

    Create or update the database entry point:

    line 21
  7. Very specific:

    Add the tables to @DriftDatabase.

    line 23
  8. Distinctive:

    Keep Drift calls scoped to the database object:

    line 25
  9. Very specific:

    Use database.select(database.todoItems), database.into(database.todoItems), database.update(database.todoItems), and …

    line 26
  10. Very specific:

    Use bare select(todoItems) only inside GeneratedDatabase subclasses or DatabaseAccessor classes where the methods and table getters are in …

    line 27
  11. Distinctive:

    Treat generator errors as blockers, not optional cleanup.

    line 30
  12. Very specific:

    Run dart run drift_dev make-migrations before and after schema changes as needed.

    line 33
  13. Very specific:

    Run dart format on edited Dart files.

    line 36
  14. Very specific:

    Run flutter analyze or dart analyze for the package.

    line 37
  15. Distinctive:

    Run targeted tests, including generated migration tests when migrations changed.

    line 38
  16. Distinctive:

    Read references/setup.md when adding Drift, opening a database, configuring web support, or sharing a database across isolates.

    line 42
  17. Distinctive:

    Read references/tables.md when defining tables, columns, defaults, keys, indexes, constraints, generated columns, or strict tables.

    line 43
  18. Distinctive:

    Read references/queries.md when implementing selects, filters, sorting, pagination, joins, aggregations, subqueries, custom columns, or …

    line 44
  19. Distinctive:

    Read references/writes.md when implementing inserts, updates, deletes, upserts, companions, transactions, or batch operations.

    line 45
  20. Distinctive:

    Read references/streams.md when implementing reactive Drift streams, StreamBuilder, StreamProvider, custom select streams, table update …

    line 46
  21. Very specific:

    Read references/migrations.md when schemaVersion, existing user data, build.yaml, make-migrations, generated schema files, or migration …

    line 47
  22. Distinctive:

    Read references/flutter-ui.md when wiring Drift data into Flutter widgets with Provider, Riverpod, StreamBuilder, search, filtering, …

    line 48
  23. Very specific:

    Do not call select(database.table) as a top-level function from a widget.

    line 52
  24. Very specific:

    Do not use watch(...), todoUpdates(...), or notifyTableUpdates(...).

    line 53
  25. Very specific:

    Do not call delete(table).go(id).

    line 54
  26. Very specific:

    Do not use batch.updateAll(...) or pass raw ids to batch.delete(...).

    line 55
  27. Very specific:

    Do not mix Provider and Riverpod APIs.

    line 56
  28. Very specific:

    Do not bump schemaVersion without a migration plan for existing databases.

    line 57
  29. Very specific:

    Do not rely on raw SQLite writes when UI streams must update.

    line 58
  30. Very specific:

    If package downloads are blocked, update source files and leave exact dart pub add or flutter pub add commands for the user, then state …

    line 62
  31. Very specific:

    If a project cannot run build_runner, do not hand-write generated *.g.dart files.

    line 63
  32. Very specific:

    If migration state is unclear, stop before changing schemaVersion.

    line 64
  33. Very specific:

    If web support is required but sqlite3.wasm and drift_worker.js are missing, add the code path and explicitly report the required web …

    line 65
  34. Distinctive:

    All query and write examples are scoped to the correct database/accessor context.

    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 Drift

Use this skill to add or repair Drift-based local persistence in Flutter apps. The skill is an operating workflow: inspect the target app first, choose only the relevant reference files, implement with current Drift APIs, and validate generated code.

Core Workflow

  1. Inspect the app before editing:
    • Check pubspec.yaml, existing database files, build.yaml, state management package, target platforms, and tests.
    • Prefer the app's current architecture and naming over the examples in this skill.
  2. Add or verify dependencies with package commands instead of hardcoding versions:
    • dart pub add drift drift_flutter path_provider dev:drift_dev dev:build_runner
    • Add provider or flutter_riverpod only when the app already uses it or the user asks for that integration.
  3. Create or update the database entry point:
    • Define tables in Dart or .drift files.
    • Add the tables to @DriftDatabase.
    • Open Flutter databases with driftDatabase from package:drift_flutter/drift_flutter.dart unless the project needs a custom executor.
  4. Keep Drift calls scoped to the database object:
    • Use database.select(database.todoItems), database.into(database.todoItems), database.update(database.todoItems), and database.delete(database.todoItems) from widgets, services, and repositories.
    • Use bare select(todoItems) only inside GeneratedDatabase subclasses or DatabaseAccessor classes where the methods and table getters are in scope.
  5. Generate code after changing Drift declarations:
    • Run dart run build_runner build.
    • Treat generator errors as blockers, not optional cleanup.
  6. For schema changes in an existing app, use Drift's guided migration workflow:
    • Configure drift_dev databases in build.yaml.
    • Run dart run drift_dev make-migrations before and after schema changes as needed.
    • Bump schemaVersion, write generated step-by-step migrations, and run generated migration tests.
  7. Validate before finishing:
    • Run dart format on edited Dart files.
    • Run flutter analyze or dart analyze for the package.
    • Run targeted tests, including generated migration tests when migrations changed.

Resource Routing

  • Read references/setup.md when adding Drift, opening a database, configuring web support, or sharing a database across isolates.
  • Read references/tables.md when defining tables, columns, defaults, keys, indexes, constraints, generated columns, or strict tables.
  • Read references/queries.md when implementing selects, filters, sorting, pagination, joins, aggregations, subqueries, custom columns, or unions.
  • Read references/writes.md when implementing inserts, updates, deletes, upserts, companions, transactions, or batch operations.
  • Read references/streams.md when implementing reactive Drift streams, StreamBuilder, StreamProvider, custom select streams, table update listeners, or manual stream invalidation.
  • Read references/migrations.md when schemaVersion, existing user data, build.yaml, make-migrations, generated schema files, or migration tests are involved.
  • Read references/flutter-ui.md when wiring Drift data into Flutter widgets with Provider, Riverpod, StreamBuilder, search, filtering, pagination, or user-facing loading and error states.

Required API Rules

  • Do not call select(database.table) as a top-level function from a widget. Use database.select(database.table) outside database classes.
  • Do not use watch(...), todoUpdates(...), or notifyTableUpdates(...). Use customSelect(...).watch(), tableUpdates(...), and notifyUpdates(...).
  • Do not call delete(table).go(id). Add a where clause and then call go(), or use generated table extension helpers if the project already uses them.
  • Do not use batch.updateAll(...) or pass raw ids to batch.delete(...). Use batch.update(..., where: ...), batch.delete(...) with an insertable row, or batch.deleteWhere(...).
  • Do not mix Provider and Riverpod APIs. Provider.of<AppDatabase>(context) belongs to provider; Provider<AppDatabase>((ref) { ... }) and AsyncValue.when(...) belong to Riverpod.
  • Do not bump schemaVersion without a migration plan for existing databases.
  • Do not rely on raw SQLite writes when UI streams must update. Use Drift write APIs or call notifyUpdates with explicit TableUpdate metadata.

Fallbacks

  • If package downloads are blocked, update source files and leave exact dart pub add or flutter pub add commands for the user, then state that dependency resolution was not validated.
  • If a project cannot run build_runner, do not hand-write generated *.g.dart files. Fix source declarations and report the generator blocker.
  • If migration state is unclear, stop before changing schemaVersion; ask for the current released schema history or database files.
  • If web support is required but sqlite3.wasm and drift_worker.js are missing, add the code path and explicitly report the required web assets.

Validation Checklist

  • pubspec.yaml contains Drift runtime and generator dependencies.
  • Database files have valid part directives, table declarations, @DriftDatabase, constructor, and schemaVersion.
  • All query and write examples are scoped to the correct database/accessor context.
  • Generated code was rebuilt with build_runner.
  • Flutter UI examples handle loading, empty, error, and data states without treating AsyncValue as a List.
  • Migrations changed only with generated schema snapshots, step-by-step migration code, and tests.
  • flutter analyze or dart analyze passes for the edited package, or any remaining analyzer failure is reported with the blocker.

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.