getPreferences method
- String uid
Gets user preferences
Implementation
Future<Map<String, dynamic>?> getPreferences(String uid) async {
try {
// Check cache first
if (_userCache.containsKey(uid)) {
return Map<String, dynamic>.from(_userCache[uid]!.preferences);
}
final docSnapshot = await _firestore.collection(_collectionPath).doc(uid).get();
if (docSnapshot.exists) {
final userData = docSnapshot.data();
final preferences = Map<String, dynamic>.from(userData?['preferences'] ?? {});
// Cache the preferences
if (!_userCache.containsKey(uid)) {
final user = RaliUser.fromMap(userData!, uid);
_userCache[uid] = user;
}
return preferences;
}
return null;
} catch (e) {
print('Error getting preferences: $e');
if (e is FirebaseException && e.code == 'unavailable' && _userCache.containsKey(uid)) {
// Return from cache when offline
return Map<String, dynamic>.from(_userCache[uid]!.preferences);
}
rethrow;
}
}