1

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?

4 Answers 4

2

Based on "The Anonymous Koder"'s answer, this is the way to do it:

return IntrinsicHeight( child: Row( children: [ AspectRatio( aspectRatio: 1.0, child: Container( decoration: BoxDecoration( color: Colors.red, ), ), ), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'line 1 bla bla bla bla bla bla bla bla bla bla bla bla', overflow: TextOverflow.ellipsis, ), Text( 'line 2 bla bla bla bla bla bla bla bla', overflow: TextOverflow.ellipsis, ), Text( 'line 3', overflow: TextOverflow.ellipsis, ), ], ), ), ], ), ); 
Sign up to request clarification or add additional context in comments.

Comments

1

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), ], ), ], ); } } 

4 Comments

I prefer not to have a SingleChildScrollView for he 3 Text lines parent. I'd like to see if it's possible for that container to get the height of those 3 lines...
SingleChildScrollView is not required. You can remove it if you want to. I just add it around certain widgets to prevent overflow errors.
this results in a "RenderBox was not laid out" error - and it makes sense, since Flutter doesn't know how to layout it...
Well, wrapping the Row with IntrinsicHeight solved this issue. Thanks :)
1

Yes this is possible, first create a container then it’s child should be a row, then the children of the row should be another container which will act as the square, and then the column which will have 3 text widget as its children. Also I will advice you to wrap the container acting as the square and the column in expanded widgets both separately in the expanded widget wrapping the column set the flex to 3 and for the container expanded widget set flex to 2.

1 Comment

wrapping the sqaure and the column in flex (2 an 3) sets the width of the sqaure, meaning it won't be exactly a sqaure...
1

Yes, It's possible. The trick here is to use LayoutBuilder which returns the size that parents can allow. Here, I used maxHeight as height and as well as the width of Red Square Container and Column takes rest of the width.

Container( width: 500, //parent size height: 100, //parent size child: LayoutBuilder( builder: (context, size) { return Row( children: [ Container( color: Colors.red, height: size.maxHeight, width: size.maxHeight ), Expanded( child: Column( children: [ Expanded( child: Container(color: Colors.yellow), ), Expanded( child: Container(color: Colors.blue), ), Expanded( child: Container(color: Colors.green), ), ] ), ), ], ); }), ), 

3 Comments

I wouldn't want to set the parent container height (to 100 in your example), since the 3 lines of Text won't fit there probably... I'd like to see if it's possible for that container to get the height of those 3 lines...
I include 100 just for example. I get what you mean. So Height of the parent should be 3 * height of the Text. Is that right?
correct. Looks like IntrinsicHeight solves it. Please see my answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.