how to display animated gif in flutter? - flutter

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

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,
),

This is what used in Flutter Gallery app to display .gif from web
Image.network('https://example.com/animated-image.gif')

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 -.
Insert the last part 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.
You will get the following output url:
https://giphy.com/media/xT0xezQGU5xCDJuCPe/200.gif
Check it out. I hope it will help someone. ;)
EDIT:
Recently, Giphy changed their url format to https://i.giphy.com/media/${URL_PART}/200.gif (Special thanks to #Rivaan for mentioning it out).
Now, new url would become: https://i.giphy.com/media/xT0xezQGU5xCDJuCPe/200.gif

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

When adding a new resource to assets, restart the ide

An update to #Chetan Goyal 's answer. It throws an exception of incorrect image data now.
To display URL from Giphy that looks something like https://giphy.com/gifs/congratulations-congrats-xT0xezQGU5xCDJuCPe, we need to extract the part after hyphen i.e. xT0xezQGU5xCDJuCPe and add it to this URL: https://i.giphy.com/media/${URL_PART}/200.gif
Hope it helps someone.

Related

How to use image_cropper in flutter web?

It's said in the description of the package that is supports web. But since it's not possible to get path of the file in flutter web I can't to use it. Because the only way to work with this package is to provide path of the image
I looked at the example and you have to use Image.network instead of Image.file on web.
Then you can pass in the url to the image like this:
Image.network(
url,
);
if you what to crop image than check out crop_image package

how to: save image data to gallery [Flutter]

I have 1 question:
I use a library and it returns the Image data type, so how do I save or share the image in the library of my device?
code:
Image image = await HmsScanUtils.buildBitmap(request);
https://pub.dev/packages/gallery_saver
This plugin saves images and videos to gallery/photos.
You need to provide a path to the file that you want to save like below:
GallerySaver.saveImage(path)
You can use this package
https://pub.dev/packages/gallery_saver.
If you dont understand any documentation given on this page then you can simply follow the following tutorial by Johannes
https://www.youtube.com/watch?v=JILcQLZvjKE

How can add a specified image asset to pubspec and then load the image to AssetImage for the app to present?

I can't find anywhere teaches how to add a specified image within asset. Actually I don't know which pictures are included in the asset, or if I want to use an image from the Internet or my own photo gallery, I don't know how I can link the picture with the asset and apply it in my code.
Similarly, I also don't know what are included in packages, like font_awesome flutter. How can I check what are included? Thank you!
I think I have solved the above questions with the help of commenters, but I have more questions coming up: Why I was unable to load the asset?
Please see the pictures below.
enter image description here
enter image description here
you can place your assets in a directory in your project folder.
For example assets\drawables\ and assets\icons\
Then in your pubspec.yaml you should declare that folder. In this example:
# To add assets to your application, add an assets section, like this:
assets:
- assets/drawables/
- assets/icons/
Than in your code you can use them as follow:
Image.asset(
'assets/drawables/image.png',
width: 200,
),
For your second question, I think you only have two options:
either look for the library documentation / website, such as www.fontawesome.com (the free icons are the one in the library). Or look in the code/package yourself
Place your picture in a folder named assets like this:
Add this line to your pubspec.yaml:
Then put this somewhere in your code:
Image.asset(
'assets/my_image.png',
width: 200,
height: 200,
fit: BoxFit.contain,
);

Flutter Unable to load asset

I could find this issue as quite common, but any of the suggestions didn't help me.
I want to simply show an image:
body: new Image.asset('rh.png',width:300,height:100),
You can see it is in the correct folder
It has correct place in pubspec.yaml
But I still get an error:
Unable to load asset: rh.png
I tried a lot of suggestions from github or stackoverflow, but none of them helped me; played with spaces and tabs in .yaml file (doing flutter clean after each attempt), tried to rename .png file and put it in the subfolder - no success. Where is the catch?
You didn't add assets with the filename:
Correct way is: new Image.asset('assets/rh.png', width:300, height:100)
Complete image path should be passed for fetching any asset file
in your case using assets/rh.png would resolve the error
The problem is with your path to your .png file.
It should address properly to the file location.
Correct form would be something like below:
new Image(image: AssetImage('assets/rh.png')),

ModX Evo: TinyMCE wont insert image path into image URL in selector

This is occuring on ModX Evo 1.0.15.
When I try to select an image (or file) using TinyMCEs image selector I can upload and browse for the image but when I select it to place within my text nothing happens - the image path area remains blank.
Heres a video demonstrating what happens: https://www.youtube.com/watch?v=VSgTsyj9B6k&feature=youtu.be&hd=1
Does anyone know how to fix this?
Weird, never had that problem.
Did you try update / reinstall of Evo? (or only tinymce and kcfinder)
Are config paths correct?
Try testing in Firefox, It's possible it's related to Chrome. If it doesn't work in Firefox, Reinstall the plugin.
Clear your cache and try selecting the image.
For a temporary solution if this doesn't work, just type in the image name into the box 'images/imagename.jpg' (minus quotes)
Good Luck