DescriptiveResource class

A resource that never exists, standing for a location that cannot be resolved.

Loaders return it instead of null, so callers keep one code path: they check exists and put description in their error message. Applications meet it as the result of a lookup that found nothing; reading it fails.

const missing = DescriptiveResource('resource [db:config]');
missing.exists(); // false

Spring (Java):

Resource missing = new DescriptiveResource("resource [db:config]");
missing.exists(); // false
Inheritance

Constructors

DescriptiveResource(String description)
Creates a missing resource described by description.
const

Properties

description → String
A text that tells people which resource this is, for error messages, such as file [/app/config/application.properties]. It is also the default name of a property source read from it, and two resources of the same type with the same description are equal.
final
filename → String?
The last part of the path, such as application.yml, or null when the resource has no file name (bytes in memory).
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
isReadable → bool
Whether the content can be read; usually the same as exists, but false for a directory.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
supportsSyncRead → bool
Whether readAsBytesSync and readAsStringSync work. True for files and the embedded classpath; false for URLs and Flutter assets.
no setterinherited
uri → Uri?
The URI of the resource (file:, https:, ...), or null when it has none.
no setterinherited

Methods

createRelative(String relativePath) → Resource
The resource at relativePath from this one, such as a sibling file next to a config file. It is not checked to exist. Throws UnsupportedError for resources without a location (bytes in memory).
inherited
exists() → bool
Whether the content is there: the file exists, the classpath entry is embedded. Check it before reading a resource that may be missing. A UrlResource cannot ask the server synchronously and always says true.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readAsBytes() → Future<Uint8List>
Always fails with a StateError: there is nothing to read.
override
readAsBytesSync() → Uint8List
Reads the whole content as bytes without waiting, for code that cannot be asynchronous. Throws UnsupportedError unless supportsSyncRead.
inherited
readAsString({Encoding encoding = utf8}) → Future<String>
Reads the whole content as text, decoded with encoding (UTF-8 unless given).
inherited
readAsStringSync({Encoding encoding = utf8}) → String
Reads the whole content as text without waiting, decoded with encoding. Throws UnsupportedError unless supportsSyncRead.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
Whether other is a resource of the same run-time type with the same description, as in Spring.
inherited