簡體   English   中英

如何為 Flutter 容器提供相當於其內部列表視圖子項的高度

[英]How to give to a Flutter container the Height equivalent to the listview child inside himself

當我沒有給容器一個高度時我有一個錯誤,它給我這個錯誤:

========渲染庫捕獲異常===================================== ================ 在 paint() 期間拋出以下 _CastError:Null 檢查運算符用於 null 值

所以為什么我 gihe hime 高度:200 但它的 static 高度我想給容器一個 listview 的大小在他里面。

容器代碼:

    Container(
       // height:200,
        alignment: Alignment.topLeft,
        decoration: const BoxDecoration(
            border: Border(
          // top: BorderSide(color: Colors.black12),
          bottom: BorderSide(color: Colors.black12),
        )),
        padding: const EdgeInsets.fromLTRB(10, 5, 0, 20),
        child: Column(
          children: <Widget>[
            Container(width: 22, color: colors),
            Expanded(
              child: ListView.builder(
                  padding: const EdgeInsets.symmetric(vertical: 8.0),
                  itemCount: reposReplay?.length,
                  itemBuilder: (context, index) {
                    return Column(
                      children: <Widget>[
                        ListTile(
                          title: Column(children: [
                            Padding(
                              padding:
                                  const EdgeInsets.fromLTRB(0, 0, 0, 10),
                              child: Row(
                                children: [
                                  Expanded(
                                    child: Text("${reposReplay?[index].by}",
                                        textAlign: TextAlign.start,
                                        style: const TextStyle(
                                            fontSize: 14,
                                            color: Colors.deepOrangeAccent,
                                            fontWeight: FontWeight.bold)),
                                  ),
                                  Expanded(
                                    child: Text(time,
                                        textAlign: TextAlign.end,
                                        style: const TextStyle(
                                            fontSize: 14,
                                            color: Colors.deepOrangeAccent,
                                            fontWeight: FontWeight.bold)),
                                  ),
                                ],
                              ),
                            ),
                          ]),
                          subtitle: Text("${reposReplay?[index].text!.replaceAll("&#x27;", "'").replaceAll("&gt;", ">").replaceAll("&quot;", "\"").replaceAll("&#x2F;", "/").replaceAll("<p>", "\n").replaceAll("&gt;.&quot;", ">.").replaceAll(exp, "")}",
                              textAlign: TextAlign.justify,
                              style: const TextStyle(
                                  fontSize: 15,
                                  fontWeight: FontWeight.normal, color: Colors.black)),
                        ),
                        const Divider(
                          height: 2.0,
                        ),
                      ],
                    );
                  }),
            )
          ],
        )
    ),

在 listview.builder 中使用以下內容:

physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM