【问题标题】:ListTile susbtitle renderflex overflowedListTile 子标题 renderflex 溢出
【发布时间】:2021-08-20 09:29:32
【问题描述】:

我有这样的 ListTile 字幕:

     subtitle:Flexible(flex:1,child:Row(children: [
                    (widget.condiments!=null)?Padding(
                 child:Text(condimentList,style: TextStyle(color:Colors.grey)),
                   padding: EdgeInsets.only(top: 10)):null,
               ])),
 trailing:  Row(             
            mainAxisSize: MainAxisSize.min,     
            children: <Widget>[
              IconButton(
              icon: Icon(Icons.delete))])

我收到以下错误:

A RenderFlex overflowed by 244 pixels on the right.
The relevant error-causing widget was
Row

我希望将它包裹在 Flexible 周围应该可以做到,但似乎我不太知道如何解决它。

【问题讨论】:

    标签: flutter


    【解决方案1】:

    只需在 Expanded 中换行即可,无需使用换行。

    dartpad 上查看 UI 输出。

    ListTile(
          title: const Text('Test'),
          trailing: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
            IconButton(onPressed: () {}, icon: const Icon(Icons.delete))
          ]),
          subtitle: Row(children: const [
            Expanded(
                child: Padding(
              padding: EdgeInsets.all(5),
              child: Text(
                'This is a test & this will have a very long paragragh to check the errors once. This is a test & this will have a very long paragragh to check the errors once.',
              ),
            ))
          ]),
        );
    

    扩展后的 UI 输出:

    未展开的 UI 输出:

    【讨论】:

    • 请查看我编辑的问题。似乎问题出在尾随代码上。
    • @bangbang 我更新了我的答案,我没有遇到任何问题,请检查答案中的飞镖垫,以获得 UI 输出
    【解决方案2】:
    SizedBox(
      width : MediaQuery.of(context).size.width,
      child:  Row(children: [
                    (widget.condiments!=null)?Padding(
                 child:Text(condimentList,style: TextStyle(color:Colors.grey)),
                   padding: EdgeInsets.only(top: 10)),
               ]),
    ):null;
    

    【讨论】:

    • 尝试使用 Sizedbox 包装行小部件,其屏幕宽度为宽度。
    • 我收到此错误:没有为“MediaQueryData”类型定义 getter 'width'。尝试导入定义“width”的库,将名称更正为现有 getter 的名称,或者定义一个名为“width”的 getter 或字段
    • 一个 RenderFlex 在右侧溢出了 199 个像素。从 204 到 199
    • 请在问题中查看我编辑的代码。我添加了尾随代码,我确定这是导致错误的原因。
    猜你喜欢
    • 2021-12-24
    • 2021-11-17
    • 2020-12-27
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    相关资源
    最近更新 更多