You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.4 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
3 years ago
import 'package:huixiang/integral/intergra_view/in_for_points.dart';
import 'package:huixiang/integral/intergra_view/integral_vip.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
4 years ago
import 'package:huixiang/retrofit/data/rank.dart';
4 years ago
import 'package:huixiang/retrofit/data/sign_info.dart';
4 years ago
import 'package:huixiang/retrofit/data/user_info.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/sign_in_widget.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'intergra_view/integral_task.dart';
4 years ago
class IntegralPage extends StatefulWidget {
3 years ago
4 years ago
@override
State<StatefulWidget> createState() {
return _IntegralPage();
}
}
class _IntegralPage extends State<IntegralPage> {
4 years ago
ApiService apiService;
SignInfo signInfo;
3 years ago
UserInfo userInfo;
4 years ago
List<Rank> ranks = [];
int rankLevel = 1;
4 years ago
querySignInfo() async {
3 years ago
EasyLoading.show(status: S.of(context).zhengzaijiazai);
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
showLoading: false,
);
userInfo = UserInfo.fromJson(jsonDecode(value.getString("user")));
4 years ago
3 years ago
BaseData<List<Rank>> rankData = await apiService.rankList()
.catchError((onError) {});
4 years ago
if (rankData != null && rankData.isSuccess) {
ranks.clear();
3 years ago
ranks.addAll(rankData.data);
4 years ago
}
3 years ago
if (userInfo != null &&
userInfo.memberRankVo != null &&
4 years ago
ranks != null &&
ranks.length > 0) {
rankLevel = (ranks
3 years ago
.indexWhere((element) => element.id == userInfo.memberRankVo.id) +
4 years ago
1);
}
3 years ago
BaseData<SignInfo> baseData =
await apiService.signInInfo().catchError((onError) {});
4 years ago
if (baseData != null && baseData.isSuccess) {
3 years ago
signInfo = baseData.data;
4 years ago
}
3 years ago
EasyLoading.dismiss();
4 years ago
}
4 years ago
@override
Widget build(BuildContext context) {
3 years ago
return Stack(
children: [
Positioned(
child: Container(
height: 122.h + kToolbarHeight + MediaQuery.of(context).padding.top,
decoration: BoxDecoration(
gradient: RadialGradient(
center: Alignment.center,
colors: [Color(0xFF36426E), Color(0xFF2D3247)],
focal: Alignment.center,
radius: 1,
4 years ago
),
),
),
3 years ago
top: 0,
left: 0,
right: 0,
4 years ago
),
3 years ago
Scaffold(
backgroundColor: Colors.transparent,
appBar: MyAppBar(
3 years ago
exit: (){Navigator.of(context).pop(signInfo.todayHasSignin ?? false);},
3 years ago
background: Colors.transparent,
leadingColor: Colors.white,
title: "",
titleColor: Colors.white,
titleSize: 16.sp,
brightness: Brightness.dark,
action: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(right: 16.w),
child: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/integral_detailed_page');
},
child: Text(
S.of(context).mingxi,
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
3 years ago
fontWeight: MyFontWeight.bold,
3 years ago
),
),
4 years ago
),
4 years ago
),
3 years ago
),
body: Container(
child: SingleChildScrollView(
3 years ago
physics: BouncingScrollPhysics(),
child: FutureBuilder(
future: querySignInfo(),
builder: (context, snap) {
return Column(
children: [
/// 上面的积分和VIP等级显示
IntegralVip(rankLevel, signInfo, userInfo,"${ (signInfo?.signInList?.length ) ?? "0"}",
((signInfo?.rewardList != null && signInfo.rewardList.length > (signInfo?.signInList?.length ?? 0)) ?
signInfo.rewardList[signInfo?.signInList?.length ?? 0]:0).toString()),
4 years ago
3 years ago
///立即签到
InForPoints(signInfo, _signIn),
4 years ago
3 years ago
///积分任务
IntegralTask(signInfo),
],
);
},
4 years ago
),
),
3 years ago
),
4 years ago
),
3 years ago
],
4 years ago
);
}
4 years ago
///立即签到
3 years ago
_signIn() async {
4 years ago
if ((signInfo != null && signInfo.todayHasSignin)) {
4 years ago
SmartDialog.showToast("今日已签到了", alignment: Alignment.center);
4 years ago
return;
}
3 years ago
EasyLoading.show(status: S.of(context).zhengzaijiazai);
3 years ago
BaseData baseData = await apiService.signIn().catchError((onError) {});
4 years ago
if (baseData != null && baseData.isSuccess) {
3 years ago
setState(() {});
4 years ago
SmartDialog.show(
widget: SignInWidget("${signInfo.signInList.length + 1}",
"${signInfo.rewardList[signInfo.signInList.length]}"));
3 years ago
} else {
3 years ago
EasyLoading.dismiss();
4 years ago
}
}
4 years ago
}