import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:easy_debounce/easy_throttle.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:get/get.dart'; import 'package:card_swiper/card_swiper.dart'; import '../../dio_cilent/kt_apis.dart'; import '../../dio_cilent/kt_request.dart'; import '../../kt_model/kt_receive_coin_info.dart'; import '../../kt_model/kt_short_video_bean.dart'; import '../../kt_utils/kt_toast_utils.dart'; import '../../kt_utils/kt_string_extend.dart'; import '../../kt_widgets/kt_network_image.dart'; import '../kt_mine/kt_store/logic.dart'; import '../kt_routes.dart'; import 'state.dart'; class KtRefillLogic extends GetxController { final state = KtRefillState(); final RefreshController refreshController = RefreshController(); @override void onReady() { super.onReady(); getReceiveDayCoin(); getRefillInfo(); } @override void onClose() { super.onClose(); refreshController.dispose(); } getReceiveDayCoin() async { ApiResponse res = await KtHttpClient().request( KtApis.getReceiveDayCoin, method: HttpMethod.get, ); if (res.success) { state.hasSubCoin = res.data['is_exist_sub'] == 1; update(); } } getRefillInfo() async { try { ApiResponse res = await KtHttpClient().request( KtApis.getReceiveDayCoinInfo, method: HttpMethod.get, ); if (res.success) { state.receiveCoinInfo = ReceiveCoinInfo.fromJson(res.data); update(); refreshController.refreshCompleted(); } } catch (e) { refreshController.refreshFailed(); } } refreshInfo() { getRefillInfo(); Get.put(KtStoreLogic()).getStoreInfo(); } receiveDayCoin({int? id}) async { Map params = {}; if (id != null) params['id'] = id; ApiResponse res = await KtHttpClient().request( KtApis.receiveDayCoin, data: params, ); if (res.success) { KtToastUtils.showToast('Success'); getRefillInfo(); getReceiveDayCoin(); getRecommend(); } } getRecommend() async { ApiResponse res = await KtHttpClient().request( KtApis.getDetailsRecommand, method: HttpMethod.get, ); if (res.success) { state.recommendList = [ ...res.data['list'].map((item) => KtShortVideoBean.fromJson(item)), ]; if (state.recommendList.isNotEmpty) { showRecommendDialog(); } update(); } } showRecommendDialog() { EasyThrottle.throttle('show-recommend', Duration(seconds: 3), () async { Get.bottomSheet( isScrollControlled: true, isDismissible: true, enableDrag: false, Stack( children: [ Positioned( bottom: 0, left: 0, child: Container( height: 503.w, width: ScreenUtil().screenWidth, padding: EdgeInsets.fromLTRB(0.w, 75.w, 0.w, 20.w), decoration: BoxDecoration( image: DecorationImage( image: AssetImage('video_recommend_bg.png'.ktIcon), fit: BoxFit.fill, ), ), child: Column( children: [ Row( children: [ SizedBox(width: 15.w), Image.asset('ip.png'.ktIcon, width: 38.w, height: 40.w), SizedBox(width: 6.w), Container( height: 30.w, padding: EdgeInsets.symmetric(horizontal: 14.w), decoration: BoxDecoration( color: Color(0xFF1E1E20), borderRadius: BorderRadius.circular(15.w), ), child: Center( child: Text( 'More Drama Gold Below!', style: TextStyle( color: Color(0xFFA7F62F), fontSize: 16.sp, fontWeight: FontWeight.w500, ), ), ), ), ], ), SizedBox( height: 290.w, child: Swiper( layout: SwiperLayout.CUSTOM, customLayoutOption: CustomLayoutOption(startIndex: -1, stateCount: 3) ..addRotate([-20.0 / 180, 0.0, 20.0 / 180]) ..addTranslate([ Offset(-220.w, 0), Offset(0, 0), Offset(220.w, 0), ]), itemWidth: 190.w, itemHeight: 226.w, itemBuilder: (context, index) { final item = state.recommendList[index % state.recommendList.length]; return GestureDetector( onTap: () { Get.back(); Get.toNamed( KtRoutes.shortVideo, arguments: { 'shortPlayId': state.recommendList[index].shortPlayId, 'imageUrl': state.recommendList[index].imageUrl ?? '', }, ); }, child: KtNetworkImage( imageUrl: item.imageUrl ?? '', width: 190.w, height: 226.w, borderRadius: BorderRadius.circular(20.w), ), ); }, itemCount: state.recommendList.length, loop: true, autoplay: true, onIndexChanged: (index) => state.recommendIndex = index, ), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ GestureDetector( onTap: () { Get.back(); Get.toNamed( KtRoutes.shortVideo, arguments: { 'shortPlayId': state .recommendList[state.recommendIndex] .shortPlayId, 'imageUrl': state .recommendList[state.recommendIndex] .imageUrl ?? '', }, ); }, child: Container( width: 280.w, height: 64.w, padding: EdgeInsets.only(bottom: 16.w), decoration: BoxDecoration( image: DecorationImage( image: AssetImage( 'video_recommend_btn.png'.ktIcon, ), fit: BoxFit.cover, ), ), child: Container( height: 48.w, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'video_recommend_play.png'.ktIcon, width: 18.w, height: 18.w, ), SizedBox(width: 4.w), Text( 'watch now', style: TextStyle( color: Colors.black, fontSize: 14.sp, fontWeight: FontWeight.w500, ), ), ], ), ), ), ), ], ), ], ), ), ), ], ), ); }); } }