首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从防火墙中检索数据以显示产品

如何从防火墙中检索数据以显示产品
EN

Stack Overflow用户
提问于 2021-09-30 13:12:17
回答 1查看 25关注 0票数 0

我试图在主页上展示我的产品,从百货公司的收藏中提取出来,并使用StreamBuilder展示。但我的主屏幕显示的是它回归的“喜喜”。我使用了正确的集合引用和正确的字段名。

在这种情况下,您的帮助将帮助初学者颤栗开发人员完成他的大学项目。

谢谢

这是我的密码

代码语言:javascript
复制
Container(
            height: 190,
            child: StreamBuilder(
                stream: collectionReference.snapshots(),
                builder: (BuildContext context,
                    AsyncSnapshot<QuerySnapshot> snapshot) {
                  if (snapshot.hasData) {
                    return ListView.builder(
                        scrollDirection: Axis.horizontal,
                        padding: EdgeInsets.only(left: 16, right: 6),
                        itemCount: 4,
                        itemBuilder: (context, index) {
                          children:
                          snapshot.data!.docs.map(
                            (e) => Container(
                              margin: EdgeInsets.only(right: 10),
                              height: 199,
                              width: 344,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(28),
                                color: Colors.white,
                                boxShadow: [
                                  BoxShadow(
                                    color: Colors.grey,
                                    offset: Offset(0.0, 1.0), //(x,y)
                                    blurRadius: 6.0,
                                  ),
                                ],
                              ),
                              child: Stack(
                                children: [
                                  Padding(
                                    padding: const EdgeInsets.all(10.0),
                                    child: Positioned(
                                      child: Image(
                                        image: AssetImage(
                                          'assets/item1.png',
                                        ),
                                        height: 200,
                                      ),
                                    ),
                                  ),
                                  Positioned(
                                    right: 20,
                                    top: 10,
                                    child: Text(
                                      e['name'],
                                      style: TextStyle(
                                          color: Colors.black,
                                          fontSize: 25,
                                          fontFamily: 'Poppins',
                                          fontWeight: FontWeight.bold),
                                    ),
                                  ),
                                
                                  Positioned(
                                    right: 20,
                                    bottom: 10,
                                    child: Text(
                                      e['price'],
                                      style: TextStyle(
                                          color: Colors.black,
                                          fontSize: 30,
                                          fontFamily: 'Poppins'),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          );
                          return Center(child: Text('hi'));
                        });
                  }
                  return Center(child: Text('Empty'));
                }),
          ),
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-30 13:47:12

问题是itemBuilder应该返回如何构建ListView中的每个项目。目前,您要做的是映射整个快照,然后返回一个包含hi的计划文本小部件。为itemBuilder尝试下面的代码:

代码语言:javascript
复制
itemBuilder: (context, index) {
    final e = snapshot.data!.docs[index];
    return Container(
      margin: EdgeInsets.only(right: 10),
      height: 199,
      width: 344,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(28),
        color: Colors.white,
        boxShadow: [
          BoxShadow(
            color: Colors.grey,
            offset: Offset(0.0, 1.0), //(x,y)
            blurRadius: 6.0,
          ),
        ],
      ),
      child: Stack(
        children: [
          Padding(
            padding: const EdgeInsets.all(10.0),
            child: Positioned(
              child: Image(
                image: AssetImage(
                  'assets/item1.png',
                ),
                height: 200,
              ),
            ),
          ),
          Positioned(
            right: 20,
            top: 10,
            child: Text(
              e['name'],
              style: TextStyle(
                  color: Colors.black,
                  fontSize: 25,
                  fontFamily: 'Poppins',
                  fontWeight: FontWeight.bold),
            ),
          ),
        
          Positioned(
            right: 20,
            bottom: 10,
            child: Text(
              e['price'],
              style: TextStyle(
                  color: Colors.black,
                  fontSize: 30,
                  fontFamily: 'Poppins'),
            ),
          ),
        ],
      ),
    );
}

还请记住,您的itemCount是4,您可能想要的是:

代码语言:javascript
复制
itemCount: snapshot.data!.docs.length
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69392872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档