- Home
- Skills
- Madteacher
- Mad Agents Skills
- Flutter Drift
flutter-drift_skill
17
GitHub Stars
1
Bundled Files
3 weeks ago
Catalog Refreshed
2 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstart where the catalogue uses aiagentskills.
npx veilstart add skill madteacher/mad-agents-skills --skill flutter-drift- SKILL.md6.2 KB
Overview
This skill is a complete guide for using the Drift database library in Flutter applications. It focuses on type-safe SQLite access, reactive streams, migrations, and platform-aware setup for mobile, web, and desktop. The content emphasizes practical patterns for CRUD, StreamBuilder integration, and state management with Provider or Riverpod.
How this skill works
The guide explains how to configure drift_flutter, run the code generator, and define a DriftDatabase with tables and schemaVersion. It shows how to perform inserts, updates, deletes, and transactions using generated DAOs and companions, and how to expose live queries as Streams for reactive UIs. Platform-specific advice covers native options for mobile/desktop, wasm and worker files for web, and isolate sharing and in-memory databases for testing.
When to use it
- Building Flutter apps that require local persistent storage with SQLite
- Need type-safe, generated queries and compile-time schema checks
- UI must react to database changes using streams
- Managing schema migrations across app versions
- Testing data logic with in-memory databases
Best practices
- Use drift_flutter for cross-platform database initialization
- Expose the database via Provider or Riverpod and close it on dispose
- Use StreamBuilder or stream-based state management for live UI updates
- Define explicit migrations and run schema validation during development
- Wrap multi-step DB changes in transactions for consistency
- Index frequently filtered columns and limit stream query sizes for performance
Example use cases
- Reactive todo lists backed by a Drift database and StreamBuilder
- Form-driven inserts with companions and validation dialogs
- Background isolates sharing a single database instance across threads
- Web deployment using sqlite3.wasm and drift_worker.js in the web/ folder
- Unit tests using an in-memory NativeDatabase for fast, isolated tests
FAQ
Run the build runner: dart run build_runner build (use --delete-conflicting-outputs if needed).
What files are required for web support?
Place sqlite3.wasm and drift_worker.js in your web/ folder and configure DriftWebOptions with their URIs.
How do I test database logic?
Create the database with NativeDatabase.memory() or pass an in-memory QueryExecutor and close it after each test.