Flutter Error: type 'Image' is not a subtype of type 'ImageProvider<Obejct>' in type cast – when trying to use a GIF as background

huangapple go评论44阅读模式
英文:

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(
            &quot;images/gif_day.mp4&quot;,
            height: 125.0,
            width: 125.0,
          ) as ImageProvider : 
           const AssetImage(&#39;assets/images/Environment.png&#39;),
        ),  
      ),
)

But I get the error:
type &#39;Image&#39; is not a subtype of type &#39;ImageProvider&lt;Obejct&gt;&#39; 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(
        &quot;images/gif_day.gif&quot;,
      )  
       const AssetImage(&#39;assets/images/Environment.png&#39;),
    ),  
  ),
)

if you want to use gif as image this is the website convert your video to gif here and use it as AssetImage widget

huangapple
  • 本文由 发表于 2023年2月6日 21:41:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75362073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定