I want to design a widget with an icon at the start and a long text in the trailing.
when I wrap them in a Row
widget, I’m getting the following result as Row does not support multiline:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(Icons.face),
Text(
'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.',
maxLines: 5,
),
],
);
}
}
but when I wrap them in a Wrap
widget, I overcome the overflow problem, however, as the Text
is a different widget from Icon
, it is starting from the second line, as shown below:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Wrap(
children: [
Icon(Icons.face),
Text(
'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.',
maxLines: 5,
),
],
);
}
}
how can I achieve a result as the photo that is shown below (clearly photoshopped):
4
Answers
One way is to consider your icon and each word as a list of widget, then
Wrap
it. So you have to handle aList<Widget>
and add first your icon, then split each word :use
RichText
One way you can do this is like so.
Try to use Text.rich: