I want to show a list of elements, which have a picture, a title and some additional information in Flutter. My layout is supposed to look like this:
I have implemented this using a ListView with Card children. I then use a Row to have the image on the left and the info on the right. Then I use a Column to have my title on top and the rest of the info below.
My problem is with the title, which may be too large for width of its container. What I originally thought was letting the user scroll through the text, but I'm not sure if it is possible to nest two scrolling-enabled widgets in Flutter, so I settled with using TextOverflow.ellipsis. However in my basic setup TextOverflow.ellipsis has no effect, and instead I face an overflow error.
After looking this up online I figured that I had to put my Text into an Expanded or Flexible, which themselves had to be a direct child of a Flex (I used Row). However this wasn't enough still, as I got the following error: RenderFlex children have non-zero flex but incoming width constraints are unbounded.. To fix this I had to add a Container as parent of my Row (Flex) with a fixed width.
Here is my current code:
Card(
color: backgroundColor,
child: Row(
children: <Widget>[
MyImageWidget(),
Container(
height: 60,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 12),
height: 30,
width: 340, // I don't want this
child: Row(
children: [
Expanded(
child: Text(
"Title which may be long, very very long",
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
],
),
),
],
),
),
],
),
);
Is there a way to get rid of this fixed width constraint? I know that I could use Media Queries but I don't want to do this unless I absolutely have to, because I might change the padding of several elements, or even move to a grid view on larger screens.
Or if I absolutely have to set this fixed width, is there a way I could ask Flutter to find out what the width of my Container would be if it had no content, and then apply it as fixed width of itself?
