Search code examples
flutterlayout

Layout in Flutter: row containing a square and 3 lines of text


I want to create the following layout: enter image description here

It's a Container, containing a Row, children:

  1. a square Container, unknown height or width
  2. a Column, children: 3 Text widgets (width is unknown)

The size of the square Container should be the height of the parent Container (its width = its height). the Column with the 3 Text widgets should expand to the rest of the parent Container.

Is it possible in Flutter? if so, how?


Solution

  • Try creating a custom widget:

    class BoxWidget extends StatelessWidget {
    
      BoxWidget(/*...*/);
      
      Widget build(_) {
        return Row(
          children: [
            AspectRatio(
              aspectRatio: 1,
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.red,
                ),
              ),
            ),
            Column(
              children: [
                Text(widget.text1, style: style),
                Text(widget.text2, style: style),
                Text(widget.text3, style: style),
              ],
            ),
          ],
        );
      }
    }