|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
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(
|
|
|
|
aspectRatio: 1.25,
|
|
|
|
child: Swiper(
|
|
|
|
pagination: SwiperPagination(
|
|
|
|
margin: EdgeInsets.only(bottom: 12.h),
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
builder: DotSwiperPaginationBuilder(
|
|
|
|
size: 8,
|
|
|
|
activeSize: 8,
|
|
|
|
space: 5,
|
|
|
|
activeColor: Colors.white,
|
|
|
|
color: Colors.white.withAlpha(76),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
autoplay: true,
|
|
|
|
duration: 1000,
|
|
|
|
autoplayDelay: 2000,
|
|
|
|
controller: widget.controller,
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
bannerClick(widget.bannerData[position]);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
// margin: EdgeInsets.all(16),
|
|
|
|
// decoration: BoxDecoration(
|
|
|
|
// borderRadius: BorderRadius.circular(8),
|
|
|
|
// ),
|
|
|
|
child: MImage(
|
|
|
|
(widget.bannerData != null &&
|
|
|
|
position < widget.bannerData.length)
|
|
|
|
? widget.bannerData[position].imgUrl ?? ""
|
|
|
|
: "",
|
|
|
|
// radius: BorderRadius.circular(8),
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
errorSrc: "assets/image/default_2_1.webp",
|
|
|
|
fadeSrc: "assets/image/default_2_1.webp",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: (widget.bannerData != null && widget.bannerData.length > 0)
|
|
|
|
? widget.bannerData.length
|
|
|
|
: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// contentType 跳转类型(0:不跳转,1:积分商品,2:活动,3:文章,4:页面跳转,5:课程,7:门店跳转)
|
|
|
|
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).pushNamed('/router/web_page', arguments: {
|
|
|
|
"activityId": bannerData.content,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Navigator.of(context).pushNamed('/router/web_page', arguments: {
|
|
|
|
"articleId": bannerData.content,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
String router = bannerData.content;
|
|
|
|
// String router = "/router/store_order?{\"id\":\"1512378184161558528\",\"tenant\":\"1188\",\"storeName\":\"农场煮意\"}";
|
|
|
|
if (router.contains("?")) {
|
|
|
|
String params = router.substring(router.indexOf("?") + 1);
|
|
|
|
Map map = jsonDecode(params);
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
router.substring(0, router.indexOf("?")),
|
|
|
|
arguments: map);
|
|
|
|
} else {
|
|
|
|
Navigator.of(context).pushNamed(router);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
Navigator.of(context).pushNamed('/router/class_details', arguments: {
|
|
|
|
"id": bannerData.content,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
String params = bannerData.content.substring(bannerData.content.indexOf("?")+1);
|
|
|
|
Map map = jsonDecode(params);
|
|
|
|
Navigator.of(context).pushNamed(bannerData.content.substring(0,bannerData.content.indexOf("?")), arguments: map);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|