I am new to flutter. I am facing issues in displaying image on the screen that I am getting from MongoDB. The image I am getting is in the format "somenameofimage.jpg" or "somenameofimage.png".
I have searched for it, but every I see NetworkImage used for loading images from internet I guess or from assets.
I am getting the result of get request in a variable that has other details like name contact etc as well.
i use this to get image from server
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: profileData.imageAddress != null
? NetworkImage(
profileData.imageAddress)
NetworkImage works fine for me... look at the URL for the picture put it in your browser to see if it is correct or not
this works too
Image.network(profileData.imageAddress,)
Related
Hi, I would like to implement something like this in flutter. A button from which I can upload local photos from the camera or from images and files in the device to the app. Once I have taken the file I want it to appear near the button with the preview of the file as shown in the example and with the possibility of removing them. What's the best way to do this? Is there a package that does these things?
Thanks in advance!
Yes, there is! The package is image_picker.
To install it, add it as a dependency to your pubspec.yaml or run flutter pub add image_picker.
dependencies:
image_picker: ^0.8.5
Here's an example of how I've used it in my recent app:
final XFile? pickedFile = await ImagePicker().pickImage(source:
ImageSource.gallery); //This opens the gallery and lets the user pick the image
if (pickedFile == null) return; //Checks if the user did actually pick something
final File image = (File(pickedFile.path)); //This is the image the user picked
Once you've got the image, you could use a container to show it.
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: Image.file(image),
),
),
)
image is not loading in output in my screen .soo plz anyone help me in solving this
Container(
decoration: const BoxDecoration(
image:DecorationImage(image: NetworkImage(''))
),
)
Check if you added your image into the pubspec.yaml file like this:
assets:
- images/image1.jpeg
- images/icon.png
I suggest use the child of the Container and not the decoration.
Also, you could use Image.Asset instead, specifing height or/and height:
Image.asset('images/icon.png', height: 20)
Documentation here and here
Generally, Network Images on flutter take time to appear.
But if it still continues then
Check Internet Permission setting in andoidmanifes.xml file
Using Asset image is not a good solution because it makes the app size larger..
The solution is that you need to use:
Container(
child: Image.network('') //your image source
)
And if that is not the case.. the image you are using is invalid but not exactly invalid. Meaning it does not end with an image format in the end.. like (.jpg,.png etc.)
I have added images on assets folder/images. So I'm trying to make a page with an image banner and this is my code:
Container(
height: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
image: const DecorationImage(
image: AssetImage("assets/images/drive.png"),
fit: BoxFit.fill,
),
),
),
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- images/a_dot_ham.jpeg
Make sure that extension of image in your project is exactly same with those images which you added in asset folders. (.jpeg,.jpg or .png)
Must check pubspec file. Then do run one time pub get command in pubspec file. Still you can't see an image in your app then go File -> Invalidate Caches / Restart.
(You can use Image.asset also instead of AssetImage too.)
I want a fade in image with a placeholder. After searching through internet I came across FadeInImage.memoryNetwork() and it is working fine as I wanted, but now I also need to call a function when the image is loaded successfully from network, thanks to Image.network() for providing loadingBuilder() function.
But the problem is that I am not able to use both FadeInImage.network() as well as Image.network() simultaneously and I want both the property for my app.
Any suggestions how to put image placeholder using Image.network or other way round how to use loadingBuilder in FadeInImage.memoryNetwork(). Any way round will solve my problem.
Any suggestions is highly appreciated.
you can try this:
var image = Image.network(//your code);
FadeInImage(
placeholder: //your placeholder
image: image.image,
)
I can show Image from Network url in flutter.
FadeInImage.assetNetwork(
placeholder: Assets.GENRE,
image: item.image, fit: BoxFit.cover,
)
Now, I want :
After got Image url from API,
I'm able to Scale that image and show on UI as Widget.
I found ImageInfo had attribute is scale
But I didn't get any example details how to apply this.
People who know,
Please give me an example,
Thank you,
You can use Image.Network as it's having scale and BoxFit both options. check out Image.Network here.
Example:
FadeInImage(
placeholder: Assets.GENRE,
image: Image.Network(url,scale:2.0,fit:BoxFit.cover,repeat:ImageRepeat.noRepeat),
)