Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderAspectRatio has unbounded constraints

I'm trying to build a scroll slider in a flutter app using this code to give to build the constraints:

var cardAspectRatio = 12.0 / 16.0;
var widgetAspectRatio = cardAspectRatio * 1.2;

AspectRatio (
aspectRatio: widgetAspectRatio,
  child: LayoutBuilder(builder: (context, constraints) {
    var width = constraints.maxWidth;
    var height = constraints.maxHeight;
})

In order to give it its width and height constraints but the resulting error says that the box constraints are unbounded:

I/flutter ( 6957): RenderAspectRatio has unbounded constraints.
I/flutter ( 6957): This RenderAspectRatio was given an aspect ratio of 
                   0.8999999999999999 but was given both unbounded
I/flutter ( 6957): constraints: BoxConstraints(unconstrained)
I/flutter ( 6957): size: MISSING
I/flutter ( 6957): aspectRatio: 0.9

How can i solve this?

like image 874
ahmed osman Avatar asked Apr 22 '19 02:04

ahmed osman


1 Answers

I had the same problem, I realized the error code gives me the solution, put the AspectRatio inside a container widget and specify its width and height. In your case, the code below will work out

Container(
    width = your width;
    height = your height;
    child:AspectRatio (
        aspectRatio: widgetAspectRatio,
        child: LayoutBuilder(builder: (context, constraints) {
            var width = constraints.maxWidth;
            var height = constraints.maxHeight;
        }
    )
)
like image 198
tom gates Avatar answered Sep 27 '22 23:09

tom gates