Dan12314
Dan12314

Reputation: 127

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

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?

Upvotes: 1

Views: 108

Answers (0)

Related Questions