美文网首页
8.flutter_swiper的简单使用

8.flutter_swiper的简单使用

作者: 李响2022 | 来源:发表于2020-03-07 01:25 被阅读0次
    import 'package:flutter/material.dart';
    import 'package:flutter_swiper/flutter_swiper.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(title:'flutter_swiper'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
    
      List imgList = [
        "https://desk-fd.zol-img.com.cn/t_s1024x768c5/g5/M00/02/00/ChMkJlbKw1eIdabyAASvPG-H6SwAALG1gFD3VQABK9U648.jpg",
        "https://desk-fd.zol-img.com.cn/t_s1024x768c5/g5/M00/02/00/ChMkJ1bKw1eILNybAAMnVXZZfj0AALG1gFIjKgAAydt911.jpg",
        "https://desk-fd.zol-img.com.cn/t_s1024x768c5/g5/M00/02/00/ChMkJlbKw1eIe_ACAAS4xbkUZBoAALG1gFLtBUABLjd443.jpg",
      ];
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
        body: Swiper(
            itemBuilder: (BuildContext context,int index){
              return Image.network(
                imgList[index],
                fit: BoxFit.fitWidth);
            },
            itemCount: imgList.length,
            pagination: SwiperPagination(),
            control: SwiperControl(),
          ),
        );
      }
    }
    

    效果图:


    Simulator Screen Shot - iPhone 11 Pro Max - 2020-03-07 at 01.24.24.png

    相关文章

      网友评论

          本文标题:8.flutter_swiper的简单使用

          本文链接:https://www.haomeiwen.com/subject/aybtdhtx.html