简体   繁体   English

如何将省略号添加到行小部件中两个文本小部件之间的文本小部件

[英]How to add ellipsis to a text widget in between two text widget in a row widget

I am in need to create a UI similar to below illustration.我需要创建一个类似于下图的 UI。 The second text to shrink to give space for third text in a row.要缩小的第二个文本为连续的第三个文本留出空间。

Excepted UI例外的用户界面

例外的用户界面

But the second text doesn't shrink whereas the third text widget shrinks但是第二个文本不会缩小,而第三个文本小部件会缩小

Present UI呈现用户界面

在此处输入图像描述

I used expanded to wrap the third Text widget.我使用扩展来包装第三个 Text 小部件。 It didn't help.它没有帮助。

Row(children: [
  Container(color:Colors.lightBlue, child:Text('1one'),),
  Container(
    color:Colors.lightGreen,
    child:Text(
      '2Two2Two2Two2dbTwo2Two2Two2Two2Two2Two2Two2Two2Two2Two2Two2Two2', 
      overflow: TextOverflow.ellipsis)),
  Expanded(
    child:Container(
      color:Colors.orange, 
      child: Text('Three3Three3Three3Three3Three3Three3Three3Three3Three3Three')
    )
  )
])

Dart pad Dart焊盘

Wrap the second widget with Expanded , instead of wrapping the third one.Expanded包裹第二个小部件,而不是包裹第三个。

Reason原因

Expanded widget render the child within the leftover available space, Expanded的小部件在剩余的可用空间内呈现子元素,

In the above requirement the second text needs to be rendered in the left over space not the third one, Hence the second text has to be wrapped by Expanded not the third one.在上述要求中,第二个文本需要在剩余空间中呈现,而不是第三个,因此第二个文本必须由Expanded而不是第三个包裹。

you can use expanded and flex value to distribute the whole space您可以使用扩展和弹性值来分配整个空间

Row(
            children: [
              Expanded(
                flex: 1,
                child: Container(
                  color: Colors.lightBlue,
                  child: Text('1one'),
                ),
              ),
              Expanded(
                flex: 2,
                child: Container(
                  color: Colors.lightGreen,
                  child: Text(
                      '2Two2Two2Two2dbTwo2Two2Two2Two2Two2Two2Two2Two2Two2Two2Two2Two2',
                      overflow: TextOverflow.ellipsis),
                ),
              ),
              Expanded(
                flex: 3,
                child: Container(
                  color: Colors.orange,
                  child: Text(
                    'Three3Three3Three3Three3Three3Three3Three3Three3Three3Three',
                    maxLines: 1,
                  ),
                ),
              )
            ],
          ),

Result结果在此处输入图像描述

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

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