title: Pass fetched value to a firestore reference to flutter's streambuilder
body: <p>I'm accessing a user's favorite group which is inside <code>groupfav</code> in Firestore, when I get it I want to give it as part of the reference to the streambuilder <code>stream:</code>, so that it knows what to show in a list, but I can't pass the variable that contains the favorite group, what should I do or what am I doing wrong?</p>
  <pre><code>static String? userID = FirebaseAuth.instance.currentUser?.uid; // get current user id
    static var taskColeccion = FirebaseFirestore.instance.collection(&quot;usuarios&quot;);
    var tack = taskColeccion.doc(&quot;$userID&quot;).get().then((value) {
      var groupfav = value.data()![&quot;groupfav&quot;]; // value i get from firestore
      return groupfav;
    });
  
    late Stream&lt;QuerySnapshot&gt; task = FirebaseFirestore.instance
    .collection(&quot;groups&quot;)
    .doc(groupfav) // pass the obtained value 
    .collection(&quot;tareas&quot;)
    .snapshots();
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Rihr7.png" rel="nofollow noreferrer">photo of firestore</a></p>
  <p>The photo shows how Firestore's logic is and the value marked in green is what I must pass to the <code>late Stream&lt;QuerySnapshot&gt; task...</code> in its reference, logically it is a random value that I would not know. thanks for any help!</p>
  <p>this is what the code looks like now (I took things that were not important)</p>
  <pre><code>class Home extends StatefulWidget {
    const Home({Key? key}) : super(key: key);
  
    @override
    _HomeState createState() =&gt; _HomeState();
  }
  
  class _HomeState extends State&lt;Home&gt; {
    static String? userID = FirebaseAuth.instance.currentUser?.uid;
    static final taskColeccion =
        FirebaseFirestore.instance.collection(&quot;usuarios&quot;);
    String groupfav = '';
    final tack = taskColeccion.doc(&quot;$userID&quot;).get().then((value) {
      groupfav = value.data()![&quot;groupfav&quot;];
      return groupfav;
    });
  
    Stream&lt;QuerySnapshot&gt; task = FirebaseFirestore.instance
        .collection(&quot;groups&quot;)
        .doc(groupfav) // pass the obtained value
        .collection(&quot;tareas&quot;)
        .snapshots();
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: const Text(&quot;Home&quot;),
          automaticallyImplyLeading: false,
        ),
        body: StreamBuilder(
          stream: task,
          builder: (
            BuildContext context,
            AsyncSnapshot&lt;QuerySnapshot&gt; snapshot,
          ) {
            if (snapshot.hasError) {
              return const Text(&quot;error&quot;);
            }
            if (snapshot.connectionState == ConnectionState.waiting) {
              return const Text(&quot;cargando&quot;);
            }
            final data = snapshot.requireData;
  
            return ListView.builder(
              itemCount: data.size,
              itemBuilder: (context, index) {
                return Card(
                  child: ListTile(
                    title: Text(&quot;${data.docs[index]['titulo']}&quot;),
                    subtitle: Text(&quot;${data.docs[index]['contenido']}&quot;),
                    onTap: () {},
                    trailing: IconButton(
                      icon: const Icon(Icons.delete),
                      color: Colors.red[200],
                      onPressed: () {
                        // delete function
                      },
                    ),
                  ),
                );
              },
            );
          },
        ),
      );
    }
  }
  </code></pre>