Another exception was thrown: RenderBox was not laid out: RenderFlex#6ac69

huangapple go评论64阅读模式
英文:

Another exception was thrown: RenderBox was not laid out: RenderFlex#6ac69

问题

我想要显示一个列表,数据来自API。但是我遇到了错误。

另一个异常被抛出:RenderBox没有布局:RenderPadding#64692 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

我不知道这是什么错误。。

以下是我的问题代码:

return AlertDialog(
    insetPadding: EdgeInsets.only(bottom: 520),
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
    title: Container(
        color: Color.fromARGB(255, 253, 253, 253),
        child: Text('Comment', style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
        padding: const EdgeInsets.all(17),
        margin: const EdgeInsets.all(0),
    ),
    titlePadding: const EdgeInsets.all(0),
    content: SingleChildScrollView(
        child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
            GridView.builder(
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 1,
                ),
                itemCount: commentList.length,
                itemBuilder: (BuildContext context, int index) {
                    return Padding(
                        padding: const EdgeInsets.all(2.0),
                        child: Container(
                            child: InkWell(
                                child: Container(
                                    padding: EdgeInsets.only(bottom: 10, top: 10, left: 20, right: 20),
                                    decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(12),
                                        border: Border.all(color: Color(0xffD4D4D4), width: 2.0)),
                                    child: Column(
                                        children: <Widget>[
                                            SizedBox(height: 15),
                                            Expanded(
                                                child: Text(
                                                    "test",
                                                    textAlign: TextAlign.justify,
                                                    style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal),
                                                ))
                                        ],
                                    )),
                            )),
                    );
                },
            ),
        ])),
);

希望这可以帮助你解决问题。

英文:

I want to display list and the data come from API. And I got error

Another exception was thrown: RenderBox was not laid out: RenderPadding#64692 relayoutBoundary=up5
NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

I don't know what kind of error is this..

Bellow is my issue code

return AlertDialog(
    insetPadding: EdgeInsets.only(bottom: 520),
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
    title: Container(
        color: Color.fromARGB(255, 253, 253, 253),
        child: Text(&#39;Comment&#39;, style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
        padding: const EdgeInsets.all(17),
            margin: const EdgeInsets.all(0),
    ),
    titlePadding: const EdgeInsets.all(0),
        content: SingleChildScrollView(
            child: Column(mainAxisSize: MainAxisSize.min, children: &lt; Widget &gt; [
                GridView.builder(
                    gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 1,
                        ),
                        itemCount: commentList.length,
                        itemBuilder: (BuildContext context, int index) {
                            return Padding(
                                padding: const EdgeInsets.all(2.0),
                                    child: Container(
                                        child: InkWell(
                                            child: Container(
                                                padding: EdgeInsets.only(bottom: 10, top: 10, left: 20, right: 20),
                                                decoration: BoxDecoration(
                                                    borderRadius: BorderRadius.circular(12),
                                                    border: Border.all(color: Color(0xffD4D4D4), width: 2.0)),
                                                child: Column(
                                                    children: &lt; Widget &gt; [
                                                        SizedBox(height: 15),
                                                        Expanded(
                                                            child: Text(
                                                                &quot;test&quot;,
                                                                textAlign: TextAlign.justify,
                                                                style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal),
                                                            ))
                                                    ],
                                                )),
                                        )),
                            );
                        },
                ),
            ])),
);

答案1

得分: 2

SingleChildScrollView 只能包含一个子元素,而 GridView 会扩展以填充可用空间。

为了解决这个问题,您可以将您的 GridView 包装在一个 SizedBox 中,并为其指定一些高度/宽度:

AlertDialog(
  insetPadding: EdgeInsets.only(bottom: 520),
  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
  title: Container(
    color: Color.fromARGB(255, 253, 253, 253),
    child: Text('Comment',
        style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
    padding: const EdgeInsets.all(17),
    margin: const EdgeInsets.all(0),
  ),
  titlePadding: const EdgeInsets.all(0),
  content: SingleChildScrollView(
      child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
        // 在这里添加 SizedBox
        SizedBox( 
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height * 0.5,
          child: GridView.builder(
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 1,
            ),
            itemCount: commentList.length,
            itemBuilder: (BuildContext context, int index) {
              return Padding(
                padding: const EdgeInsets.all(2.0),
                child: Container(
                    child: InkWell(
                  child: Container(
                      padding: EdgeInsets.only(
                          bottom: 10, top: 10, left: 20, right: 20),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(12),
                          border:
                              Border.all(color: Color(0xffD4D4D4), width: 2.0)),
                      child: Column(
                        children: <Widget>[
                          SizedBox(height: 15),
                          Expanded(
                              child: Text(
                            "test",
                            textAlign: TextAlign.justify,
                            style: TextStyle(
                                fontSize: 15, fontWeight: FontWeight.normal),
                          ))
                        ],
                      )),
                )),
              );
            },
          ),
        ),
      ])),
);
英文:

The SingleChildScrollView can only have one child, and the GridView expands to fill the available space.

To fix the problem, wrap your GridView with a SizedBox and give it some height/width:

AlertDialog(
      insetPadding: EdgeInsets.only(bottom: 520),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
      title: Container(
        color: Color.fromARGB(255, 253, 253, 253),
        child: Text(&#39;Comment&#39;,
            style: TextStyle(color: Color.fromARGB(255, 4, 4, 4))),
        padding: const EdgeInsets.all(17),
        margin: const EdgeInsets.all(0),
      ),
      titlePadding: const EdgeInsets.all(0),
      content: SingleChildScrollView(
          child: Column(mainAxisSize: MainAxisSize.min, children: &lt;Widget&gt;[
            // &lt;--- Add SizedBox here
        SizedBox( 
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height * 0.5,
          child: GridView.builder(
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 1,
            ),
            itemCount: commentList.length,
            itemBuilder: (BuildContext context, int index) {
              return Padding(
                padding: const EdgeInsets.all(2.0),
                child: Container(
                    child: InkWell(
                  child: Container(
                      padding: EdgeInsets.only(
                          bottom: 10, top: 10, left: 20, right: 20),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(12),
                          border:
                              Border.all(color: Color(0xffD4D4D4), width: 2.0)),
                      child: Column(
                        children: &lt;Widget&gt;[
                          SizedBox(height: 15),
                          Expanded(
                              child: Text(
                            &quot;test&quot;,
                            textAlign: TextAlign.justify,
                            style: TextStyle(
                                fontSize: 15, fontWeight: FontWeight.normal),
                          ))
                        ],
                      )),
                )),
              );
            },
          ),
        ),
      ])),
    );

huangapple
  • 本文由 发表于 2023年1月9日 03:56:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75050842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定