gpt4 book ai didi

android-studio - 如果 child 有其他状况则 flutter

转载 作者:行者123 更新时间:2023-12-03 04:57:07 25 4
gpt4 key购买 nike

我正在使用Flutter测验应用程序,它从JSON文件中获取问题和图像
当应用程序正在运行且没有图像时,我会得到一个加载符号,我需要使用if删除没有图像的正在加载中的符号,但是我遇到了错误,我附上了伪代码,有人可以告诉我该怎么做。它???

 Expanded(
child: AspectRatio(
aspectRatio: 16 / 11,
child: ClipRect(
child: SizedBox(
height: 50,
child: PhotoView(
imageProvider: AssetImage(
myQuestion[i]["Image"] ?? "None"),
minScale:
PhotoViewComputedScale.contained *
0.5,
maxScale:
PhotoViewComputedScale.covered * 2,
initialScale: 0.6,
backgroundDecoration: BoxDecoration(
color: Theme.of(context).canvasColor,
),
),
),
),
),
),


最佳答案

我不能发表评论。而且我不确切知道您正在运行哪种错误,但是我认为是作为图像源提供了字符串。

您可以将逻辑检查从AssetImage中的小部件树中移到更高的位置。

Expanded(
child: AspectRatio(
aspectRatio: 16 / 11,
child: ClipRect(
child: SizedBox(
height: 50,
child: myQuestion[i]["Image"]!=null && myQuestion[i]["Image"].isNotEmpty()
? PhotoView(
imageProvider: AssetImage( myQuestion[i]["Image"] ), // we know it's not empty and is not null
minScale: PhotoViewComputedScale.contained * 0.5,
maxScale: PhotoViewComputedScale.covered * 2,
initialScale: 0.6,
backgroundDecoration: BoxDecoration(
color: Theme.of(context).canvasColor,
),
)
: Container(),
),
),
),
),


我们使用三元运算符来检查 Assets 是否不为空且不为空。如果它具有有效值,则显示图像,否则显示并清空容器。根据您要显示的内容和位置,可以将此逻辑上移到小部件树上。

关于android-studio - 如果 child 有其他状况则 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60418619/

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