SharedPreferencesDatabase class

SharedPreferences implementation of DatabaseRepository.

Provides platform-native key-value storage using Flutter's SharedPreferences. Actively maintained by the Flutter team with cross-platform support.

Features:

  • Platform-native storage (NSUserDefaults on iOS, SharedPreferences on Android)
  • Cross-platform (iOS, Android, Web, Windows, macOS, Linux)
  • Simple and reliable
  • No encryption (use SecureStorageDatabase for sensitive data)

Example:

db.configure(
  prefs: SharedPreferencesDatabase(),
  // ...
);

Constructors

SharedPreferencesDatabase()

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

delete(String collection, String id) → Future<void>
Deletes a document from the database.
exists(String collection, String id) → Future<bool>
Checks if a document exists.
existsWhere(String collection, {required Map<String, dynamic> where}) → Future<bool>
Checks if any document matches the given criteria.
get(String collection, String id, {dynamic defaultValue}) → Future<Map<String, dynamic>?>
Retrieves a document from the database.
getAll(String collection) → Future<Map<String, dynamic>?>
Retrieves all documents from a collection.
init() → Future<void>
Initializes the database connection and required resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query(String collection, {Map<String, dynamic> where = const {}}) → Future<List<Map<String, dynamic>>>
Queries documents matching the specified criteria.
set(String collection, String id, Map<String, dynamic> data) → Future<void>
Creates or overwrites a document in the database.
toString() → String
A string representation of this object.
inherited
update(String collection, String id, Map<String, dynamic> data) → Future<void>
Updates specific fields in an existing document.

Operators

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