how to trim text in textformfield if very long text like overflow.ellipse in Text?
Asked
Active
Viewed 428 times
0

Afdal
- 501
- 9
- 19
-
do you want to trim text till end or you want ellipse feature like android native?? – DeePanShu Oct 07 '21 at 09:29
-
you can give maxLines for textformfield. – Jignesh Patel Oct 07 '21 at 09:35
-
just trim to show in TextField but actual text not trim ... because if line > 1 will be overflow .. so i want trim ellipse to fix overflow @DeePanShu – Afdal Oct 07 '21 at 09:37
-
i've try maxLine = 1 .. but, is not trim ... i can scroll horizontall in TextField to see long text @JigneshPatel – Afdal Oct 07 '21 at 09:38
-
@Afdal Can you give maxLine = 2? – Jignesh Patel Oct 07 '21 at 09:41
-
did you tried this: https://stackoverflow.com/a/62737859/10954249 – DeePanShu Oct 07 '21 at 09:41
-
this Text Widget sir.. not TextFormField @DeePanShu – Afdal Oct 07 '21 at 09:45
-
i've try.. is not trim.. but, i see height of TextField 2 and i can scroll vertical – Afdal Oct 07 '21 at 09:48
-
https://github.com/flutter/flutter/issues/62963 : no solution set for this, you have to make your custom TextInputField – DeePanShu Oct 07 '21 at 09:51
-
ohh i see,,, thanks @DeePanShu – Afdal Oct 07 '21 at 10:04
1 Answers
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:
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