【问题标题】:How to handle right overflowed inside ListTile flutter如何处理ListTile颤动中的右溢出
【发布时间】:2020-09-27 03:15:10
【问题描述】:

我有 listTile 来显示标题和副标题...这是代码

ListTile(
              leading: InkWell(
                onTap: () {},
                child: Icon(Icons.fingerprint),
              ),
              title: Text("name xxx"),
              subtitle: 
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Text(
                        "xxxxxxxx",
                      ),
                      Text(
                        ' - ',
                        style: TextStyle(
                          fontSize: 10.0,
                        ),
                      ),
                      Text(
                        "yyyyyyyyyy",
                        style: TextStyle(
                          fontSize: 10.0,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
              trailing: ...
            )

当我用长句子替换 xxxxxxyyyyyyy 时...我得到了 right overflowed by 69 pixels 那么,有没有办法显示我的长字幕并防止这个问题

【问题讨论】:

    标签: list flutter dart


    【解决方案1】:

    您的问题有很多潜在的解决方案,我可以建议您两个简单的选择:

    选项 1

    如果您绝对需要显示两个 Text 小部件的所有内容,您可以将它们包装在 Wrap 中,而不是 Row

    ListTile(
      leading: InkWell(
        onTap: () {},
        child: Icon(Icons.fingerprint),
      ),
      title: Text("name xxx"),
      subtitle: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Wrap(
            children: [
              Text(
                "long text yeah long text long long and very long",
              ),
              Text(
                ' - ',
                style: TextStyle(
                  fontSize: 10.0,
                ),
              ),
              Text(
                "Another quite long stuff, it's veeery long and by no means short",
                style: TextStyle(
                  fontSize: 10.0,
                ),
              ),
            ],
          ),
        ],
      ),
    ),
    

    选项 2

    如果您需要您的 Row 及其所有子项保持在一行文本中,您可以使用 Flexible 包装您的 Text 小部件并指示它们处理潜在的溢出(可能使用省略号):

    ListTile(
      leading: InkWell(
        onTap: () {},
        child: Icon(Icons.fingerprint),
      ),
      title: Text("name xxx"),
      subtitle: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Flexible(
                child: Text(
                  "long text yeah long text long long and very long",
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
              Text(
                ' - ',
                style: TextStyle(
                  fontSize: 10.0,
                ),
              ),
              Flexible(
                child: Text(
                  "Another quite long stuff, it's veeery long and by no means short",
                  style: TextStyle(
                    fontSize: 10.0,
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ],
          ),
        ],
      ),
    ),
    

    【讨论】:

      【解决方案2】:

      Expanded 小部件包装Text 小部件:

                          children: [
                            const Expanded(child:
                            Text(
                              "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                                textAlign: TextAlign.justify,
                                overflow: TextOverflow.ellipsis,
                              ),
                            ),
                            Text(
                              ' - ',
                              style: TextStyle(
                                fontSize: 10.0,
                              ),
                            ),
                            const Expanded(child:
                            Text(
                              "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
                                textAlign: TextAlign.justify,
                                overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: 10.0,
                                ),
                              ),
                            ),
                          ],
      

      https://api.flutter.dev/flutter/widgets/Expanded-class.html

      【讨论】:

      • 嗨,在我的字幕中,我有 2 个长句子......它们是“xxx”和“yyy”......我已经尝试过你的代码,但我仍然会溢出 69 个像素...... . 有什么我应该补充的吗
      • 它有效:D,我也尝试使用Flexible,它也有效,非常感谢您的帮助
      猜你喜欢
      • 2021-09-27
      • 2022-11-29
      • 2023-01-30
      • 2023-03-04
      • 2022-01-24
      • 2022-12-20
      • 2019-09-02
      • 2019-10-10
      • 1970-01-01
      相关资源
      最近更新 更多