轮播图 flutter_swiper

导入package

flutter_swiper: ^1.1.6

实现:

import 'package:flutter_swiper/flutter_swiper.dart';

class _MyHomePageState extends State {
  List _imageUrls = [
      'http://pages.ctrip.com/commerce/promote/20180718/yxzy/img/640sygd.jpg',
      'http://pages.ctrip.com/commerce/promote/20180718/yxzy/img/640sygd.jpg',
       'http://pages.ctrip.com/commerce/promote/20180718/yxzy/img/640sygd.jpg',
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body:  Column(

          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              height: 160,
              child: Swiper(
                itemCount: _imageUrls.length,
                autoplay: true,
                itemBuilder: (BuildContext contex,int index){
                  return Image.network(
                  _imageUrls[index],
                  fit: BoxFit.fill);
                },
                pagination: SwiperPagination(),
        ),
      ),
      ],
    )
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

你可能感兴趣的:(Flutter,轮播图)