useAllReady function

bool useAllReady({
  1. void onReady(
    1. BuildContext context
    )?,
  2. void onError(
    1. BuildContext context,
    2. Object error
    )?,
  3. Duration? timeout,
})

Implementation

bool useAllReady(
    {void Function(BuildContext context)? onReady,
    void Function(BuildContext context, Object error)? onError,
    Duration? timeout}) {
  return use(_WatchFutureHook<Object, bool>(
    instanceName: null,
    select: null,
    preserveState: true,
    handler: (context, x, dispose) {
      if (x.hasError) {
        onError?.call(context, x.error!);
      } else {
        onReady?.call(context);
        (context as Element).markNeedsBuild();
      }
      dispose();
    },
    initialValueProvider: () => GetIt.I.allReadySync(),

    /// 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.allReady(timeout: timeout).then((_) => true),
  )).data!;
}