DiscData class
High-level API for reading/writing files, abstracting away the per-platform differences (path separators, default root directory, hidden-directory conventions, browser storage, ...).
Files are read and written asynchronously; a file is written all at once (a reader never sees half of it), and a file name can never point outside filesPath.
In a browser, files live in IndexedDB, next to the database: the methods
that read and write bytes, text or base64 work the same; getFile, which
returns a dart:io file, returns null.
Access the singleton through DiscData.instance.
Properties
-
databasesPath
→ Future<
String> -
Directory holding the
dbNamefile of DataAccess.changeDB.no setter -
filesPath
→ Future<
String> -
Directory used to store user-facing files saved by the package.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- pathJoin → String
-
Platform path separator (
'\'on Windows,'/'elsewhere).latefinal -
rootPath
→ Future<
String> -
Root directory for the current application. Equivalent to
getApplicationDocumentsDirectory().path(/in a browser).no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
appendDataToFile(
Object? data, DataType dataType, {String? fileName, String? path}) → Future< void> -
Appends
datato an existing file. -
checkFileExists(
{String? fileName, String? path}) → Future< bool> -
Returns
trueif the file identified byfileName(relative to filesPath) or by the absolutepathexists. -
debugResetPaths(
) → void - Forgets the cached folders (tests only).
-
deleteFile(
{String? fileName, String? path}) → Future< bool> - Deletes a file.
-
getEntityFileOnDisc<
D, T> (String urlColumnName, String key, Object value, {String? path}) → Future< D?> - Loads a file whose name is stored in a column of an SQLite table.
-
getFile(
{String? fileName, String? path}) → Future< File?> -
Returns the file handle, or
nullwhen the file does not exist (alwaysnullin a browser, which has no file system). The file is returned as stored: encrypted when the database is; read it with readFileAsBytes or readFileAsString, which decrypt. -
getImageFromDisc(
{String? imageName, String? path, BoxFit fit = BoxFit.fill}) → Future< Image?> - Loads an image and returns an Image widget.
-
getParentDir(
String path) → String -
Returns the parent directory of
path, computed by stripping the last component from the path. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
readFileAsBase64(
{String? fileName, String? path}) → Future< String?> -
Reads the file and returns its content encoded as a Base64 string.
Returns
nullwhen the file does not exist. -
readFileAsBytes(
{String? fileName, String? path}) → Future< Uint8List?> -
Reads the file and returns its raw bytes.
Returns
nullwhen the file does not exist. -
readFileAsString(
{String? fileName, String? path}) → Future< String?> -
Reads the file and returns its UTF-8 content.
Returns
nullwhen the file does not exist. -
saveDataToDisc(
Object? data, DataType dataType, {String? takeThisName, String? path, bool recursive = false, bool? encrypt}) → Future< String?> -
Writes
data. -
toString(
) → String -
A string representation of this object.
inherited
-
validatePath(
String? path) → String? -
Normalizes a file system
pathso it can be safely consumed bydart:io.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited