useIsReady<T extends Object> function

bool useIsReady<T extends Object>({
  1. void onReady(
    1. BuildContext context
    )?,
  2. void onError(
    1. BuildContext context,
    2. Object? error
    )?,
  3. Duration? timeout,
  4. String? instanceName,
})

Implementation

bool useIsReady<T extends Object>(
    {void Function(BuildContext context)? onReady,
    void Function(BuildContext context, Object? error)? onError,
    Duration? timeout,
    String? instanceName}) {
  return use(_WatchFutureHook<Object, bool>(
      preserveState: true,
      select: null,
      instanceName: instanceName,
      handler: (context, x, cancel) {
        if (x.hasError) {
          onError?.call(context, x.error);
        } else {
          onReady?.call(context);
        }
        (context as Element).markNeedsBuild();
        cancel(); // we want exactly one call.
      },
      initialValueProvider: () =>
          GetIt.I.isReadySync<T>(instanceName: instanceName),

      /// as `GetIt.allReady` returns a Future<void> we convert it
      /// to a bool because if this Future completes the meaning is true.
      futureProvider: () => GetIt.I
          .isReady<T>(instanceName: instanceName, timeout: timeout)
          .then((_) => true))).data!;
}