1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] How to pass Exception in sync riverpod provider?

Discussão em 'Mobile' iniciado por Stack, Outubro 17, 2024 às 08:34.

  1. Stack

    Stack Membro Participativo

    I have a provider which throws an exception which I want to handle where I read the provider:

    @Riverpod(dependencies: [firebaseAuth])
    User currentUser(CurrentUserRef ref) {
    final user = ref.watch(firebaseAuthProvider).currentUser;
    if (user == null) {
    throw UserNotSignedInException();
    }
    return user;
    }


    and I want to catch it here:

    try {
    ref.read(currentUserProvider);
    resolver.next();
    } on UserNotSignedInException {
    logger('User is not logged in, pushing intro route');
    router.push(const IntroRoute());
    }


    But the Exception is thrown inside the provider and never reaches the catch block. Does somebody know how to pass the exception so I can handle it in the try catch? I know when using AsyncValue that I get an AsyncError to handle but I don't want an async provider.

    Continue reading...

Compartilhe esta Página