'my value becomes null in streambuilder listview.builder when getting data from firebase

I see that the stream builder returns ${globals.statusKey} as null, but I don't know why, because I can print the value out well, and the FriendStatus code is also a widget that I called well in another part of the app(which was drawer).

I can see these kinds of problem occurring frequently in stream builder but cannot find any solution.

There is an error like below

'package:cloud_firestore/src/firestore.dart': Failed assertion: line 63 ps 7:1 '! collectionPath.contains('//'):a collection path must not contain "//"

And here is the code.

 body: SafeArea(
    child: Container(
      padding: EdgeInsets.fromLTRB(10, 5, 0, 0),
      // child: SingleChildScrollView(
      //   scrollDirection: Axis.vertical,
      child: Column(children: [
        tapableDate(),
        const SizedBox(
          height: 10,
        ),
        Container(
          height: 220,
          width: 330,
          decoration: BoxDecoration(
            border: Border.all(
              color: Colors.black,
            ),
          ),
          child: FriendStatus(),
        ),
        Text(
          "See \n statusKey: ${globals.statusKey} \n count: \n",
        ),

        // Provider(create: (context) => TimerService(), child: EventList()),
        // ),
      ]),
      // ),
    ),
  ),

Code of FriendStatus.dart

    import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:gw/globals.dart' as globals;

class FriendStatus extends StatefulWidget {
  const FriendStatus({Key? key}) : super(key: key);

  @override
  State<FriendStatus> createState() => _FriendStatusState();
}

class _FriendStatusState extends State<FriendStatus> {
  FirebaseFirestore firestore = FirebaseFirestore.instance;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
          padding: EdgeInsets.fromLTRB(20, 10, 20, 0),
          child: Column(
            children: [
              StreamBuilder(
                stream: FirebaseFirestore.instance
                    .collection('user/${globals.currentUid}/friends')
                    .snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>
                        snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return Center(
                      child: CircularProgressIndicator(),
                    );
                  }
                  final docs = snapshot.data!.docs;
              return ListView.builder(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                itemCount: docs.length,
                itemBuilder: (context, index) {
                  return Container(
                      //padding:,
                      child: ListTile(
                    leading: Icon(
                      Icons.circle,
                      color: Colors.grey[850],
                    ),
                    title: Text(docs[index]['name']),
                  ));
                },
              );
            },
          )
        ],
      )),
);

} }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source