Search code examples
flutterrefreshbloc

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. The second text to shrink to give space for third text in a row.

Excepted UI

Excepted UI

But the second text doesn't shrink whereas the third text widget shrinks

Present UI

enter image description here

I used expanded to wrap the third Text widget. 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


Solution

  • Wrap the second widget with Expanded, instead of wrapping the third one.

    Reason

    Expanded widget render the child within the leftover available space,

    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.