Reputation: 557
I want to limit the number of lines and render html tags in flutter right now i am using Text widget and limiting the number of lines. The problem is i am getting html tags in my rest full api so i want to render these tags. I tried flutter html package but there is no option to limit the number of lines. Thanks
Container(
padding: EdgeInsets.symmetric(horizontal:10.0),
margin: EdgeInsets.only(bottom:10.0),
child: Text(
widget.description,
style:plpDescriptionTextstyle,
maxLines: 4,
),
),
Upvotes: 2
Views: 11377
Reputation: 926
You can try this:
Html(
data: widget.description.length > 50
? widget.description.substring(0, 45) + '...'
: widget. Description,
),
Note: Make sure to check the length of the description
, to avoid any error during substring
.
Upvotes: 0
Reputation: 180
You can use styles in this library:
Html(
data: 'Your text with html tag',
style: {
'#': Style(
fontSize: FontSize(18),
maxLines: 10,
textOverflow: TextOverflow.ellipsis,
),
},
),
Upvotes: 13
Reputation: 557
After searching hours i came to this solution incase if someone is facing same issue.
Container(
padding: EdgeInsets.symmetric(horizontal:2.0),
margin: EdgeInsets.only(bottom:10.0),
child:
Html(
data: widget.description.substring(0, 90)+'..'
),
),
Upvotes: 3