You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.6 KiB

3 years ago
import 'dart:convert';
3 years ago
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:huixiang/retrofit/data/banner.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class HomeBanner extends StatefulWidget {
final List<BannerData> bannerData;
final SwiperController controller;
HomeBanner(this.bannerData, this.controller);
@override
State<StatefulWidget> createState() {
return _HomeBanner();
}
}
class _HomeBanner extends State<HomeBanner> {
@override
Widget build(BuildContext context) {
return Container(
child: AspectRatio(
3 years ago
aspectRatio: 1.4,
3 years ago
child: Swiper(
pagination: SwiperPagination(
margin: EdgeInsets.only(bottom: 12.h),
3 years ago
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
size: 8,
activeSize: 8,
space: 5,
activeColor: Colors.white,
color: Colors.white.withAlpha(76),
),
),
controller: widget.controller,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return InkWell(
onTap: () {
bannerClick(widget.bannerData[position]);
},
child: Container(
3 years ago
// margin: EdgeInsets.all(16),
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(8),
// ),
3 years ago
child: MImage(
3 years ago
(widget.bannerData != null &&
position < widget.bannerData.length)
3 years ago
? widget.bannerData[position].imgUrl ?? ""
: "",
3 years ago
// radius: BorderRadius.circular(8),
3 years ago
fit: BoxFit.cover,
errorSrc: "assets/image/default_2_1.webp",
fadeSrc: "assets/image/default_2_1.webp",
3 years ago
),
),
);
},
itemCount: (widget.bannerData != null && widget.bannerData.length > 0)
? widget.bannerData.length
: 1,
),
),
);
}
3 years ago
/// contentType 跳转类型(0:不跳转,1:积分商品,2:活动,3:文章,4:页面跳转,5:课程)
3 years ago
bannerClick(BannerData bannerData) async {
switch (bannerData.contentType) {
case 1:
3 years ago
Navigator.of(context).pushNamed('/router/integral_store_page',
arguments: {"goodsId": bannerData.content});
3 years ago
break;
case 2:
3 years ago
Navigator.of(context)
.pushNamed('/router/web_page', arguments: {
"activityId": bannerData.content,
});
3 years ago
break;
case 3:
3 years ago
Navigator.of(context)
.pushNamed('/router/web_page', arguments: {
"articleId": bannerData.content,
});
3 years ago
break;
3 years ago
case 4:
String router = bannerData.content;
3 years ago
// String router = "/router/store_order?{\"id\":\"1512378184161558528\",\"tenant\":\"1188\",\"storeName\":\"农场煮意\"}";
3 years ago
if (router.contains("?")) {
3 years ago
String params = router.substring(router.indexOf("?")+1);
3 years ago
Map map = jsonDecode(params);
3 years ago
Navigator.of(context).pushNamed(router.substring(0,router.indexOf("?")), arguments: map);
3 years ago
} else {
Navigator.of(context).pushNamed(router);
}
break;
3 years ago
case 5:
Navigator.of(context)
.pushNamed('/router/class_details', arguments: {
"id": bannerData.content,
});
break;
3 years ago
}
}
}