Omkar Waghe
Omkar Waghe

Reputation: 178

How to add flutter image from local folder stored in assets

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

Upvotes: 0

Views: 1559

Answers (2)

Sanjay Sharma
Sanjay Sharma

Reputation: 4035

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

Upvotes: 1

Bogdan Lukin
Bogdan Lukin

Reputation: 1

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.

Upvotes: 0

Related Questions