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.
In this repository10 other files it gives its agents.
- agents-md-generatorSkill
- dart-driftSkill
- flutter-adaptive-uiSkill
- flutter-animationsSkill
- flutter-architectureSkill
- flutter-duit-bduiSkill
- flutter-internationalizationSkill
- flutter-navigationSkill
- flutter-networkingSkill
- flutter-testingSkill
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
- Distinctive: line 11
Use this skill to add or repair Drift-based local persistence in Flutter apps.
- Very specific: line 16
Check pubspec.yaml, existing database files, build.yaml, state management package, target platforms, and tests.
- Distinctive: line 17
Prefer the app's current architecture and naming over the examples in this skill.
- Distinctive: line 18
Add or verify dependencies with package commands instead of hardcoding versions:
- Very specific: line 20
Add provider or flutter_riverpod only when the app already uses it or the user asks for that integration.
- Distinctive: line 21
Create or update the database entry point:
- Very specific: line 23
Add the tables to @DriftDatabase.
- Distinctive: line 25
Keep Drift calls scoped to the database object:
- Very specific: line 26
Use database.select(database.todoItems), database.into(database.todoItems), database.update(database.todoItems), and …
- Very specific: line 27
Use bare select(todoItems) only inside GeneratedDatabase subclasses or DatabaseAccessor classes where the methods and table getters are in …
- Distinctive: line 30
Treat generator errors as blockers, not optional cleanup.
- Very specific: line 33
Run dart run drift_dev make-migrations before and after schema changes as needed.
- Very specific: line 36
Run dart format on edited Dart files.
- Very specific: line 37
Run flutter analyze or dart analyze for the package.
- Distinctive: line 38
Run targeted tests, including generated migration tests when migrations changed.
- Distinctive: line 42
Read references/setup.md when adding Drift, opening a database, configuring web support, or sharing a database across isolates.
- Distinctive: line 43
Read references/tables.md when defining tables, columns, defaults, keys, indexes, constraints, generated columns, or strict tables.
- Distinctive: line 44
Read references/queries.md when implementing selects, filters, sorting, pagination, joins, aggregations, subqueries, custom columns, or …
- Distinctive: line 45
Read references/writes.md when implementing inserts, updates, deletes, upserts, companions, transactions, or batch operations.
- Distinctive: line 46
Read references/streams.md when implementing reactive Drift streams, StreamBuilder, StreamProvider, custom select streams, table update …
- Very specific: line 47
Read references/migrations.md when schemaVersion, existing user data, build.yaml, make-migrations, generated schema files, or migration …
- Distinctive: line 48
Read references/flutter-ui.md when wiring Drift data into Flutter widgets with Provider, Riverpod, StreamBuilder, search, filtering, …
- Very specific: line 52
Do not call select(database.table) as a top-level function from a widget.
- Very specific: line 53
Do not use watch(...), todoUpdates(...), or notifyTableUpdates(...).
- Very specific: line 54
Do not call delete(table).go(id).
- Very specific: line 55
Do not use batch.updateAll(...) or pass raw ids to batch.delete(...).
- Very specific: line 56
Do not mix Provider and Riverpod APIs.
- Very specific: line 57
Do not bump schemaVersion without a migration plan for existing databases.
- Very specific: line 58
Do not rely on raw SQLite writes when UI streams must update.
- Very specific: line 62
If package downloads are blocked, update source files and leave exact dart pub add or flutter pub add commands for the user, then state …
- Very specific: line 63
If a project cannot run build_runner, do not hand-write generated *.g.dart files.
- Very specific: line 64
If migration state is unclear, stop before changing schemaVersion.
- Very specific: line 65
If web support is required but sqlite3.wasm and drift_worker.js are missing, add the code path and explicitly report the required web …
- Distinctive: line 71
All query and write examples are scoped to the correct database/accessor context.
≈ “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 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
- 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.
- Check
- 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
providerorflutter_riverpodonly when the app already uses it or the user asks for that integration.
- Create or update the database entry point:
- Define tables in Dart or
.driftfiles. - Add the tables to
@DriftDatabase. - Open Flutter databases with
driftDatabasefrompackage:drift_flutter/drift_flutter.dartunless the project needs a custom executor.
- Define tables in Dart or
- Keep Drift calls scoped to the database object:
- Use
database.select(database.todoItems),database.into(database.todoItems),database.update(database.todoItems), anddatabase.delete(database.todoItems)from widgets, services, and repositories. - Use bare
select(todoItems)only insideGeneratedDatabasesubclasses orDatabaseAccessorclasses where the methods and table getters are in scope.
- Use
- Generate code after changing Drift declarations:
- Run
dart run build_runner build. - Treat generator errors as blockers, not optional cleanup.
- Run
- For schema changes in an existing app, use Drift's guided migration workflow:
- Configure
drift_devdatabases inbuild.yaml. - Run
dart run drift_dev make-migrationsbefore and after schema changes as needed. - Bump
schemaVersion, write generated step-by-step migrations, and run generated migration tests.
- Configure
- Validate before finishing:
- Run
dart formaton edited Dart files. - Run
flutter analyzeordart analyzefor the package. - Run targeted tests, including generated migration tests when migrations changed.
- Run
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. Usedatabase.select(database.table)outside database classes. - Do not use
watch(...),todoUpdates(...), ornotifyTableUpdates(...). UsecustomSelect(...).watch(),tableUpdates(...), andnotifyUpdates(...). - Do not call
delete(table).go(id). Add awhereclause and then callgo(), or use generated table extension helpers if the project already uses them. - Do not use
batch.updateAll(...)or pass raw ids tobatch.delete(...). Usebatch.update(..., where: ...),batch.delete(...)with an insertable row, orbatch.deleteWhere(...). - Do not mix Provider and Riverpod APIs.
Provider.of<AppDatabase>(context)belongs toprovider;Provider<AppDatabase>((ref) { ... })andAsyncValue.when(...)belong to Riverpod. - Do not bump
schemaVersionwithout a migration plan for existing databases. - Do not rely on raw SQLite writes when UI streams must update. Use Drift write APIs or call
notifyUpdateswith explicitTableUpdatemetadata.
Fallbacks
- If package downloads are blocked, update source files and leave exact
dart pub addorflutter pub addcommands for the user, then state that dependency resolution was not validated. - If a project cannot run
build_runner, do not hand-write generated*.g.dartfiles. 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.wasmanddrift_worker.jsare missing, add the code path and explicitly report the required web assets.
Validation Checklist
pubspec.yamlcontains Drift runtime and generator dependencies.- Database files have valid
partdirectives, table declarations,@DriftDatabase, constructor, andschemaVersion. - 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
AsyncValueas aList. - Migrations changed only with generated schema snapshots, step-by-step migration code, and tests.
flutter analyzeordart analyzepasses for the edited package, or any remaining analyzer failure is reported with the blocker.
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.

