Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

children have non-zero flex but incoming height constraints are unbounded

Tags:

flutter

return Card(
  child: Row(
    children: <Widget>[
      Placeholder(
        fallbackHeight: 100,
        fallbackWidth: 100,
      ),
      Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Container(height: 10,  child: Container(child: Text("One"),)),
          Expanded(child: Container(child:  Text("Center") )),

        ],
      )
    ],
  ),
);

On the code above I am getting error:

I/flutter ( 4872): The following assertion was thrown during performLayout(): I/flutter ( 4872): RenderFlex children have non-zero flex but incoming height constraints are unbounded. I/flutter ( 4872): When a column is in a parent that does not provide a finite height constraint, for example if it is I/flutter ( 4872): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a I/flutter ( 4872): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining I/flutter ( 4872): space in the vertical direction.

Whole code:

class FilmItems extends StatelessWidget {
  List<String> filmListList;

  List<String> _getFilmList() {
    var items = List<String>.generate(101, (counter) => "item $counter");
    return items;
  }

  FilmItems() {
    filmListList = _getFilmList();
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: filmListList.length,
        itemBuilder: (BuildContext context, int index) {
          return Card(
            child: Row(
              children: <Widget>[
                Placeholder(
                  fallbackHeight: 100,
                  fallbackWidth: 100,
                ),
                Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Container(height: 10,  child: Container(child: Text("One"),)),
                    Expanded(child: Container(child:  Text("Center") )),

                  ],
                )
              ],
            ),
          );
        });
  }
}

What is wrong?

like image 384
Dmitry Bubnenkov Avatar asked Dec 06 '25 14:12

Dmitry Bubnenkov


1 Answers

The problem is that you are using Expanded and any of it's parents have an explicit height.

The solution would depend on how do you want to handle the height of the Expanded. In your case, seems to be that you want to have a Row with a fixed height equal to the Placeholder. In that case, you need to wrap the Row with the same height as the Placeholder, like this:

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: Text("")),
    body: ListView.builder(
        itemCount: 3,
        itemBuilder: (BuildContext context, int index) {
          return Card(
            child: SizedBox(
              height: 100,
              child: Row(
                children: <Widget>[
                  Placeholder(
                    fallbackHeight: 100,
                    fallbackWidth: 100,
                  ),
                  Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text("One"),
                      Expanded(child: Center(child: Text("Center"))),
                    ],
                  ),
                ],
              ),
            ),
          );
        }),
  );
}

I removed the height 10 of the Text("One") because if the fontSize is bigger, the text would look cropped. And I wrapped the Text("Center") with a Center widget, I think that's what you wanted to achieve.

Suggestion: If the content inside the Row could haven a bigger height than the Row, the content would look cropped. If that could happen you might want to take another approach.

like image 192
Pablo Barrera Avatar answered Dec 09 '25 15:12

Pablo Barrera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!