mockableCreator property

  1. @override
Object? Function() get mockableCreator
override

Implementation

@override
Object? Function() get mockableCreator {
  if (cachedCreatorMocks.last != null) {
    isWaitingToInitialize = true;
    return super.mockableCreator;
  }
  return () async {
    _isInitialized = false;
    // snapValue = snapValue.copyWith(infoMessage: 'REPO $kInitMessage');
    auth._param = param?.call();
    await _init();
    snapValue = snapValue.copyWith(infoMessage: kInitMessage);
    if (onAuthStream != null) {
      final Stream<T> stream = await onAuthStream!(getRepoAs<IAuth<T, P>>());
      final future = Completer<T>();
      _isInitialized = true;
      onAuthStreamSubscription = stream.listen(
        (data) {
          if (!future.isCompleted) {
            future.complete(data);
          } else {
            setToHasData(data);
          }
        },
        onError: (err, s) {
          if (!future.isCompleted) {
            future.completeError(err, s);
          } else {
            setToHasError(
              err,
              stackTrace: s,
            );
          }
        },
      );
      return future.future;
    }

    final result = super.mockableCreator();
    if (result is T && result != unsignedUser) {
      snapValue = snapValue.copyWith(data: result);
      return auth._autoSignOut().then(
        (data) {
          _isInitialized = true;
          return data;
        },
      );
    } else {
      _isInitialized = true;
      return result;
    }
  };
}