Flutter 輪播圖2
阿新 • • 發佈:2021-01-11
技術標籤:Flutter
上一篇部落格我們做一個全屏的輪播效果,這次我們做一個比較大眾的~
老規矩,看效果圖
(一)效果圖
(二)看程式碼
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("文字")], ), ], ) ); } }