import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/constant.dart'; import 'package:huixiang/data/base_data.dart'; import 'package:huixiang/data/base_list_data.dart'; import 'package:huixiang/data/rank.dart'; import 'package:huixiang/data/sign_info.dart'; import 'package:huixiang/data/user_info.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/integral/intergra_view/in_for_points.dart'; import 'package:huixiang/integral/intergra_view/integral_vip.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/utils/shared_preference.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:huixiang/view_widget/my_footer.dart'; import 'package:huixiang/view_widget/sign_in_widget.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../utils/flutter_utils.dart'; import 'intergra_view/integral_task.dart'; class IntegralPage extends StatefulWidget { @override State createState() { return _IntegralPage(); } } class _IntegralPage extends State { ApiService? apiService; SignInfo? signInfo; UserInfo? userInfo; List ranks = []; int rankLevel = 1; final ScrollController scrollController = ScrollController(); final RefreshController refreshController = RefreshController(); querySignInfo() async { apiService = ApiService( Dio(), context: context, token: SharedInstance.instance.token, showLoading: false, ); userInfo = UserInfo.fromJson(jsonDecode(SharedInstance.instance.userJson)); BaseListData? rankData = await apiService?.rankList().catchError((onError) { refreshController.refreshFailed(); return BaseListData()..isSuccess = false; }); if (rankData?.isSuccess ?? false) { ranks.clear(); ranks.addAll(rankData!.data ?? []); refreshController.refreshCompleted(); } else { refreshController.refreshFailed(); } if (ranks.length > 0) { rankLevel = (ranks.indexWhere((element) => element.id == userInfo?.memberRankVo?.id) + 1); } BaseData? baseData = await apiService?.signInInfo().catchError((onError) { return BaseData()..isSuccess = false; }); if (baseData?.isSuccess ?? false) { signInfo = baseData!.data; refreshController.refreshCompleted(); } SmartDialog.dismiss(); } @override Widget build(BuildContext context) { return Container( color: Colors.white, child: Stack( children: [ Container( decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.fill, image: AssetImage("assets/image/jifen.webp"), ), ), width: double.infinity, height: 215.h, ), Scaffold( backgroundColor: Colors.transparent, appBar: MyAppBar( exit: () { Navigator.of(context).pop(signInfo?.todayHasSignin ?? false); }, background: Colors.transparent, leadingColor: Colors.white, title: "", titleColor: Colors.white, titleSize: 16.sp, systemUiOverlayStyle: SystemUiOverlayStyle.dark, action: Container( alignment: Alignment.center, margin: EdgeInsets.only(right: 16.w), child: GestureDetector( onTap: () { Navigator.of(context).pushNamed( '/router/integral_detailed_page', arguments: {"titleType": 2}, ); }, child: Text( S.of(context).mingxi, style: TextStyle( color: Colors.white, fontSize: 16.sp, fontWeight: MyFontWeight.bold, ), ), ), ), ), body: SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, header: MyHeader( color: Colors.white, ), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), onRefresh: () { setState(() { querySignInfo(); }); }, physics: BouncingScrollPhysics(), scrollController: scrollController, child: Container( child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: FutureBuilder( future: querySignInfo(), builder: (context, snap) { return Column( children: [ /// 上面的积分和VIP等级显示 IntegralVip( rankLevel, signInfo, userInfo, "${(signInfo?.signInList?.length) ?? "0"}", (((signInfo?.rewardList?.length ?? 0) > (signInfo?.signInList?.length ?? 0)) ? (signInfo?.rewardList?[ signInfo?.signInList?.length ?? 0] ?? 0) : 0) .toString(), ), ///立即签到 InForPoints(signInfo, _signIn), ///积分任务 IntegralTask(signInfo), ], ); }, ), ), ), ), ), ], ), ); } ///立即签到 _signIn() async { if ((signInfo?.todayHasSignin ?? false)) { SmartDialog.showToast("今日已签到了", alignment: Alignment.center); return; } S.current.zhengzaijiazai.loading; BaseData? baseData = await apiService?.signIn().catchError((onError) { return BaseData()..isSuccess = false; }); if (baseData?.isSuccess ?? false) { setState(() {}); SmartDialog.show( builder: (ctx) => SignInWidget( "${(signInfo?.signInList?.length ?? 0) + 1}", "${signInfo?.rewardList?[(signInfo?.signInList?.length ?? 0)]}", ), ); } else { SmartDialog.dismiss(); } } }