synclayer_firebase 1.0.0 copy "synclayer_firebase: ^1.0.0" to clipboard
synclayer_firebase: ^1.0.0 copied to clipboard

discontinued

Firebase Firestore adapter for SyncLayer - enables offline-first sync with Firebase backend.

synclayer_firebase #

Firebase Firestore adapter for SyncLayer - enables offline-first synchronization with Firebase backend.

Features #

✅ Direct Firebase Firestore integration
✅ Automatic conflict resolution
✅ Delta sync support (partial updates)
✅ Sync filters for multi-tenant apps
✅ Real-time synchronization
✅ Offline-first architecture

Installation #

Add to your pubspec.yaml:

dependencies:
  synclayer: ^1.4.1
  synclayer_firebase: ^1.0.0
  firebase_core: ^3.0.0
  cloud_firestore: ^6.1.2

Usage #

1. Initialize Firebase #

import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

2. Initialize SyncLayer with Firebase #

import 'package:synclayer/synclayer.dart';
import 'package:synclayer_firebase/synclayer_firebase.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

await SyncLayer.init(
  SyncConfig(
    customBackendAdapter: FirebaseAdapter(
      firestore: FirebaseFirestore.instance,
    ),
    collections: ['todos', 'users'],
    syncInterval: Duration(minutes: 5),
  ),
);

3. Use SyncLayer #

// Save (works offline)
await SyncLayer.collection('todos').save({
  'text': 'Buy groceries',
  'done': false,
});

// Query
final todos = await SyncLayer.collection('todos')
  .where('done', isEqualTo: false)
  .get();

// Watch for changes
SyncLayer.collection('todos').watch().listen((todos) {
  print('Todos updated: ${todos.length}');
});

Firestore Schema #

Your Firestore collections should have this structure:

todos (collection)
  └─ {recordId} (document)
      ├─ data: Map<String, dynamic>  // Your actual data
      ├─ updatedAt: Timestamp
      └─ version: int

Example document:

{
  "data": {
    "text": "Buy groceries",
    "done": false
  },
  "updatedAt": "2024-01-01T12:00:00Z",
  "version": 1
}

Multi-Tenant Support #

Use sync filters to isolate user data:

await SyncLayer.init(
  SyncConfig(
    customBackendAdapter: FirebaseAdapter(
      firestore: FirebaseFirestore.instance,
    ),
    collections: ['todos'],
    syncFilters: {
      'todos': SyncFilter(
        where: {'userId': currentUserId},
      ),
    },
  ),
);

Security Rules #

Add Firestore security rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{collection}/{document} {
      allow read, write: if request.auth != null 
        && resource.data.data.userId == request.auth.uid;
    }
  }
}

Learn More #

License #

MIT License - see LICENSE file.

0
likes
140
points
47
downloads

Publisher

verified publisherhostspica.com

Weekly Downloads

Firebase Firestore adapter for SyncLayer - enables offline-first sync with Firebase backend.

Documentation

API reference

License

MIT (license)

Dependencies

cloud_firestore, flutter, synclayer

More

Packages that depend on synclayer_firebase