firewatch 0.1.1
firewatch: ^0.1.1 copied to clipboard
Lightweight Firestore repositories for Flutter: single-doc and collection repos that react to auth, stream updates, and support live-window pagination.
firewatch #
Lightweight Firestore repositories for Flutter.
- π Auth-reactive: attach/detach on UID changes via any
ValueListenable<String?>
- β‘ Instant UI: primes from local cache; then streams live updates
- πͺΆ Small surface area: single-doc + collection repos
- π Live window pagination: grow with
loadMore()
, reset viaresetPages()
- π§© No auth lock-in: bring your own auth listenable
Install #
dependencies:
firewatch: ^0.1.0
Quick start #
import 'package:firewatch/firewatch.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
final authUid = ValueNotifier<String?>(null); // wire to your auth layer
final profileRepo = FirestoreDocRepository<UserProfile>(
firestore: FirebaseFirestore.instance,
fromJson: UserProfile.fromJson,
docRefBuilder: (fs, uid) => fs.doc('users/$uid'),
authUid: authUid,
subscribe: true,
);
final friendsRepo = FirestoreCollectionRepository<UserProfile>(
firestore: FirebaseFirestore.instance,
fromJson: UserProfile.fromJson,
colRefBuilder: (fs, uid) => fs.collection('users/$uid/friends'),
authUid: authUid,
subscribe: true,
pageSize: 25,
);
// Grow the list:
await friendsRepo.loadMore();
Bring your own Auth #
Firewatch accepts any ValueListenable<String?> that yields the current user UID. Update it on sign-in/out and the repos will re-attach.
authUid.value = 'abc123'; // sign in
authUid.value = null; // sign out
Commands API #
Both repos expose command_it
async commands:
profileRepo.write(UserProfile(id: 'abc123', displayName: 'Marty'));
profileRepo.patch({'bio': 'Hello'});
friendsRepo.add({'displayName': 'Alice'});
friendsRepo.delete(id!);
UI State #
isLoading
: true while fetching/refreshinghasInitialized
(collections): first load completedhasMore
(collections): whetherloadMore()
can grow the windownotifierFor(docId)
: get a pre-soakedValueNotifier<T?>
for a specific item
Examples & Tests #
See example/usage.dart
Documentation #
License #
MIT - See LICENSE