0

how to trim text in textformfield if very long text like overflow.ellipse in Text?

TextFormField

Afdal
  • 501
  • 9
  • 19

1 Answers1

0

Reading your question and the comments, it looks like the problem you have might be related to layouts, rather than the Text widget itself.

You need to make sure your Text widget has a bounded width, for example, you can use Expanded to make it fill all remaining spaces in Row:

Row(
  children: [
    Expanded( // won't work if you remove the `Expanded` here
      child: Text(
        'lorem ipsum ' * 20,
        overflow: TextOverflow.ellipsis,
      ),
    ),
    ElevatedButton(
      onPressed: () {},
      child: Text('Button'),
    ),
  ],
),

Comparison with and without the Expanded widget in the above code:

demo picture

Similarly, you can use SizedBox or any other methods, to make sure the Text widget has a finite width.

WSBT
  • 33,033
  • 18
  • 128
  • 133