flutter_easy_db
A secure, easy-to-use encrypted local database for Flutter. Combines the simplicity of Isar's object-oriented API with Drift's type-safe queries, adding AES-256 encryption for all stored data.
Features
- AES-256 Encryption — All data encrypted at rest with per-record random IVs
- Simple API — Isar-inspired: no SQL, no boilerplate, just
put()andquery() - Type-safe Queries — Drift-inspired fluent query builder with filters, sorting, pagination
- Reactive Streams — Watch collections for real-time updates
- Batch Operations — Insert multiple documents in a single transaction
- Zero Config Collections — No schema definition needed, just use
db.collection('name') - Cross-platform — Works on iOS, Android, macOS, Linux, Windows
Quick Start
// Open encrypted database
final db = await EasyDb.open(
EasyDbConfig(
dbName: 'my_app',
encryptionKey: 'my-32-character-secret-key!!!!!', // exactly 32 chars
),
);
// Store data
final users = db.collection('users');
await users.put({'name': 'Alice', 'age': 30});
// Query data
final results = await users.query()
.where('age', isGreaterThan: 25)
.sortBy('name')
.find();
// Watch for changes
users.watch().listen((docs) {
print('Updated: ${docs.length} users');
});
// Close when done
await db.close();
Installation
dependencies:
flutter_easy_db:
path: ./flutter_easy_db # or publish to pub.flutter-io.cn
Security
- Uses AES-256-CBC encryption with SHA-256 key derivation
- Each record encrypted with a unique random IV (prevents pattern analysis)
- Encryption key never stored on disk
- Pass
nullforencryptionKeyto disable encryption (development only)
API Reference
EasyDb
| Method | Description |
|---|---|
EasyDb.open(config) |
Opens/creates a database |
db.collection(name) |
Gets or creates a collection |
db.collections |
Lists all collection names |
db.dropCollection(name) |
Deletes a collection |
db.clearAll() |
Clears all data |
db.close() |
Closes the database |
EasyDb.deleteDatabase(name) |
Deletes the database file |
EasyCollection
| Method | Description |
|---|---|
put(data, {id}) |
Insert or update a document |
putAll(items) |
Batch insert |
get(id) |
Get document by ID |
getAll() |
Get all documents |
delete(id) |
Delete by ID |
clear() |
Clear collection |
count() |
Document count |
query() |
Start a query |
watch() |
Reactive stream |
Query Builder
collection.query()
.where('field', isEqualTo: value)
.where('field', isGreaterThan: value)
.where('field', contains: 'text')
.where('field', startsWith: 'text')
.where('field', isIn: [1, 2, 3])
.sortBy('field', descending: true)
.limit(10)
.offset(20)
.find(); // List<DbDocument>
.findFirst(); // DbDocument?
.delete(); // int (deleted count)
Architecture
┌─────────────────────────────────────────┐
│ Your Flutter App │
├─────────────────────────────────────────┤
│ flutter_easy_db API │
│ (EasyDb → Collection → Query) │
├─────────────────────────────────────────┤
│ AES-256 Encryption Layer │
│ (encrypt/decrypt on read/write) │
├─────────────────────────────────────────┤
│ SQLite (sqflite) │
│ (stores encrypted JSON blobs) │
└─────────────────────────────────────────┘
License
MIT
Libraries
- flutter_easy_db
- flutter_easy_db - A secure, easy-to-use encrypted local database for Flutter.