OpaqueToken<T> 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. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

toString() → String
Returns a string representation of this object.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited