【问题标题】:Expanded Widget throws " RenderBox was not laid out" ExceptionExpanded Widget 抛出“RenderBox 未布局”异常
【发布时间】:2019-04-08 11:51:49
【问题描述】:

我是新来的颤振。我正在设置一个包含 ListView 小部件的扩展小部件。 Expanded Widget 位于 Column Widget 中。但是运行代码会给出“RenderBox 未布局”异常。如何修复代码?

 Widget build(BuildContext context) {
    return ListView(
      children: products
          .map(
            (element) => Card(
                  child: Column(
                    children: <Widget>[
                      Text(element)
                    ],
                  ),
                ),
          )
          .toList(),
    );
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.all(10.0),
          child:   ProductControl(_addProduct),
        ),
        Expanded(
          child: Products(_products),
        )
      ],
    );
  }

错误:

I/flutter ( 9914): Another exception was thrown: RenderBox was not laid out: RenderFlex#e84ab relayoutBoundary=up2 NEEDS-PAINT

【问题讨论】:

  • 你的问题我不清楚。您提供了 2 个构建方法,哪个导致 isuse?
  • 这是第二个。 Product 类是一个 ListView 小部件。
  • 您可以发布您的Products 课程吗?对我来说,它现在工作正常。

标签: flutter


【解决方案1】:

ListViewScrollView 一起使用时,请使用Flexible 而不是Expanded

【讨论】:

  • 成功了吗?如果您仍有问题,请告诉我。
【解决方案2】:

您可以使用 Flexible 或 Try wrapping expand 在具有固定宽度和高度的容器中

    Widget build(BuildContext context) {
        return Column(
          children: <Widget>[
            Container(
              margin: EdgeInsets.all(10.0),
              child:   ProductControl(_addProduct),
            ),
           container(
            width:300,//set as required
            height:300,
            child:  Expanded(
              child: Products(_products),
            ),
           ),
          ],
        );
      }

【讨论】:

    猜你喜欢
    • 2023-01-24
    • 2021-11-24
    • 1970-01-01
    • 2021-06-03
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多