Reputation: 103
I trying expand a container layout. I tried use Expanded widget but still not works for me properly. I would like expand to max size blue container as you can see in example bellow. Do you have any tips how I can do it? Or what widget can I use it to solve my problem?
Here is my code:
Container(
padding: EdgeInsets.all(3),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.brown.shade800,
child: Text("J")),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Some text"),
Container(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)),
child: Text("How expand this container to max width?"))
],
)
],
)
],
));
Thanks
Upvotes: 1
Views: 1878
Reputation: 1314
Wrap the column
widget with the Expanded
widget and change the crossAxisAlignment: CrossAxisAlignment.start
to crossAxisAlignment: CrossAxisAlignment.stretch
.
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text("Some text"),
Container(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)
),
child: Text("How expand this container to max width?")
)
],
),
)
Upvotes: 2
Reputation: 29438
I can't explain this, but it works only with two Expanded
s:
ConstrainedBox(
constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width),
child: Container(
padding: EdgeInsets.all(3),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.brown.shade800, child: Text("J")),
Expanded(
child: Column(
key: key,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Some text"),
Container(
decoration: new BoxDecoration(
border: new Border.all(color: Colors.blueAccent)),
child: Row(
children: <Widget>[
Expanded(
child: Text(
"How expand this container to max width?"))
],
),
),
],
),
)
],
)
],
),
),
);
Upvotes: 3