Skip to main content

bfs_manager 0.0.37 copy "bfs_manager: ^0.0.37" to clipboard
bfs_manager: ^0.0.37 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

pub package


Install #

dependencies:
  bfs_manager: ^0.0.34
flutter pub get

Quick start #

import 'package:bfs_manager/bfs_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await BfsManager.instance.init(
    baseUrl: 'https://your-api.com/api',
    tables: {
      'tb_tasks': {
        'title': 'TEXT',
        'status': 'TEXT',
        'image_path': 'TEXT',
      },
      'tb_reminder': {
        'title': 'TEXT',
        'reminder_datetime': 'INTEGER',
        'is_complete': 'INTEGER',
      },
    },
  );

  runApp(const MyApp());
}

uuid TEXT PRIMARY KEY auto-add થાય છે. અલગ SQL CREATE TABLE જરૂરી નથી.

Demo: example/README.md

Optional — backend કસ્ટમ fields/keys વાપરે તો init માં override:

await BfsManager.instance.init(
  baseUrl: 'https://your-api.com/api',
  tables: {...},
  authRequired: BfsAuthRequired(
    login: ['phone', 'otp'],           // default: email, password
    register: ['name', 'phone', 'otp'], // default: name, email, password
  ),
  responseKeys: BfsResponseKeyMap(
    token: 'access_token',             // default: token
    user: 'customer',                  // default: users → user
    prefsPrefix: 'customer',           // default: users (SharedPreferences prefix)
  ),
  onUnauthorized: () {
    // 401/403 → token cleared, local data kept → go to Login
  },
);

Manual soft logout (token only, data kept):

await BfsManager.instance.clearAuthToken();

2) Auth & User Profile Data #

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
});

👤 Reading User Profile (SharedPreferences)

સર્વરમાંથી યુઝર ટેબલની તમામ કોલમ્સ આપમેળે SharedPreferences માં ${prefix}_$column તરીકે સેવ થાય છે (દા.ત. users_name, users_email, users_id):

String name  = await BfsManager.instance.getString('users_name');
String email = await BfsManager.instance.getString('users_email');
String phone = await BfsManager.instance.getString('users_phone');
String id    = await BfsManager.instance.getString('users_id');

bool loggedIn = BfsManager.instance.isLoggedIn;
await BfsManager.instance.logout();        // Server logout + wipes local user profile & DB
await BfsManager.instance.deleteAccount(); // Server delete account + wipes local data

3) Local CRUD (auto queue + push) #

Single file

await BfsManager.instance.save('tb_tasks', {
  'title': 'Buy milk',
  'status': 'pending',
  'image_path': '/path/photo.jpg', // auto multipart upload
});

Multiple files (same column) — pass a List of local paths:

await BfsManager.instance.save('tb_tasks', {
  'title': 'Task with gallery',
  'status': 'pending',
  'image_path': [
    '/path/photo1.jpg',
    '/path/photo2.jpg',
    '/path/photo3.jpg',
  ],
});

Or as a JSON string (useful if your SQLite column is TEXT):

await BfsManager.instance.save('tb_tasks', {
  'title': 'Task with gallery',
  'status': 'pending',
  'image_path': '["/path/photo1.jpg","/path/photo2.jpg","/path/photo3.jpg"]',
});
await BfsManager.instance.edit('tb_tasks', {
  'uuid': taskUuid,
  'status': 'done',
});

await BfsManager.instance.remove('tb_tasks', taskUuid);

Multipart keys for multiple files:
files[tb_tasks][uuid][image_path][0], [1], [2], …
See Developer Guide → File uploads.

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

0
likes
150
points
1.13k
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Offline-first Flutter sync SDK for SQLite ↔ server. Simple API: init, register/login, save/edit/remove, and sync.

Homepage
Repository (GitHub)
View/report issues

Topics

#sync #sqlite #offline #flutter #laravel

License

MIT (license)

Dependencies

flutter, http, path, shared_preferences, sqflite, uuid

More

Packages that depend on bfs_manager