how to display animated gif in flutter?

杀马特。学长 韩版系。学妹 提交于 2020-06-25 21:35:47

问题


I am trying to display gif in flutter.

I am using the code

Image(image : NetworkImage(message.image_url))

But it shows error:

Another exception was thrown: Exception: HTTP request failed, statusCode: 403, https://media.giphy.com/media/13AXYJh2jDt2IE/giphy.gif%20

回答1:


Place your gif in your images folder of your project and mention it in pubspec.yaml file,just like you do for images.

Image.asset(
                    "images/loading.gif",
                    height: 125.0,
                    width: 125.0,
                  )



回答2:


This is what used in Flutter Gallery app to display .gif from web

Image.network('https://example.com/animated-image.gif')



回答3:


Giphy does not allow you to load the image. There's nothing that flutter can do about it: https://en.wikipedia.org/wiki/HTTP_403




回答4:


I found a way with which you can download and add giphy.com's gif in your application using @Nudge answer.

Here is the trick which you can use-

Sample Giphy's .gif URL - https://giphy.com/gifs/congratulations-congrats-xT0xezQGU5xCDJuCPe

You have to split the last part of url after - and replace it in the following url- https://giphy.com/media/{URL_PART}/200.gif.

In this case, URL_PART will be xT0xezQGU5xCDJuCPe. Simply replace it in the above url and check the shocking result.

I hope it will help someone. ;)



来源:https://stackoverflow.com/questions/51556356/how-to-display-animated-gif-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!