Optional class

A parameter metadata that marks a dependency as optional.

Injector provides null if the dependency is not found.

Example

class Engine {}

@Injectable()
class Car {
  final Engine engine;
  Car(@Optional() this.engine);
}

var injector = Injector.resolveAndCreate([Car]);
expect(injector.get(Car).engine, isNull);
Annotations
  • @Target({TargetKind.parameter})

Constructors

Optional()
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.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited