Flutter Image not displaying - flutter

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

Related

Image won't load after updating to Flutter 3.3 (cached_network_image)

After I upgraded to Flutter 3.3. The image from CachedNetworkImage widget no longer load image.
The console doesn't print anything helpful about this behavior, like nothing was happen.
cached_network_image version: 3.2.2 (latest as of today)
Code snippet:
return CachedNetworkImage(
imageUrl: "https://mywaktusolat.vercel.app/assets/images/WPLABU-AnNur-8743ec6837fb6e154aad76252e754eb6.jpg",
fit: BoxFit.cover,
color: Colors.black.withOpacity(0.4),
colorBlendMode: BlendMode.overlay,
);

Flutter - How implement a file, image and camera picker for local storage

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

I want a image but nither assest image nor network image is loading on screen

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

How can I display image from get request on screen in flutter?

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

How to add images in vscode - Flutter

I am trying to add images to an asset folder in VSCode, but I only get the option to type the image name. When I do and click on the newly created image, it says "an error has occurred." I presume this is because I am only typing the file name, not adding the actual image.
I added the full path to the yml file, but nothing loads in the app.
assets:
- C:/Users/tt/Desktop/Flutter_projects/Practise/imaages/images/assets/android.png
Flutter code:
child: Image(
image: AssetImage('assets/android.png')
),
),
use relative path to indicate the folder(e.g.myImages) that hosts your image assets.
then
flutter:
assets:
- myImages/android.png
see flutter doc for more info:
Adding assets and images