Flutter Carousel Figure 2

In the previous blog, we made a full-screen carousel effect, this time we made a more popular one~

Old rules, look at the renderings
(1) renderings
Insert picture description here
(2) look at the code

import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class SwiperPage extends StatefulWidget {
  @override
  _SwiperPageState createState() => _SwiperPageState();
}

class _SwiperPageState extends State<SwiperPage> {
  List<Map> imgList = [
    {"url": "images/moon.jpg"},
    {"url": "images/moon3.jpg"},
    {"url": "images/moon2.jpg"}
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("轮播图"),
        ),
        body: Column(
          children: [
            Container(//外层加container设置宽高
              height: 180,
              child: 
                Swiper(
                  itemBuilder: (BuildContext context, int index) {
                    return new Image.asset(
                      imgList[index]["url"],
                      fit: BoxFit.fill,
                    );
                  },
                  autoplay: true,
                  itemCount: imgList.length,
                  pagination: new SwiperPagination(),
                  control:  new SwiperControl(),
                ),
            ),
            Row(
              children: [Text("文本")],
            ),
          ],
        )
        );
  }
}

Guess you like

Origin blog.csdn.net/weixin_45425105/article/details/112003581