RemotePrefs class abstract

Abstract interface for implementing remote preference storage.

Extend this class to integrate with any backend service like Firebase, Supabase, custom REST APIs, etc.

The mixin _PrefsConverter provides helper methods for type conversion between Dart types and string representations suitable for storage.

Example implementation:

class FirebasePrefs extends RemotePrefs {
  final FirebaseFirestore _firestore = FirebaseFirestore.instance;

  @override
  Future<Map<String, dynamic>?> getPreferences() async {
    final userId = FirebaseAuth.instance.currentUser?.uid;
    if (userId == null) return null;

    final doc = await _firestore.collection('prefs').doc(userId).get();
    // ... parse and return preferences
  }

  @override
  Future<void> setPreference(String key, dynamic value) async {
    final userId = FirebaseAuth.instance.currentUser?.uid;
    if (userId == null) return;

    final typed = toTypedValue(value);
    await _firestore.collection('prefs').doc(userId).update({
      key: typed.toMap(),
    });
  }
}

Constructors

RemotePrefs()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

getPreferences() → Future<Map<String, dynamic>?>
Fetches all remote preferences for the current user.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseFromString(String value, String dataType) → dynamic
Parses a string value back to its original Dart type.
inherited
setPreference(String key, dynamic value) → Future<void>
Saves a single preference to remote storage.
toString() → String
A string representation of this object.
inherited
toTypedValue(dynamic value) → TypedValue
Converts a Dart value to a typed storage format.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited