OpaqueToken<T extends Object> class
A token to be used instead of Type when configuring dependency injection.
const loginUrl = const OpaqueToken<String>('loginUrl');
@Component(
selector: 'dashboard',
providers: const [
const ValueProvider.forToken(loginUrl, 'https://someurl.com'),
],
)
class DashboardComponent {}
The type T
is not required, but is recommended, otherwise it is dynamic
.
The only positional argument, uniqueName
, is used to determine uniqueness
of the token. That is, const OpaqueToken('SECRET')
is identical to
const OpaqueToken('SECRET')
in another library or package.
You may also sub-class OpaqueToken to create a "more unique" token:
class LoginUrl extends OpaqueToken<String> {
const LoginUrl();
}
const loginUrl = const LoginUrl();
@Component(
selector: 'dashboard',
providers: const [
const ValueProvider.forToken(loginUrl, 'https://someurl.com'),
],
)
class DashboardComponent {}
WARNING: It is not supported to create a non-const instance of this
class or sub-types of this class. Instances should only be created or
referenced using the const
operator.
- Implementers
- Annotations
-
- @optionalTypeArgs
Constructors
- OpaqueToken([String _uniqueName = ''])
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited