Local database for Flutter
Structured local data with Sembast
When an app needs queryable, offline-first local storage, the kit adds a Sembast database behind a provider, with per-entity stores and a Riverpod v3 notifier backed by the database.
What this feature covers
- Database provider: A hand-written Provider<Database>, initialized in bootstrap via a provider override.
- Per-entity stores: Top-level StoreRef constants, one per entity.
- CRUD services: A feature service over a store, with Finder, Filter and SortOrder.
- Reactive state: A Riverpod v3 Notifier<List<Model>> that wraps the service.
- Clear data: A hook into the settings clear-app-data flow that drops stores and closes the database.
How Flutter Agent Kit implements it
Sembast is the kit's sanctioned engine for structured, queryable local data. The database is a Provider<Database> overridden at startup, with no late global and no private singleton factory. Entity services live under lib/features/<feature>/services/ and store snake_case keys, while the notifier exposes the list to the UI.
For blobs and serialized objects, such as conversations or logs, the kit uses file-based JSON instead. Hive, sqflite, Isar and drift are explicitly avoided to keep one storage pattern across projects.
Frequently asked questions
Why Sembast and not Hive or sqflite?
Sembast is a single-pattern, dependency-light engine for structured and queryable data with no code generation, which matches the kit's no-build_runner rule. Blobs and serialized objects use file-based JSON, so the kit never needs a second database engine.
Is the local database initialized with a late variable?
No. The database is a Provider<Database> overridden in bootstrap before the app starts, the same pattern the kit uses for SharedPreferences and secure storage. There is no late global and no singleton constructor.
Get Flutter Agent Kit
Flutter Agent Kit ships this as a ready feature skill, together with the AGENTS.md context layer and the rest of the skills. €99.99 one-time, lifetime updates, unlimited personal and commercial projects.
Browse all features included in Flutter Agent Kit.