Umaiz Khan
Umaiz Khan

Reputation: 1227

Flutter Swipper show multiple asset images

I am new in flutter. Using swipper in my first app. I have already search but not found i am using swipper to show images with sweip but its showing only one image which is swipping i need to add more images from asset how can i do this Any cone please tell ? thanks

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body:  new Swiper(
         itemBuilder: (BuildContext context, int index) {

           return new Image.asset(
            "assets/images/hotel_2.png",
            fit: BoxFit.fill,
           );

        },
        itemCount: 2,
        itemWidth: 300.0,
        itemHeight: 300.0,
        layout: SwiperLayout.STACK,
      )
    );
  }
}

Upvotes: 0

Views: 1355

Answers (2)

Fayyaz kharl
Fayyaz kharl

Reputation: 51

you have to set images name like this final List imgList = [ 'assets/img/dummy.jpg', 'assets/img/1.jpg', 'assets/img/2.jpg', 'assets/img/3.jpg', 'assets/img/4.jpg', ];

also import images in pubpack.yaml file

Upvotes: 0

Riz-waan
Riz-waan

Reputation: 643

Alright, I found the answer. Coincidentally, I was looking for the same thing.

Source from Github User: ghozay19

final List imgList = [
'img/dummy.jpg',
'img/1.jpg',
'img/2.jpg',
'img/3.jpg',
'img/4.jpg',
];

child: new Swiper(                            
    itemBuilder:
        (BuildContext context, int index) {                         
            return new Image.asset(
                  imgList[index],
                  fit: BoxFit.fill,
            );
        },
    itemCount: 4,
    viewportFraction: 0.7,
    scale: 0.8,
),

Upvotes: 1

Related Questions