82

In Android, we can do the following to make ImageView to fill as much space as possible depending on the size of the TextView.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

How do we achieve this in Flutter? Assume I need to make Datetime(green) to fill as much as possible.

new Column(
    children: <Widget>[
        new Text('Title',
            style: new TextStyle(fontWeight: FontWeight.bold)
        ),
        new Text('Datetime',
            style: new TextStyle(color: Colors.grey)
        ),
    ],
)

enter image description here

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Guster
  • 1,733
  • 1
  • 16
  • 18
  • Don't you want the *image* to fill up, not the text? it's an entirely different subject making the font larger – Pluriscient Apr 23 '18 at 11:36
  • I've edited the question. Please ignore the image, basically I just want to make the Datetime(the one in green) to fill as much height as possible depending on the size of Title. The font will not change. – Guster Apr 24 '18 at 02:51

6 Answers6

143

Not 100% sure but I think you mean this. The Expanded widget expands to the space it can use. Althought I think it behaves a bit differently in a Row or Column.

new Column(
children: <Widget>[
    new Text('Title',
        style: new TextStyle(fontWeight: FontWeight.bold)
    ),
    new Expanded(
        child: new Text('Datetime',
             style: new TextStyle(color: Colors.grey)
        ),
    ),
],
)
Kevin Walter
  • 6,507
  • 8
  • 28
  • 32
32

You can use:

  1. Expanded with Align to position child

    Column(
      children: [
        FlutterLogo(),
        Expanded( // add this
          child: Align(
            alignment: Alignment.bottomCenter,
            child: FlutterLogo(),
          ),
        ),
      ],
    )
    
  2. Spacer

    Column(
      children: [
        FlutterLogo(),
        Spacer(), // add this
        FlutterLogo(),
      ],
    )
    
  3. mainAxisAlignment

    Column(
      mainAxisAlignment: MainAxisAlignment.spaceBetween, // add this
      children: [
        FlutterLogo(colors: Colors.orange),
        FlutterLogo(colors: Colors.blue),
      ],
    )
    
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
13

If you need just to add blank space, use Spacer()

new Column(
children: <Widget>[
    new Text('Title',
        style: new TextStyle(fontWeight: FontWeight.bold)
    ),
    new Text('Datetime',
        style: new TextStyle(color: Colors.grey)
    ),
    Spacer(),
],
Vadim Osovsky
  • 838
  • 9
  • 14
3
Flexible(
  child: Column(
    mainAxisAlignment:MainAxisAlignment.spaceBetween,
    children: <Widget>[
        new Text('Title',
            style: new TextStyle(fontWeight: FontWeight.bold)
        ),
        new Text('Datetime',
            style: new TextStyle(color: Colors.grey)
        ),
  ],
),
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
1

This is how it worked in my case:

IntrinsicHeight(
      child: Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Flexible(
              child: Image.memory(
                File('path').readAsBytesSync(),
                width: 150,
                height: 150,
              ),
              flex: 5,
            ),
            Flexible(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('Title',
                      style: TextStyle(fontWeight: FontWeight.bold)
                  ),
                  Text('Datetime',
                      style: TextStyle(color: Colors.grey)
                  ),
                ],
              ),
              flex: 1,
            ),
          ]),
    ),
Ali Izadyar
  • 140
  • 1
  • 2
  • 13
0

You must give a height to the Row, so its children knows the avaliable space. You can do it wrapping the Row with an IntrinsicHeight Widget;