Michael S
Michael S

Reputation: 769

How to configure a container in flutter to use the same height of an other children in the same row or column

I like to increase the height of the widget "B" so the orange color use the same space like the green color. I have added a code example. If a added Extended() like Expanded(Container(Text('B'))) the full horizontal space of the screen is used. If a added Extended() like Column(Expanded(Container(Text('B')))) the full vertical space of the screen is used.

Does someone has a hint? Thank you in advance!

Gretings

Michael

Problem:

enter image description here

Goal:

enter image description here

Code:

import 'package:flutter/material.dart';

void main() {
  runApp(DemoX());
}

class DemoX extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                color: Colors.red,
                child: Container(
                  color: Colors.green,
                  child: Text('A1\nA2'),
                ),
              ),
              Container(
                color: Colors.orange,
                child: Text('B'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Upvotes: 1

Views: 1196

Answers (1)

CopsOnRoad
CopsOnRoad

Reputation: 268374

Screenshot

enter image description here


Code:

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: SafeArea(
      child: IntrinsicHeight(
        child: Row(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Container(
              color: Colors.green,
              child: Text('A1\nA2'),
            ),
            Container(
              color: Colors.orange,
              child: Text('B'),
            ),
          ],
        ),
      ),
    ),
  );
}

Upvotes: 8

Related Questions