|
|
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
|
|
|
|
import 'package:huixiang/data/banner.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/utils/shared_preference.dart';
|
|
|
|
import 'package:huixiang/view_widget/custom_image.dart';
|
|
|
|
import 'package:huixiang/view_widget/login_tips_dialog.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
|
|
|
|
class CourseBanner extends StatefulWidget {
|
|
|
|
|
|
|
|
final List<BannerData> bannerData;
|
|
|
|
|
|
|
|
CourseBanner(this.bannerData);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _CourseBanner();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CourseBanner extends State<CourseBanner> {
|
|
|
|
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
List<BannerData> bannerData = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 2.08,
|
|
|
|
child: Swiper(
|
|
|
|
viewportFraction: 0.88,
|
|
|
|
scale: 0.93,
|
|
|
|
autoplay: true,
|
|
|
|
duration: 1000,
|
|
|
|
autoplayDelay: 2000,
|
|
|
|
pagination: SwiperPagination(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
builder: DotSwiperPaginationBuilder(
|
|
|
|
size: 8,
|
|
|
|
activeSize: 8,
|
|
|
|
space: 5,
|
|
|
|
activeColor: Colors.black,
|
|
|
|
color: Colors.black.withAlpha(76),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
bannerClick(widget.bannerData[position]);
|
|
|
|
},
|
|
|
|
child: MImage(
|
|
|
|
(position < widget.bannerData.length)
|
|
|
|
? "${widget.bannerData[position].imgUrl}"
|
|
|
|
: "",
|
|
|
|
fit: BoxFit.fill,
|
|
|
|
radius: BorderRadius.circular(8),
|
|
|
|
errorSrc: "assets/image/default_2_1.webp",
|
|
|
|
fadeSrc: "assets/image/default_2_1.webp",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
itemCount: (widget.bannerData.isNotEmpty)
|
|
|
|
? widget.bannerData.length
|
|
|
|
: 1),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// contentType 跳转类型(0:不跳转,1:积分商品,2:活动,3:文章,4:页面跳转,5:课程,7门店跳转)
|
|
|
|
bannerClick(BannerData bannerData) async {
|
|
|
|
if (SharedInstance.instance.token.isEmpty) {
|
|
|
|
LoginTipsDialog.instance.show(context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (router?.isEmpty ?? true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (router!.contains("?")) {
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|