I have a SliverList with a delegate that returns Row for each item. The design requires this result:
The two children are Text and Image. The Image fir is BoxFit.cover and I am using Flexible to give them the desired width ratio. I need the image boundary height to match the text height only if the height is greater than or equal to width boundary (to keep it at least a square).
First solution was to use LayoutBuilder to read the constraints of the image width and put the image in a ConstrainedBox with minHeight of LayoutBuilder->constraints->maxWidth.
LayoutBuilder(
builder: (context, constraints) => ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxWidth,
maxHeight: constraints.maxWidth),
child: CachedNetworkImage(
imageUrl: "https://via.placeholder.com/400x300",
fit: BoxFit.cover,
),
),
)
All is well until the text is longer than image width, at this point the image remains a square and does not stretch to the full row height:
Second solution was to wrap the Row in an IntrinsicHeight widget. But this means I can't use the LayoutBuilder inside it. So I removed the Layout builder and now I can't access the constraints to set the Image minHeight. The Image stretches very well to fill the full Row height. Until when the text is too short, which makes the image height go below its width:
How can I build this design to be responsive with variable text height?




