如何使用firebase数据在没有listView的情况下进行流式数据

发布于 2025-01-22 09:54:15 字数 45 浏览 0 评论 0原文

我需要在尊敬的地方显示我的壁炉数据。但是在同一页面中。 在我遵循的每个教程中

I need to show my firebase data in deference places. But in the same page.
In every tutorial I followed they use Listview and I need to know there is another way to get data without using the list view

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

八巷 2025-01-29 09:54:15

ya终于我想我找到了答案

  final uid = FirebaseAuth.instance.currentUser!.uid;
  userdata = FirebaseFirestore.instance.collection('/users/$uid/userdata');
  

  return Scaffold(
      body: StreamBuilder(
        stream: userdata.snapshots(),
        builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.hasError) {
            return Text('Something went wrong');
          }
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Text("Loading");
          }
          try {
            snapshot.data!.docs.map((DocumentSnapshot document) {
              data = document.data()! as Map<String, dynamic>;
            }).toList();
          } catch (e) {
            print(e.toString());
          }
       },
      ),
    );

Ya finally I think I found an answer

  final uid = FirebaseAuth.instance.currentUser!.uid;
  userdata = FirebaseFirestore.instance.collection('/users/$uid/userdata');
  

  return Scaffold(
      body: StreamBuilder(
        stream: userdata.snapshots(),
        builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (snapshot.hasError) {
            return Text('Something went wrong');
          }
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Text("Loading");
          }
          try {
            snapshot.data!.docs.map((DocumentSnapshot document) {
              data = document.data()! as Map<String, dynamic>;
            }).toList();
          } catch (e) {
            print(e.toString());
          }
       },
      ),
    );
寂寞笑我太脆弱 2025-01-29 09:54:15
 Expanded(
          child: StreamBuilder(
            stream:
                FirebaseFirestore.instance.collection("posts").snapshots(),
            builder: (context,
                AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>
                    snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return const Center(
                  child: CircularProgressIndicator(),
                );
              }

              if (snapshot.hasData) {
                return ListView.builder(
                  itemCount: snapshot.data!.docs.length,
                  itemBuilder: (context, index) {
                    log(snapshot.data!.docs[index].data().toString());

                    return UserVideos(
                      snap: snapshot.data!.docs[index].data(),
                    );
                  },
                );
              }
              log("${snapshot.stackTrace}stack trace");
              log("${snapshot.error}error");
              return const Text("Something went wrong");
            },
          ),
        ),
 Expanded(
          child: StreamBuilder(
            stream:
                FirebaseFirestore.instance.collection("posts").snapshots(),
            builder: (context,
                AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>>
                    snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return const Center(
                  child: CircularProgressIndicator(),
                );
              }

              if (snapshot.hasData) {
                return ListView.builder(
                  itemCount: snapshot.data!.docs.length,
                  itemBuilder: (context, index) {
                    log(snapshot.data!.docs[index].data().toString());

                    return UserVideos(
                      snap: snapshot.data!.docs[index].data(),
                    );
                  },
                );
              }
              log("${snapshot.stackTrace}stack trace");
              log("${snapshot.error}error");
              return const Text("Something went wrong");
            },
          ),
        ),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文