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.

130 lines
3.8 KiB

3 years ago
3 years ago
import 'dart:convert';
3 years ago
import 'package:flutter/material.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:huixiang/data/banner.dart';
3 years ago
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class PointMallBanner extends StatefulWidget {
final List<BannerData> bannerData;
PointMallBanner(this.bannerData);
@override
State<StatefulWidget> createState() {
return _PointMallBanner();
}
}
class _PointMallBanner extends State<PointMallBanner> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 16.h),
child: AspectRatio(
aspectRatio: 2.0,
child: Swiper(
pagination: SwiperPagination(
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
size: 8,
activeSize: 8,
space: 5,
activeColor: Colors.black,
color: Colors.black.withAlpha(76),
),
),
viewportFraction: 0.7,
scale: 0.7,
physics: BouncingScrollPhysics(),
itemBuilder: (context, position) {
return InkWell(
onTap: () {
bannerClick(widget.bannerData[position]);
},
child: Container(
margin: EdgeInsets.only(bottom: 40.h),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
),
child: MImage(
position < widget.bannerData.length
? widget.bannerData[position].imgUrl ?? ""
3 years ago
: "",
radius: BorderRadius.circular(8),
fit: BoxFit.cover,
errorSrc: "assets/image/default_2_1.webp",
fadeSrc: "assets/image/default_2_1.webp",
3 years ago
),
),
);
},
itemCount: (widget.bannerData.isNotEmpty) ? widget.bannerData.length : 1,
3 years ago
),
),
);
}
/// contentType 跳转类型(0:不跳转,1:积分商品,2:活动,3:文章,4:页面跳转,5:课程,7:门店跳转)
3 years ago
bannerClick(BannerData bannerData) async {
switch (bannerData.contentType) {
case 1:
Navigator.of(context).pushNamed('/router/integral_store_page',
arguments: {"goodsId": bannerData.content});
break;
case 2:
Navigator.of(context)
3 years ago
.pushNamed('/router/web_page', arguments: {
3 years ago
"activityId": bannerData.content,
});
break;
case 3:
Navigator.of(context)
3 years ago
.pushNamed('/router/web_page', arguments: {
3 years ago
"articleId": bannerData.content,
});
break;
3 years ago
case 4:
String? router = bannerData.content;
if (router?.isEmpty ?? true) {
return;
}
if (router!.contains("?")) {
3 years ago
String params = router.substring(router.indexOf("?"));
params = params.replaceAll("?", "");
Map map = jsonDecode(params);
Navigator.of(context).pushNamed(router, arguments: map);
} else {
Navigator.of(context).pushNamed(router);
}
break;
3 years ago
case 5:
Navigator.of(context)
.pushNamed('/router/class_details', arguments: {
"id": bannerData.content,
});
break;
case 7:
String? router = bannerData.content;
if (router?.isEmpty ?? true) {
return;
}
String params = router!.substring(router.indexOf("?")+1);
Map map = jsonDecode(params);
Navigator.of(context).pushNamed(router.substring(0, router.indexOf("?")), arguments: map);
break;
3 years ago
}
}
}