我正在尝试使用此代码在颤振应用程序中构建滚动滑块来构建约束:
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;
})
Run Code Online (Sandbox Code Playgroud)
为了给它它的宽度和高度约束,但由此产生的错误表明框约束是无界的:
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
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
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;
}
)
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2035 次 |
最近记录: |