import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:huixiang/data/achivement_detail_list.dart'; import 'package:huixiang/data/vip_benefit.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/data/base_data.dart'; import 'package:huixiang/data/social_info.dart'; import 'package:huixiang/data/user_info.dart'; import 'package:huixiang/data/vip_badges.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/flutter_utils.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/badge_attainment_dialog.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/custom_image.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_footer.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../../view_widget/no_data_view.dart'; class MineAttainmentPage extends StatefulWidget { final Map? arguments; MineAttainmentPage({this.arguments}); @override State createState() { return _MineAttainmentPage(); } } class _MineAttainmentPage extends State { ApiService? apiService; final RefreshController _refreshController = RefreshController(); UserInfo? userInfo; List vipBadgesList = []; List achievementDetail = []; int checkPosition = 0; SocialInfo? infoNumber; final RefreshController refreshController = RefreshController(); @override void dispose() { super.dispose(); _refreshController.dispose(); } @override void initState() { super.initState(); userInfo = widget.arguments?["userInfo"]; queryAttainmentBadges(); querySocialInfo(); } ///成就徽章分类 queryAttainmentBadges() async { BaseData>? baseData = await apiService?.findBadges({}).catchError((error) { _refreshController.refreshFailed(); }); if (baseData?.isSuccess ?? false) { vipBadgesList.clear(); vipBadgesList.addAll(baseData?.data ?? []); setState(() { _refreshController.refreshCompleted(); }); } else { _refreshController.refreshFailed(); } } ///成就分类弹窗详情 queryAchievementDetail(index) async { BaseData>? baseData = await apiService ?.getAchievementDetail(vipBadgesList[index].id ?? "") .catchError((onError) {}); if (baseData?.isSuccess ?? false) { setState(() { achievementDetail.clear(); achievementDetail.addAll(baseData?.data ?? []); showDeleteDialog(index); }); } EasyLoading.dismiss(); } ///个人社交信息(粉丝/关注数量/成就数量) querySocialInfo() async { SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( Dio(), context: context, token: value.getString("token"), showLoading: false, ); BaseData? baseData = await apiService?.socialInfo().catchError((onError) {}); if (baseData?.isSuccess ?? false) { setState(() { infoNumber = baseData?.data; refreshController.refreshCompleted(); }); } EasyLoading.dismiss(); } _onRefresh() { queryAttainmentBadges(); querySocialInfo(); } @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.fill, image: AssetImage("assets/image/attainment_bj.webp"), ), ), child: Scaffold( backgroundColor: Colors.transparent, appBar: MyAppBar( title: S.of(context).wodechengjiu, titleColor: Colors.black, titleSize: 18.sp, background: Colors.transparent, leadingColor: Colors.black, ), body: SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, header: MyHeader(), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), onRefresh: () { setState(() { _onRefresh(); }); }, physics: BouncingScrollPhysics(), child: Container( child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Column( children: [ SizedBox(height: 24.h), MImage( userInfo?.headimg ?? "", isCircle: true, width: 58.h, height: 58.h, fit: BoxFit.cover, errorSrc: "assets/image/default_user.webp", fadeSrc: "assets/image/default_user.webp", ), SizedBox(height: 8.h), Text( userInfo?.nickname ?? S.of(context).denglu, style: TextStyle( fontSize: 16.sp, fontWeight: FontWeight.bold, color: Color(0xFF353535), ), ), SizedBox(height: 28.h), Container( margin: EdgeInsets.only( left: 16.w, right: 16.w, top: 26.h, bottom: 8.h, ), padding: EdgeInsets.symmetric( vertical: 20.h, ), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withAlpha(12), offset: Offset(0, 3), blurRadius: 14, spreadRadius: 0, ) ], borderRadius: BorderRadius.all(Radius.circular(8)), ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: EdgeInsets.symmetric(horizontal: 20.w), child: Row( children: [ Text( S.of(context).chengjiuhuizhang, style: TextStyle( fontWeight: MyFontWeight.medium, fontSize: 14.sp, color: Color(0xFF353535), ), ), SizedBox(width: 4), Text( "(", style: TextStyle( fontWeight: MyFontWeight.medium, fontSize: 14, color: Color(0xFF353535), ), ), Text( "${infoNumber?.achievementNumber ?? 0}", style: TextStyle( fontWeight: MyFontWeight.medium, fontSize: 14, color: Color(0xFF32A060), ), ), Text( "/${vipBadgesList.length})", style: TextStyle( fontWeight: MyFontWeight.medium, fontSize: 14, color: Color(0xFF353535), ), ), ], ), ), SizedBox(height: 12.h), attainmentBadge(), ], ), ), ], ), ), ), ), ), ); } ///成就徽章列表 Widget attainmentBadge() { return (vipBadgesList.isNotEmpty) ? GridView.builder( itemCount: vipBadgesList.length ?? 0, shrinkWrap: true, physics: NeverScrollableScrollPhysics(), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( //一行的Widget数量 crossAxisCount: 3, // //水平子Widget之间间距 // crossAxisSpacing: 13, // //垂直子Widget之间间距 // mainAxisSpacing: 12, // //子Widget宽高比例 // childAspectRatio: AppUtils.textScale(context) > 1 // ? (1 - ((AppUtils.textScale(context) - 1))) // : 0.85, ), itemBuilder: (context, index) { return GestureDetector( onTap: () { setState(() { queryAchievementDetail(index); }); }, child: badgeItem(vipBadgesList[index]), ); }, ) : NoDataView( src: "assets/image/xiao_fei.webp", isShowBtn: false, text: "当前暂无成就徽章~", fontSize: 16.sp, margin: EdgeInsets.only(left: 60.w, right: 60.w), ); ; } Widget badgeItem(VipBadges vipBadgesList) { return Container( alignment: Alignment.center, child: Column( children: [ MImage( vipBadgesList.icon ?? "", width: 80.h, height: 80.h, fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox( height: 4.h, ), Text( vipBadgesList.name ?? "", overflow: TextOverflow.ellipsis, style: TextStyle( color: Color(0xFF181818), fontWeight: MyFontWeight.medium, fontSize: 12.sp, ), ), ], ), ); } ///徽章成就弹窗 showDeleteDialog(index) { showDialog( context: context, builder: (context) { return StatefulBuilder(builder: (context, state) { return AlertDialog( content: Container( width: MediaQuery.of(context).size.width - 84, height: 430.h, child: Column( children: [ GestureDetector( onTap: () { Navigator.of(context).pop(); }, child: Row( children: [ Spacer(), Image.asset( "assets/image/icon_order_cancel.webp", width: 24, height: 24, ), ], ), ), MImage( // this.vipBadgesList[index].icon, achievementDetail[checkPosition].icon ?? "", width: 150, height: 150, fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox(height: 10), Text( "${vipBadgesList.length > index ? vipBadgesList[index].name : ""}${achievementDetail.length > checkPosition ? achievementDetail[checkPosition].name : ""}徽章", style: TextStyle( fontSize: 16.sp, fontWeight: MyFontWeight.semi_bold, color: Color(0xFF181818), ), ), SizedBox( height: 6.h, ), Text( "再${vipBadgesList.length > index ? vipBadgesList[index].name : ""} ${AppUtils.calculateDouble(double.tryParse(achievementDetail.length > checkPosition ? "${achievementDetail[checkPosition].lessScore}" : "0") ?? 0)} 即可升级", style: TextStyle( fontSize: 12.sp, fontWeight: MyFontWeight.regular, color: Color(0xFFA3A3A3), ), ), SizedBox( height: 4.h, ), Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( "${S.of(context).jiangli}:", style: TextStyle( fontWeight: MyFontWeight.regular, fontSize: 12.sp, color: Color(0xFF515151), ), ), SizedBox(width: 8), Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: achievementDetail[checkPosition].rewardList != null ? achievementDetail[checkPosition] .rewardList!.map((e) { return Text( rewardStr(e), style: TextStyle( fontWeight: MyFontWeight.regular, fontSize: 12.sp, color: Color(0xFF515151), ), ); }).toList() : [], ), ], ), Expanded( child: Container( height: double.maxFinite, margin: EdgeInsets.only(top: 14), child: ListView.builder( shrinkWrap: true, scrollDirection: Axis.horizontal, physics: BouncingScrollPhysics(), itemCount: achievementDetail.length ?? 0, itemBuilder: (context, position) { return GestureDetector( onTap: () { state(() { checkPosition = position; }); }, child: badgeGradeItem(achievementDetail[position], position, achievementDetail.length), ); }, ), ), ), ], ), ), ); }); }, ); } String rewardStr(RewardList rewardList) { if (rewardList.rewardType == 1) return "积分:${rewardList.refId}"; else if (rewardList.rewardType == 2) return "平台余额:${rewardList.refId}"; else if (rewardList.rewardType == 3) return "平台兑换券:${rewardList.couponName}"; return ""; } ///徽章级别列表 Widget badgeGradeItem(AchivementDetailList achievementDetail, var position, var size) { return Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.start, children: [ Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ MImage( achievementDetail.icon ?? "", width: checkPosition == position ? 50 : 30, height: checkPosition == position ? 50 : 30, fit: BoxFit.cover, errorSrc: "assets/image/default_1.webp", fadeSrc: "assets/image/default_1.webp", ), SizedBox(height: 10), Text( achievementDetail.name ?? "", style: TextStyle( fontSize: 10.sp, fontWeight: MyFontWeight.regular, color: Color(0xFFA3A3A3), ), ), ], ), Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ if (position != size - 1) Container( width: 35.w, height: 2.h, // margin: EdgeInsets.only(top: 25), decoration: new BoxDecoration( color: Color(0xFFE1F2F7), ), ), SizedBox(height: 20), ], ), ], ); } ///成就徽章弹窗(暂无接口字段判断该功能实现) showAlertDialog() { //显示对话框 showDialog( context: context, builder: (BuildContext context) { return BadgeAttainmentDialog(); }, ); } }