【问题标题】:Flutter - Wrap text with overflow.elipsis, it won't work like the way i wantFlutter - 用 overflow.ellipsis 包装文本,它不会像我想要的那样工作
【发布时间】:2022-07-21 16:08:13
【问题描述】:

这是我的省略号文本部分的代码

         Padding(
              padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
              child: Row(
                children: [
                  Flexible(
                    flex: 10,
                    child: Container(
                      padding: const EdgeInsets.only(right: 13.0),
                      child: const Text(
                        '\$ 900.000.000',
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 18,
                          color: Colors.red,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                  ),
                  const Flexible(
                    flex: 3,
                    child: Icon(
                      Icons.favorite_border_outlined,
                    ),
                  ),
                ],
              ),
            ),

我正在尝试创建一条显示价格的线,如下所示。

$ 2.000.00....

但结果是这样的

我已经尝试使用这个参考,但它仍然无法工作Flutter - Wrap text on overflow, like insert ellipsis or fade 我希望文本仍然与其他文本聚集在一起,而没有像 this was a long text loooooooooooooooooooooooooooooooooooooooong 这样的空间@

【问题讨论】:

    标签: flutter dart text flutter-layout flutter-text


    【解决方案1】:

    TextOverflow.ellipsis 检查是否有“\u2026”来剪辑文本。您可以将其替换为“\u{200B}”

     child: Padding(
                    padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
                    child: Row(
                      children: [
                        Flexible(
                          flex: 10,
                          child: Container(
                            padding: const EdgeInsets.only(right: 13.0),
                            child: Text(
                              ('\$ 900.000.000').replaceAll("", "\u{200B}"),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                fontSize: 18,
                                color: Colors.red,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                        const Flexible(
                          flex: 3,
                          child: Icon(
                            Icons.favorite_border_outlined,
                          ),
                        ),
                      ],
                    ),
                  ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多