简体   繁体   English

Flutter ListTile 标题溢出问题

[英]Flutter ListTile title overflow issue

I'm displaying a long text inside ListTile's title using the following code and I'm having UI issue with the Text overflow feature:我正在使用以下代码在 ListTile 的title中显示一个长文本,并且我遇到了Text溢出功能的 UI 问题:

ListTile(
  contentPadding: const EdgeInsets.symmetric(horizontal: 32.0),
  leading: SizedBox(
    width: 32.0,
    child: Center(
      child: Container(
        width: 32.0,
        height: 32.0,
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: HexColor.fromHex(_clientStatusList.first.color)
              .withOpacity(0.2),
          border: Border.all(
              color: HexColor.fromHex(_clientStatusList.first.color)),
        ),
        child: Center(
            child: Icon(
          CustomIcons.customer_important,
          size: 14.0,
          color: HexColor.fromHex(_clientStatusList.first.color),
        )),
      ),
    ),
  ),
  title: Text(
    _clientStatusList.map((e) => e.name).join(", "),
    maxLines: 1,
    overflow: TextOverflow.ellipsis,
  ),
  subtitle: Text("Status"),
),

Result from the above code: https://i.stack.imgur.com/O5Euf.png上述代码的结果: https://i.stack.imgur.com/O5Euf.png

Result without maxLines and overflow : https://i.stack.imgur.com/VWOpF.png结果没有maxLinesoverflowhttps://i.stack.imgur.com/VWOpF.png

I guess that the expected result is: https://i.stack.imgur.com/OFMoT.png我猜预期的结果是: https://i.stack.imgur.com/OFMoT.png

Flutter doctor: Flutter博士:

[✓] Flutter (Channel stable, v1.17.2, on Mac OS X 10.15.5 19F96, locale en-IL)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.45.1)
[✓] Connected device (1 available)

The documentation fo maxLine says: maxLine 的文档说:

If this is 1 (the default), the text will not wrap, but will scroll horizontally instead.如果这是 1(默认值),文本将不换行,而是水平滚动。

so, the output is right according to widget.因此,根据小部件,output 是正确的。

I would suggest link 1 and link 2 to take a look.我建议链接 1链接 2看看。

NB: You can try with Expanded() Widget, sometimes it is handy to use full empty space.注意:您可以尝试使用Expanded()小部件,有时使用完整的空白空间很方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM