Search code examples
flutterimageassetsimage-slider

How to add assets images in carousel_slider?


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

Solution

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