FileDraftStore class

A DraftStore that keeps each draft in its own JSON file.

Use it on Android, iOS, desktop and anywhere else dart:io is available. Import it from package:form_draft/io.dart, so that builds targeting the web never reach this library.

final store = FileDraftStore(
  Directory('${(await getApplicationSupportDirectory()).path}/drafts'),
);

Writes go through a temporary file and are renamed into place, so a draft is never left half written if the app is killed during a save. Operations are serialized: the last write always wins.

Implemented types

Constructors

FileDraftStore(Directory directory, {String suffix = '.draft.json'})
Creates a store writing drafts inside directory.

Properties

directory → Directory
Directory holding the draft files.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
suffix → String
File name suffix of the drafts.
final

Methods

delete(String id) → Future<void>
Deletes the draft stored under id.
override
fileFor(String id) → File
Path of the draft file for id.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(String id) → Future<String?>
Reads the raw draft stored under id.
override
toString() → String
A string representation of this object.
inherited
write(String id, String value) → Future<void>
Writes value as the raw draft stored under id, replacing any previous value.
override

Operators

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