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.

230 lines
7.6 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'package:dio/dio.dart';
4 years ago
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/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';
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';
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> {
ApiService? apiService;
SignInfo? signInfo;
4 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 {
// SmartDialog.showLoading(msg: 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
BaseListData<Rank>? rankData =
await apiService?.rankList().catchError((onError) {
SmartDialog.showToast(AppUtils.dioErrorTypeToString(onError.type),
alignment: Alignment.center);
refreshController.refreshFailed();
});
if (rankData?.isSuccess ?? false) {
4 years ago
ranks.clear();
ranks.addAll(rankData!.data ?? []);
3 years ago
refreshController.refreshCompleted();
} else {
3 years ago
refreshController.refreshFailed();
4 years ago
}
if (ranks.length > 0) {
rankLevel = (ranks.indexWhere(
(element) => element.id == userInfo?.memberRankVo?.id) +
1);
4 years ago
}
3 years ago
BaseData<SignInfo>? baseData =
await apiService?.signInInfo().catchError((onError) {});
if (baseData?.isSuccess ?? false) {
signInfo = baseData!.data;
3 years ago
refreshController.refreshCompleted();
4 years ago
}
SmartDialog.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,
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,
),
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?.length ?? 0) >
(signInfo?.signInList?.length ?? 0))
? (signInfo?.rewardList?[
signInfo?.signInList?.length ??
0] ??
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 {
if ((signInfo?.todayHasSignin ?? false)) {
4 years ago
SmartDialog.showToast("今日已签到了", alignment: Alignment.center);
4 years ago
return;
}
SmartDialog.showLoading(
msg: S.of(context).zhengzaijiazai,
);
BaseData? baseData = await apiService?.signIn().catchError((onError) {});
if (baseData?.isSuccess ?? false) {
3 years ago
setState(() {});
4 years ago
SmartDialog.show(
builder: (ctx) => SignInWidget(
"${(signInfo?.signInList?.length ?? 0) + 1}",
"${signInfo?.rewardList?[(signInfo?.signInList?.length ?? 0)]}"));
4 years ago
} else {
SmartDialog.dismiss();
4 years ago
}
}
4 years ago
}