英文:
Flutter Error: type 'Image' is not a subtype of type 'ImageProvider<Obejct>' in type cast - when trying to use a GIF as background
问题
我的目标是将GIF用作背景。
我尝试了这个:
return Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: true ? Image.asset(
"images/gif_day.mp4",
height: 125.0,
width: 125.0,
) as ImageProvider :
const AssetImage('assets/images/Environment.png'),
),
),
);
但是我遇到了错误:
type 'Image' is not a subtype of type 'ImageProvider<Object>' in type cast
我认为这是一个已知的问题,我尝试了其他帖子中提到的解决方案,但无法解决。
英文:
My goal is to use a GIF as the background.
I tried this:
return Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: true? Image.asset(
"images/gif_day.mp4",
height: 125.0,
width: 125.0,
) as ImageProvider :
const AssetImage('assets/images/Environment.png'),
),
),
)
But I get the error:
type 'Image' is not a subtype of type 'ImageProvider<Obejct>' in type cast
I think this is a known issue and I tried the solutions from other posts with the same problem, but I can't get it to work.
答案1
得分: 0
无法将Image分配给ImageProvider,请尝试以下方式:
return Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage("images/gif_day.gif"),
),
),
)
如果您想要使用GIF作为图像,请使用这个网站将您的视频转换为GIF,然后将其作为AssetImage小部件使用。
英文:
you can not assign Image to the ImageProvider try this instead
return Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: true? AssetImage(
"images/gif_day.gif",
)
const AssetImage('assets/images/Environment.png'),
),
),
)
if you want to use gif as image this is the website convert your video to gif here and use it as AssetImage widget
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论