ResourcePropertySource class

A property source with the properties of one .properties file.

It is what @PropertySource adds for each file, named after the resource (its description) unless a name is given. Create one directly to add a properties file to an environment by hand, for example from an EnvironmentPostProcessor; config files under lib/resources/ need no code.

// Extra settings next to the program, below every other source.
final resource = FileSystemResource('config/app.properties');
if (resource.exists()) {
  environment.propertySources.addLast(
    ResourcePropertySource.fromResource(resource, name: 'app'),
  );
}

// A Flutter asset can only be read asynchronously.
final asset = await ResourcePropertySource.load(assetResource);

Spring (Java):

var source = new ResourcePropertySource("app",
    new FileSystemResource("config/app.properties"));
environment.getPropertySources().addLast(source);

Spring always reads synchronously; here use load for resources that can only be read asynchronously, such as Flutter assets.

Inheritance

Constructors

ResourcePropertySource.fromContent(Resource resource, String content, {String? name})
Parses content, text already read from resource, into a source.
factory
ResourcePropertySource.fromResource(Resource resource, {String? name, Encoding encoding = utf8})
Reads resource now, decoded with encoding (UTF-8 unless given), into a source called name or after the resource.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
The name of this source, unique within the environment's list. It is how other code finds, replaces or orders the source, and it appears in error messages (Config resource 'resources:/application.yml').
finalinherited
propertyNames → List<String>
The keys of all properties this source has, as they are written in it.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
source → Map<String, Object?>
The object the values are read from: a map, the command-line arguments, a client.
finalinherited

Methods

containsProperty(String name) → bool
Whether the map has the key name, even with a null value.
inherited
getProperty(String name) → Object?
The value of the property name, or null when this source does not have it (the environment then asks the next source).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
Whether other is a source with the same name, whatever its values, as in Spring.
inherited

Static Methods

load(Resource resource, {String? name, Encoding encoding = utf8}) → Future<ResourcePropertySource>
Reads resource, waiting for it, decoded with encoding (UTF-8 unless given), into a source called name or after the resource. Works for every resource, including Flutter assets and URLs.