PersistentQueueStore class

A QueueStore implementation that persists queued requests as a JSON file on disk.

How it works:

  1. Requests are stored in-memory as a Queue for fast access
  2. Every mutation (enqueue, dequeue, remove, clear) writes the full queue to a JSON file
  3. On initialize, the file is read and the queue is restored

Important: Because closures cannot be serialized, this store works with SerializableRequest instead of QueuedRequest. Use toQueuedRequest to convert when processing.

final store = PersistentQueueStore(
  directory: appDocDir,
  executor: (req) async {
    return await dio.request(req.url, options: Options(method: req.method));
  },
);
await store.initialize();
Implemented types

Constructors

PersistentQueueStore({required Directory directory, required RequestExecutor executor, String fileName = 'network_queue.json', NetworkLogger? logger})

Properties

all List<QueuedRequest>
All requests currently in the queue (oldest first).
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether the queue is empty.
no setteroverride
length int
Number of queued requests.
no setteroverride
requests List<SerializableRequest>
The underlying serializable requests (read-only snapshot).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() → void
Clear all queued requests.
override
dequeue() QueuedRequest?
Remove and return the next request, or null if empty.
override
enqueue(QueuedRequest request) → void
Add a request to the end of the queue.
override
enqueueSerializable(SerializableRequest request) Future<void>
Enqueue a SerializableRequest (preferred for persistent storage).
initialize() Future<void>
Load persisted requests from disk. Must be called before using the store.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
peek() QueuedRequest?
Peek at the next request without removing it.
override
remove(String id) bool
Remove a specific request by its id.
override
toString() String
A string representation of this object.
inherited

Operators

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