LocalPersist constructor

LocalPersist(
  1. Object dbName, {
  2. String? dbSubDir,
  3. List<Object>? subDirs,
})

Saves to appDocsDir/db/${dbName}.db

If dbName is a String, it will be used as such. If dbName is an enum, it will use only the enum value itself. For example if files is an enum, then LocalPersist(files.abc) is the same as LocalPersist("abc") If dbName is another object type, a toString() will be done, and then the text after the last dot will be used.

The default database directory defaultDbSubDir is db. You can change this variable to globally change the directory, or provide dbSubDir in the constructor.

You can also provide other subDirs as Strings or enums. Example: LocalPersist("photos", subDirs: ["article", "images"]) saves to appDocsDir/db/article/images/photos.db

Important: — In tests, instead of using appDocsDir it will save to the system temp dir. — If you mock the file-system (see method setFileSystem()) it will save to fileSystem.systemTempDirectory.

Implementation

LocalPersist(Object dbName, {this.dbSubDir, List<Object>? subDirs})
    : dbName = _getStringFromEnum(dbName),
      subDirs = subDirs?.map((s) => _getStringFromEnum(s)).toList(),
      _file = null,
      _fileSystemRef = _fileSystem;