gpt4 book ai didi

flutter - RenderAspectRatio 具有无限约束

转载 作者:行者123 更新时间:2023-12-03 02:40:27 27 4
gpt4 key购买 nike

我正在尝试使用此代码在 flutter 应用程序中构建滚动 slider 来构建约束:

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;
})

为了给它它的宽度和高度约束,但结果错误表明盒子约束是无界的:
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

我该如何解决这个问题?

最佳答案

我有同样的问题,我意识到错误代码给了我解决方案,将 AspectRatio 放在容器小部件中并指定它的宽度和高度。在您的情况下,下面的代码将起作用

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

关于flutter - RenderAspectRatio 具有无限约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55788523/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com