updateUser method
Updates user data with merge semantics and tracks changes for offline support
Implementation
Future<void> updateUser(String uid, Map<String, dynamic> data) async {
try {
if (!_isOnline) {
// We're offline, store changes to sync later
_updateCache(uid, data);
throw RALIException('Currently offline, changes will be saved when online', cause: null);
}
await _firestore.collection(_collectionPath).doc(uid).update(data);
// Update cache if it exists
_updateCache(uid, data);
} catch (e) {
print('Error updating user: $e');
// Handle network errors for offline updates
if (e is FirebaseException && e.code == 'unavailable') {
// Queue updates for later syncing
_updateCache(uid, data);
_trackPendingChanges(uid, data);
throw RALIException('Network unavailable, changes will be synced when online', cause: e);
}
throw RALIException('Failed to update user data', cause: e);
}
}