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.

226 lines
7.7 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';
3 years ago
import 'package:huixiang/view_widget/classic_header.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
3 years ago
import 'package:huixiang/view_widget/my_footer.dart';
4 years ago
import 'package:huixiang/view_widget/sign_in_widget.dart';
3 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../utils/flutter_utils.dart';
3 years ago
import 'intergra_view/integral_task.dart';
4 years ago
class IntegralPage extends StatefulWidget {
@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;
3 years ago
final ScrollController scrollController = ScrollController();
final RefreshController refreshController = RefreshController();
4 years ago
4 years ago
querySignInfo() async {
3 years ago
// EasyLoading.show(status: S.of(context).zhengzaijiazai);
3 years ago
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
BaseData<List<Rank>> rankData =
await apiService.rankList().catchError((onError) {
SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type),
alignment: Alignment.center);
refreshController.refreshFailed();
});
4 years ago
if (rankData != null && rankData.isSuccess) {
ranks.clear();
3 years ago
ranks.addAll(rankData.data);
3 years ago
refreshController.refreshCompleted();
} else {
3 years ago
refreshController.refreshFailed();
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;
3 years ago
refreshController.refreshCompleted();
4 years ago
}
3 years ago
EasyLoading.dismiss();
4 years ago
}
4 years ago
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Stack(
children: [
// Positioned(
// child: Container(
// height: 122.h + kToolbarHeight + MediaQuery.of(context).padding.top,
// decoration: BoxDecoration(
// image: DecorationImage(
// fit: BoxFit.fill,
// image: AssetImage("assets/image/jifen.webp"),
// ),
// ),
// ),
// top: 0,
// left: 0,
// right: 0,
// ),
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage("assets/image/jifen.webp"),
),
4 years ago
),
width: double.infinity,
height: 215.h,
4 years ago
),
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,
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',
arguments: {"titleType": 2});
},
child: Text(
S.of(context).mingxi,
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontWeight: MyFontWeight.bold,
),
3 years ago
),
),
4 years ago
),
4 years ago
),
body: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(color: Colors.white,),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: () {
setState(() {
querySignInfo();
});
3 years ago
},
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 != null &&
signInfo.rewardList.length >
(signInfo?.signInList?.length ??
0))
? signInfo.rewardList[
signInfo?.signInList?.length ?? 0]
: 0)
.toString()),
4 years ago
///立即签到
InForPoints(signInfo, _signIn),
4 years ago
///积分任务
IntegralTask(signInfo),
],
);
},
),
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;
}
EasyLoading.show(
status: S.of(context).zhengzaijiazai,
maskType: EasyLoadingMaskType.black);
3 years ago
BaseData baseData = await apiService.signIn().catchError((onError) {});
4 years ago
if (baseData != null && baseData.isSuccess) {
3 years ago
setState(() {});
3 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
}