useIsReady<T extends Object> function
bool
useIsReady<T extends Object>({
- void onReady(
- BuildContext context
- void onError(
- BuildContext context,
- Object? error
- Duration? timeout,
- 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!;
}