How to add assets images in carousel_slider?

211 Views Asked by At

i am tring to add images in carousel flutter and i make a list of images from my assets but i am facing this error.

ArgumentError (Invalid argument(s): No host specified in URI file:///home/zr/untitled%20folder/snap/flutter/PROJECTS/nic/nic/assets/images/ataltunel.jpg)

note: (i dont't want to load images from network) please give some ideas to solve it.

this is the code....!!!!!

body: Container(
            child: Column(
              children: [
                CarouselSlider(
                  options: CarouselOptions(
                      height: 170.0, autoPlay: true, enlargeCenterPage: true),
                  items: _slideimages.map((i) {
                    return Builder(
                      builder: (BuildContext context) {
                        return Container(
                          width: MediaQuery.of(context).size.width,
                          child: Image.network(i),
                        );
                      },
                    );
                  }).toList(),
                ),
              ],
            ),
          ),
3

There are 3 best solutions below

0
Kothai On BEST ANSWER

If you dont't want to load images from network, then try loading the images from local assets, for which create a folder /assests and include that in your pubspec.yml file and run pub get command and once done add those images in _slideimages list and use it. use Image.assert(i)

0
Mohammed Rabeeh On

if you using images from asset then use Image.asset("path"); or you using image file then you can use Image.file("file path");

1
Md. Yeasin Sheikh On

You need to use Image.asset to load from assets.

child: Image.network(i), /// make sure to provide current path.

Make sure to add on pubspec.yaml file. Find more about assets-and-images .