runAppAsync<T> function

Future<ComponentRef<T>> runAppAsync <T>(ComponentFactory<T> componentFactory, { @required Future<void> beforeComponentCreated(Injector), InjectorFactory createInjector: _identityInjector })

Asynchronous alternative to runApp, supporting beforeComponentCreated.

The provided callback (beforeComponentCreated) is invoked before creating the root component, with a handle to the root injector. The user may choose to return a Future - it will be awaited before creating the root component.

See runApp for additional details.

Implementation

Future<ComponentRef<T>> runAppAsync<T>(
  ComponentFactory<T> componentFactory, {
  @required Future<void> Function(Injector) beforeComponentCreated,
  InjectorFactory createInjector = _identityInjector,
}) {
  if (isDevMode) {
    if (componentFactory == null) {
      throw ArgumentError.notNull('componentFactory');
    }
    if (beforeComponentCreated == null) {
      throw ArgumentError.notNull('beforeComponentCreated');
    }
  }
  final injector = appInjector(createInjector);
  return beforeComponentCreated(injector).then((_) {
    final appRef = unsafeCast<ApplicationRef>(injector.get(ApplicationRef));
    return appRef.bootstrap(componentFactory);
  });
}