// import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_campus/config/app_colors.dart';
import 'package:flutter_campus/utils/pagination.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
class HomePage extends StatefulWidget {
HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State
with AutomaticKeepAliveClientMixin {
List
'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2295011466,4114040936&fm=26&gp=0.jpg',
'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2295011466,4114040936&fm=26&gp=0.jpg',
'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2295011466,4114040936&fm=26&gp=0.jpg',
'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2295011466,4114040936&fm=26&gp=0.jpg'
];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
// leading: Builder(
// builder: (context) => IconButton(
// icon: Icon(Icons.menu),
// onPressed: () => Scaffold.of(context).openDrawer(),
// ),
// ),
// title: Text('首页'),
// centerTitle: true,
// actions:
// IconButton(
// icon: Icon(Icons.search),
// tooltip: "搜索",
// onPressed: () {
// print("搜索");
// },
// ),
// PopupMenuButton
// itemBuilder: (BuildContext context) =>
// PopupMenuItem
// child: Text('发起群聊'),
// value: 'chat',
// ),
// PopupMenuItem
// child: Text('添加朋友'),
// value: 'add',
// ),
// PopupMenuItem
// child: Text('扫一扫'),
// value: 'scan',
// ),
// PopupMenuItem
// child: Text('收付款'),
// value: 'pay',
// ),
// ],
// onSelected: (String action) {
// switch (action) {
// case "chat":
// print("发起群聊");
// break;
// case "add":
// print("添加朋友");
// break;
// case "scan":
// print("扫一扫");
// break;
// case "pay":
// print("收付款");
// break;
// }
// },
// ),
// ],
// ),
// drawer: Drawer(
// child: Container(
// alignment: Alignment.center,
// child: Text(
// '我是Drawer',
// style: TextStyle(fontSize: 30),
// ),
// ),
// elevation: 1000.0,
// ),
// drawerScrimColor: Color.fromARGB(80, 0, 0, 0),
resizeToAvoidBottomInset: false,
body: Container(
child: ListView(
// addAutomaticKeepAlives: true,
children: [
Container(
height: 180.0,
margin: EdgeInsets.all(12.0),
child: Swiper(
// itemHeight: 180,
// itemWidth: 240,
itemBuilder: (BuildContext context, int index) {
return Card(
// margin: EdgeInsets.all(12.0),
child: Image.network(imgs[index], fit: BoxFit.fill),
);
},
itemCount: imgs.length,
// pagination:
// new SwiperPagination(builder: SwiperPagination.dots),
autoplay: true,
// control: new SwiperControl(),
pagination: SwiperPagination(
//指示器显示的位置 Alignment.bottomCenter 底部中间
alignment: Alignment.bottomCenter,
// 距离调整
margin: const EdgeInsets.only(bottom: 10),
// 指示器构建
// builder: DotSwiperPaginationBuilder(
// // 点之间的间隔
// space: 2,
// // 没选中时的大小
// size: 6,
// // 选中时的大小
// activeSize: 12,
// // 没选中时的颜色
// color: Colors.black54,
// //选中时的颜色
// activeColor: Colors.white,
// ),
// builder: RectSwiperPaginationBuilder(
// color: AppColors.unactive,
// activeColor: AppColors.active_one,
// size: const Size(10.0, 2.0),
// activeSize: const Size(10.0, 2.0),
// ),
builder: SwiperCustomPagination(builder:
(BuildContext context, SwiperPluginConfig config) {
return RectIndicator(
position: config.activeIndex,
count: imgs.length,
color: AppColors.active_one,
activeColor:
AppColors.unactive_one, //未选中 指示器颜色,选中的颜色key为Color
width: 8.0, //指示器宽度
activeWidth: 14.0, //选中的指示器宽度
radius: 4, //指示器圆角角度
height: 2.0,
); //指示器高度
}),
)),
),
],
),
),
);
}
@override
// ignore: todo
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}
https://www.csdn.net/tags/Ntjagg0sMjY1MzUtYmxvZwO0O0OO0O0O.html
class RectIndicator extends StatelessWidget {
final int position;
final int count;
final Color color;
final Color activeColor;
final double width;
final double activeWidth;
final double height;
final double radius;
RectIndicator({
Key key,
this.width: 50.0,
this.activeWidth: 50.0,
this.height: 4,
@required this.position,
@required this.count,
this.color: Colors.white,
this.radius,
this.activeColor: const Color(0xFF3E4750),
}) : assert(count != null && position != null),
super(key: key);
_indicator(bool isActive) {
return AnimatedContainer(
margin: EdgeInsets.symmetric(horizontal: 3.0), //指示器间距
height: height,
width: isActive ? activeWidth : width,
decoration: BoxDecoration(
color: isActive ? color : activeColor,
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset(0.0, 2.0),
blurRadius: 0.0)
],
borderRadius: BorderRadius.circular(radius ?? height / 2.0)),
duration: Duration(milliseconds: 150),
);
}
_buildPageIndicators() {
List
indicatorList = []; for (int i = 0; i < count; i++) {
indicatorList.add(i == position ? _indicator(true) : _indicator(false));
}
return indicatorList;
}
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: _buildPageIndicators(),
);
}
}
https://xbzweb.com/2019/10/28/flutter%E5%A5%BD%E7%94%A8%E7%9A%84%E8%BD%AE%E5%AD%90%E6%8E%A8%E8%8D%90%E4%B8%89-%E8%B6%85%E5%BC%BA%E8%BD%AE%E6%92%AD%E5%9B%BESwiper/#%E5%89%8D%E8%A8%80