How to create container width same width as parent?
return Container(
height:
100, //when ListView has no constrained height; it gets an infinite height https://stackoverflow.com/questions/67778027/error-renderbox-was-not-laid-out-failed-assertion-line-1940-pos-12-hassize
child: ListView.builder(
//https://api.flutter.dev/flutter/widgets/ListView-class.html
padding: const EdgeInsets.all(8),
//shrinkWrap: true,
itemCount: entries.length,
itemBuilder: (BuildContext context, int index) {
return(Container(
height: 50,
color: Colors.amber[colorCodes[index % 2]],
child: Row(children: [
//Center(child: Text(entries[index])),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container( //<-- make this container same width as parent
width: double.infinity, //doesn't work
child: Column(children: [
Text("hello"),
Expanded(child:
Align(alignment: Alignment.bottomLeft,
child:
LinearProgressIndicator(
minHeight: 5,
backgroundColor: Colors.redAccent,
value: 0.50)))
],
))),
])
//child: Center(child: LinearProgressIndicator(backgroundColor: Colors.greenAccent,value: 20))
));
}),
);
Terminal: Another exception was thrown: BoxConstraints forces an infinite width.
Question: how to make width row(or at least it’s children) same as screenwidth? Same with columnheight?
3
Answers
There are a couple issues here:
Positioned
can only be a child of theStack
widget. You’ll need to remove that widget.Row
with a child of infinite width (this is what is causing your "BoxConstraints
forces an infinite width" error. ARow
already has an unconstrained width and will fill (or even overflow) its parent if it needs to. To make the child of aRow
use up the entire available screen width, wrap the child in anExpanded
widget.Column
to take up the full screen height. It is currently wrapped in aContainer
with theheight
set to50
. If you mean theListView
, removing the outermostContainer
‘sheight
should do the trick. I don’t see any children (at least those that aren’t commented out) that should cause yourListView
to overflow.The video and explanations on this page may be helpful.
The problem is the
Positioned
that only works with theStack
parent.You need to make
Container
a direct child ofRow
which in the end will fill the width of its parent.If the requirement is to use
Positioned
, then the solution is simply to put it insideStack
widget as previously stated.If the requirement is, also, to make the child
Container
to be at the bottom of theRow
, setMainAxisAlignment.spaceBetween
tomainAxisAlignment
inRow
to force the childContainer
to the bottom.I would suggest something like this:
{{{{{{{{{{{{{{NO to any francosi… you cant fuck with a francosi}}}}}}}}}}}}}}