Flutter:文本中间出现三个点的文本溢出省略号

Kri*_* CN 6 flutter

有没有办法在 Flutter 中将溢出点设置为文本的中间?

一个正常的用例是显示文件名,其中文件扩展名对用户也是可见的。

即,目前,通过使用参数为 as 的Text小部件,我们得到以下结果overflowTextOverflow.ellipsis

Text(
    "IMG_100232321321312312312312312321321312321343024.PNG",
    maxLines: 1,
    overflow: TextOverflow.ellipsis,
    style: Theme.of(context).textTheme.caption,
);
Run Code Online (Sandbox Code Playgroud)

结果将类似于:

IMG_10023232132131...

有什么办法可以得到这样的结果:

IMG_10023...3024.PNG

far*_*ama 6

您可以像这样使用路径库:

导入 'package:path/path.dart' 作为路径;

   var data = "IMG_100232321321312312312312312321321312321343024.PNG";


          Row(
              children: <Widget>[
                Flexible(
                  child: Text(
                    data.split(path.extension(data))[0],
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: Theme.of(context).textTheme.caption,
                  ),
                ),
                Text(
                  path.extension(data),
                  style: Theme.of(context).textTheme.caption,
                ),
              ],
            )
Run Code Online (Sandbox Code Playgroud)


Jig*_*tel 4

可以做这样的事情..

Row(
      children: <Widget>[
        Spacer(),
        Expanded(
          child: Text(
            fileName.length > 8 ? fileName.substring(0, fileName.length - 8) : fileName,
            maxLines: 1,
            textAlign: TextAlign.end,
            overflow: TextOverflow.ellipsis,
          ),
        ),
        Expanded(
          child: Text(
            fileName.length > 8 ? fileName.substring(fileName.length - 8) : '',
            maxLines: 1,
            textAlign: TextAlign.start,
          ),
        ),
        Spacer(),
      ],
)
Run Code Online (Sandbox Code Playgroud)