幻灯片flutter_swiper
jj
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
class swiper extends StatefulWidget {
String title;
//图片路径 List<String> banners = <String>[ 'assets/images/banners/1.jpeg', 'assets/images/banners/2.jpeg', 'assets/images/banners/3.jpeg', 'assets/images/banners/4.jpeg', ];
swiper({Key key, this.title}) : super(key: key);
@override
_swiperState createState() => _swiperState();
}
class _swiperState extends State<swiper> {
@override
Widget build(BuildContext context) {
double imgwidth = MediaQuery.of(context).size.width;
double imgheight = imgwidth / 4.0 * 3.0;
return new Scaffold(
body: Container(
width: 500,
height: 200,
child: Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.network(
"https://via.placeholder.com/350x150",
fit: BoxFit.fill,
);
},
itemCount: 3,
pagination: new SwiperPagination(),
control: new SwiperControl(),
itemWidth: 300.0,
itemHeight: 100.0,
layout: SwiperLayout.TINDER,
),
),
);
}
}
#builder 2
itemBuilder: (BuildContext context, index){ return Container( //图片左右内边距 margin: EdgeInsets.only(left: 5, right: 5), child: Image.asset( banners[index], width: width, height: height, fit: BoxFit.cover, ), ); },