bfs_manager 0.0.21
bfs_manager: ^0.0.21 copied to clipboard
Offline-first Flutter sync SDK for SQLite ↔ server. Simple API: init, register/login, save/edit/remove, and sync.
bfs_manager #
Offline-first Flutter sync SDK — local SQLite ↔ Laravel (or any compatible) server.
Developer mainly needs 4 things:
init· auth ·save/edit/remove·sync
Install #
dependencies:
bfs_manager: ^0.0.21
flutter pub get
Quick start #
1) Init (once in main) #
import 'package:bfs_manager/bfs_manager.dart';
import 'package:sqflite/sqflite.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final db = await openDatabase('app.db', version: 1, onCreate: (db, v) async {
await db.execute('''
CREATE TABLE tb_tasks (
uuid TEXT PRIMARY KEY,
title TEXT,
status TEXT,
image_path TEXT
)
''');
});
await BfsManager.instance.init(
baseUrl: 'https://your-api.com/api',
appDatabase: db,
);
runApp(const MyApp());
}
2) Auth #
await BfsManager.instance.register({
'name': 'Ashok',
'email': 'a@x.com',
'password': 'secret123',
}, onSuccess: (r) => print(r['token']), onFail: print);
await BfsManager.instance.login({
'email': 'a@x.com',
'password': 'secret123',
}, onSuccess: (_) async {
await BfsManager.instance.sync(type: BfsSyncType.all); // first download
});
await BfsManager.instance.logout();
await BfsManager.instance.deleteAccount();
3) Local CRUD (auto queue + push) #
await BfsManager.instance.save('tb_tasks', {
'title': 'Buy milk',
'status': 'pending',
'image_path': '/path/photo.jpg', // auto multipart upload
});
await BfsManager.instance.edit('tb_tasks', {
'uuid': taskUuid,
'status': 'done',
});
await BfsManager.instance.remove('tb_tasks', taskUuid);
4) Sync #
await BfsManager.instance.sync(); // push + pull latest
await BfsManager.instance.sync(type: BfsSyncType.all); // full download
await BfsManager.instance.sync(type: BfsSyncType.push); // push only
await BfsManager.instance.sync(type: BfsSyncType.latest);// pull only
| Type | What it does |
|---|---|
BfsSyncType.sync |
Push queue + pull updates (default) |
BfsSyncType.all |
Full paginated pull-all |
BfsSyncType.push |
Push pending local changes |
BfsSyncType.latest |
Pull incremental updates |
Typical app flow #
main → init
login → sync(all)
CRUD → save / edit / remove
resume → sync()
logout / deleteAccount
Built-in optimizations #
- Debounced auto-push (default 800ms)
- Batched push (default 10 rows per request)
- Push lock (no parallel storms)
- Pull writes in SQLite transactions
- Table column cache
Tune in init:
await BfsManager.instance.init(
baseUrl: '...',
appDatabase: db,
pushBatchSize: 10,
pullPageLimit: 100,
pushDebounce: const Duration(milliseconds: 800),
);
Docs #
- Developer Guide — full API, payloads, files, best practices
- CHANGELOG
License #
MIT