0

I have Stored local images in assets/images file added the pubspcs.yml also
assets: - Assets/images/ but i am fetching values from another dummy.dart file like this

return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(title: Text(categoryTitle)),
        body: ListView.builder(
          itemBuilder: (ctx, index) {
            return MealItem(
              id: displayedMeals[index].id,
              title: displayedMeals[index].title,
              **imageUrl: displayedMeals[index].imageUrl,**
              duration: displayedMeals[index].duration,
              affordability: displayedMeals[index].affordability,
              complexity: displayedMeals[index].complexity,
           // removeItem: _removeMeal,
            );
                /* Text(categoryMeals[index].title) */;
          },
          itemCount: displayedMeals.length,
        )
 );

and I want the image to come with this index file which i am fetching from dummy.dart

 imageUrl:
        'https://www.whiskaffair.com/wp-content/uploads/2018/02/Hyderabadi-Mutton-Biryani-6.jpg',

instead of this i want from the image from assets/images folder

8
  • 1
    Your question is not clear. Do you want a placeholder for the image which is fetched from a URL? Commented May 17, 2020 at 10:03
  • @SanjaySharma I have stored local images in assets/images folder and I am fetching some values with the imageURL from dummy.dart file in the listview..if I give http://...someonlineimage...image is showing...but I want to add image from local folder Commented May 17, 2020 at 10:08
  • Can you share the code of MealItem Commented May 17, 2020 at 10:08
  • class MealItem extends StatelessWidget { final String imageUrl; MealItem({ @required this.imageUrl, }); Commented May 17, 2020 at 10:18
  • Are you serious? This is not the complete code of MealItem :) Commented May 17, 2020 at 10:21

2 Answers 2

1

You can use an asset image as default image.

 child: new Container(
      child: FadeInImage.assetNetwork(
          placeholder: 'place_holder.jpg',
          image:url
      )
  )

Put this in pubspec.yaml

  assets:
  - assets/place_holder.jpg
Sign up to request clarification or add additional context in comments.

2 Comments

Hi sanjay can you give more info if I want to add multiple images from assets/images folder and render it in to assetNetwork... I have more than 100 images
Add - assets/img/ and put all the images inside img folder
0

Images are resolved using ImageProvider.

There is a bunch of concrete implementations for different sources of images: FileImage, AssetImage, NetworkImage, MemoryImage, etc. Also there is associated factory constructors on Image class.

Probably you have something similar in MealItem:

Image.network(imageUrl)

You could either use ImageProvider:

Image(image: imageProvider)

Or directly provide Image widget in constructor.

Anyway you should know the source of the image to use appropriate ImageProvider implementation or Image constructor.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.