Within my layout, I have a Row
. On the left side of that Row
, I have a Column
containing two Text
objects of differing font sizes. On the right side of the Row
, I have an Image
. I want the Image
to scale itself uniformly to have an equal height to the intrinsic height of the Column
on the left side of the Row
. I want this to work whether the Image
's pixel height is lesser or greater than the intrinsic height of the Column
, regardless of the font sizes used in the Text
widgets and the text scaling factor used by the operating system. (That is, I don't want to hard-code the Image
size.)
How can I make this work? I suspect I may need to cloak the Image
in some widget to make its parent think it has an intrinsic height of 0 because Image
s have intrinsic heights equal to their pixel heights.
Here is some broken code I tried in DartPad:
(Note: the network image is the same image used in the documentation @ https://flutter.dev/docs/cookbook/images/network-image . I don't have any rights to it.)
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: IntrinsicHeight(
child: Container(
color: Colors.green,
width: 600,
height: 600,
child: Row(crossAxisAlignment: CrossAxisAlignment.end, children: [
Column(children: [
Text("Larger", style: TextStyle(fontSize: 36)),
Text("Smaller", style: TextStyle(fontSize: 18))
]),
Expanded(
child: Image.network(
"https://picsum.photos/250?image=9",
alignment: Alignment.bottomRight,
fit: BoxFit.scaleDown,
))
]),
),
)));
}
}