LocalPersist class

This will save/load multiple simple objects in UTF-8 Json format.

Save example:

var persist = LocalPersist("xyz");
List<Object> simpleObjs = ['"Hello"', '"How are you?"', [1, 2, 3], 42];
await persist.save();

Load example:

var persist = LocalPersist("xyz");
List<Object> decoded = await persist.load();

Constructors

LocalPersist(Object dbName, {String dbSubDir, List<Object> subDirs})
Saves to appDocsDir/db/${dbName}.db [...]
LocalPersist.from(File file)
Saves to the given file.

Properties

dbName String
final
dbSubDir String
final
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
subDirs List<String>
final

Methods

delete() Future<bool>
Deletes the file. If the file was deleted, returns true. If the file did not exist, return false.
exists() Future<bool>
Returns true if the file exist. False, otherwise.
file() Future<File>
Gets the file.
length() Future<int>
Returns the file length. If the file doesn't exist, or exists and is empty, returns 0.
load() Future<List<Object>>
Loads the simple objects from the file. If the file doesn't exist, returns null. If the file exists and is empty, returns an empty list.
loadAsObj() Future<Map<String, dynamic>>
Same as load, but expects the file to be a Map<String, dynamic> representing a single object. Will fail if it's not a map, or if contains more than one single object. It may return null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
save(List<Object> simpleObjs, {bool append: false}) Future<File>
Saves the given simple objects. If append is false (the default), the file will be overwritten. If append is true, it will write to the end of the file.
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Properties

appDocDir Directory
read-only
defaultDbSubDir String
The default is saving/loading to/from "appDocsDir/db/". This is not final, so you can change it.
read / write
defaultTermination String
The default is adding a ".db" termination to the file name. This is not final, so you can change it.
read / write

Static Methods

bytesToUint8Lists(Uint8List bytes) List<Uint8List>
concatUint8Lists(List<Uint8List> chunks) Uint8List
decode(Uint8List bytes) List<Object>
encode(List<Object> simpleObjs) Uint8List
jsonsToUint8Lists(Iterable<String> jsons) List<Uint8List>
objsToJsons(List<Object> simpleObjs) Iterable<String>
pathName(String dbName, {String dbSubDir, List<String> subDirs}) String
resetFileSystem() → void
setFileSystem(FileSystem fileSystem) → void
You can set a memory file-system in your tests. For example: [...]
simpleObjsToString(List<Object> simpleObjs) String
toSimpleObjs(Iterable<String> jsons) Iterable<Object>
uint8ListsToJsons(Iterable<Uint8List> chunks) Iterable<String>

Constants

maxJsonSize → const int
256 * 256