美文网首页Flutter1
Flutter(Widget)-轮播图

Flutter(Widget)-轮播图

作者: aofeilin | 来源:发表于2022-06-20 10:10 被阅读0次
    截屏2022-06-28 21.16.34.png
    flutter_swiper: ^1.1.6
    
    import 'package:flutter/material.dart';
    import 'package:flutter_swiper/flutter_swiper.dart';
    
    class ZFLSwiperPage extends StatefulWidget {
      @override
      _ZFLSwiperPageState createState() => _ZFLSwiperPageState();
    }
    
    class _ZFLSwiperPageState extends State<ZFLSwiperPage> {
      List list = [
        {"url": "https://www.itying.com/images/flutter/1.png"},
        {"url": "https://www.itying.com/images/flutter/2.png"},
        {"url": "https://www.itying.com/images/flutter/3.png"},
        {"url": "https://www.itying.com/images/flutter/4.png"}
      ];
    
      @override
      Widget build(BuildContext context) {
        return Container(
          width: double.infinity,
          child: Column(
            children: [
              AspectRatio(
                aspectRatio: 16 / 9,
                child: Swiper(
                  itemBuilder: (BuildContext context, int index) {
                    return Image.network(
                      list[index]["url"],
                      fit: BoxFit.fill,
                    );
                  },
                  itemCount: list.length,
                  autoplay: true,
                  pagination: SwiperPagination(),
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 10),
                alignment: Alignment.topLeft,
                child: Text("张三"),
              )
            ],
          ),
        );
      }
    }
    
    1655690737403702.gif

    相关文章

      网友评论

        本文标题:Flutter(Widget)-轮播图

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