导致错误的相关小部件是Column| Flutter

yfwxisqw  于 2022-11-30  发布在  Flutter
关注(0)|答案(1)|浏览(104)

在StreamBuilder中使用列时显示此错误
错误:
渲染库捕获异常RenderBox未布局:渲染重新绘制边界#6d45d重新绘制边界= up2需要绘制'软件包:flutter/src/rendering/box. dart':包:flutter/.../rendering/box. dart:1Assert失败:第2001行位置12:'具有大小'
导致错误的相关小部件是Column

body: StreamBuilder(
          stream: FirebaseFirestore.instance
              .collection("posts")
              .orderBy('datePublished', descending: true)
              .snapshots(),
          builder: (context,
              AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>> snapshot) {
            
            //connection no problem
            return Column(
              children: [
                SizedBox(
                  height: 100.0,
                  child: ListView.builder(
                    shrinkWrap: true,
                    scrollDirection: Axis.horizontal,
                    itemCount: 5,
                    itemBuilder: (context, index) => Container(
                      padding: const EdgeInsets.all(12),
                      margin: const EdgeInsets.all(12),
                      height: 250,
                      width: 150,
                      color: Colors.pink,
                    ),
                  ),
                ),
                ListView.builder(
                  itemCount: snapshot.data!.docs.length,
                  itemBuilder: (context, index) => PostCard(
                    snap: snapshot.data!.docs[index].data(),
                  ),
                )
              ],
            );
          },
        ));
0x6upsns

0x6upsns1#

ListView需要有界大小,当你用Expanded Package 它时,你设置了它的界,试试这个:

Expanded(
    child: ListView.builder(
      itemCount: snapshot.data!.docs.length,
      itemBuilder: (context, index) => PostCard(
        snap: snapshot.data!.docs[index].data(),
      ),
    ),
  ),

相关问题