provide<T> function

void provide<T>(
  1. Object key,
  2. T value
)

Provides a value of type T associated with a key in the current element's scope.

Must be called within a setup() function. The value will be available for injection in the current element and its children.

key The key to associate the value with value The value to provide

Implementation

void provide<T>(Object key, T value) {
  if (currentElement == null) {
    if (kDebugMode) {
      debugPrint('odroe/setup: provide() can only be used inside setup().');
    }

    return;
  }

  var provides = currentElement!.provides;
  final parentProvides = currentElement!.parent?.provides;

  if (provides == parentProvides) {
    provides = currentElement!.provides = {...?parentProvides};
  }

  provides![key] = value;
}