FakeStateStorage class

An in-memory StateStorage implementation for use in tests.

Supports seeded initial data, failure injection, latency simulation, and call inspection (counts and recorded keys).

final storage = FakeStateStorage()
  ..seed('user', '{"id":1}')
  ..loadError = Exception('disk read failed');
Implemented types

Constructors

FakeStateStorage({Map<String, String>? initialData})
Creates a FakeStateStorage, optionally pre-populated with initialData.

Properties

data Map<String, String>
An unmodifiable view of the underlying key→value map.
no setter
deleteCount int
Total number of delete calls since construction (or last reset).
getter/setter pair
deleteDelay Duration?
If non-null, delete awaits this duration before completing.
getter/setter pair
deletedKeys List<String>
All keys passed to delete, in order, including duplicates.
no setter
deleteError Object?
If non-null, delete throws this object instead of removing the key.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
loadCount int
Total number of load calls since construction (or last reset).
getter/setter pair
loadDelay Duration?
If non-null, load awaits this duration before completing.
getter/setter pair
loadError Object?
If non-null, load throws this object instead of returning a value.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
saveCount int
Total number of save calls since construction (or last reset).
getter/setter pair
saveDelay Duration?
If non-null, save awaits this duration before completing.
getter/setter pair
savedKeys List<String>
All keys passed to save, in order, including duplicates.
no setter
saveError Object?
If non-null, save throws this object instead of recording the write.
getter/setter pair

Methods

clear() → void
Wipes stored data only.
delete(String key) Future<void>
Removes any value stored under key.
override
hasKey(String key) bool
Whether key is currently present in storage.
load(String key) Future<String?>
Loads the value associated with the given key.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rawValue(String key) String?
The raw serialized value for key, or null if missing.
reset() → void
Wipes all internal state — data, counters, errors, and delays.
save(String key, String value) Future<void>
Saves a value associated with the given key.
override
seed(String key, String value) → void
Writes value into the in-memory map without counting as a save call.
toString() String
A string representation of this object.
inherited

Operators

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