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?
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;
}
)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With