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

[Flutter] How do I read a Riverpod provider within a Class or Stream without Ref or context?

Discussão em 'Mobile' iniciado por Stack, Outubro 13, 2024 às 16:02.

  1. Stack

    Stack Membro Participativo

    I have a Class I use for backend, within which I have a Stream that Streams data from Firebase, as shown below. I need to access the data from a Riverpod Provider to specify the Firebase collection reference (yearFromProvider2). How can this be done from within a Class that does not have any access to ref or context.

    Stream<DocumentSnapshot> userStream() async* {
    //Need to read another Stream here to access the value of year to add to collection reference
    yield* FirebaseFirestore.instance
    .collection(yearFromProvider2)
    .doc("test")
    .snapshots();
    }


    In all other parts of my app I would use StreamProvider and call it as follows:

    final data = ref.watch(provider).value;


    This cannot be done within the Class as I do not have any access to Ref or the BuildContext. Is there any quick solution to read an instance of the Provider2?

    Continue reading...

Compartilhe esta Página