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.

614 lines
19 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
4 years ago
import 'package:huixiang/generated/l10n.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';
import 'package:huixiang/retrofit/data/task.dart';
4 years ago
import 'package:huixiang/retrofit/data/user_info.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:huixiang/view_widget/round_button.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.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';
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;
4 years ago
UserInfo userinfo;
List<Rank> ranks = [];
int rankLevel = 1;
4 years ago
@override
void initState() {
super.initState();
4 years ago
SharedPreferences.getInstance().then((value) {
4 years ago
apiService = ApiService(Dio(),
context: context,
token: value.getString("token"),
showLoading: false);
4 years ago
userinfo = UserInfo.fromJson(jsonDecode(value.getString("user")));
4 years ago
SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai);
4 years ago
querySignInfo();
});
4 years ago
}
querySignInfo() async {
BaseData baseData = await apiService.signInInfo();
4 years ago
BaseData rankData = await apiService.rankList();
if (rankData != null && rankData.isSuccess) {
ranks.clear();
ranks.addAll((rankData.data as List<dynamic>)
.map((e) => Rank.fromJson(e))
.toList());
}
if (userinfo != null &&
userinfo.memberRankVo != null &&
ranks != null &&
ranks.length > 0) {
rankLevel = (ranks
.indexWhere((element) => element.id == userinfo.memberRankVo.id) +
1);
}
4 years ago
SmartDialog.dismiss();
4 years ago
if (baseData != null && baseData.isSuccess) {
4 years ago
signInfo = SignInfo.fromJson(baseData.data);
setState(() {});
}
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
background: Color(0xFF3A405A),
leadingColor: Colors.white,
title: S.of(context).jifenxiangqing,
titleColor: Colors.white,
titleSize: 16.sp,
action: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(right: 16.w),
child: GestureDetector(
onTap: () {
4 years ago
Navigator.of(context).pushNamed('/router/integral_detailed_page');
4 years ago
},
child: Text(
S.of(context).mingxi,
style: TextStyle(
color: Colors.white,
fontSize: 18.sp,
fontWeight: FontWeight.bold,
4 years ago
),
),
),
),
),
body: SingleChildScrollView(
child: Container(
child: Stack(
4 years ago
children: [
Positioned(
child: Container(
height: 122.h,
color: Color(0xFF3A405A),
),
top: 0,
left: 0,
right: 0,
),
Column(
children: [
integralAndVip(),
inForPoints(),
integralTask(),
],
),
4 years ago
],
),
),
),
);
}
Widget integralTask() {
return Container(
width: double.infinity,
margin: EdgeInsets.all(16),
4 years ago
padding: EdgeInsets.fromLTRB(10.w, 20.h, 10.w, 20.h),
4 years ago
decoration: BoxDecoration(
4 years ago
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
4 years ago
margin: EdgeInsets.only(left: 10.w),
4 years ago
child: Text(
S.of(context).zuorenwudejifen,
style: TextStyle(
4 years ago
color: Color(0xFF353535),
fontWeight: FontWeight.bold,
fontSize: 16.sp,
),
4 years ago
),
),
Container(
child: AspectRatio(
4 years ago
aspectRatio: 1.5,
4 years ago
child: Swiper(
4 years ago
loop: false,
physics: BouncingScrollPhysics(),
4 years ago
pagination: SwiperPagination(
4 years ago
alignment: Alignment.bottomCenter,
builder: DotSwiperPaginationBuilder(
size: 8,
activeSize: 8,
space: 5,
activeColor: Colors.black,
color: Colors.black.withAlpha(76),
),
),
4 years ago
itemBuilder: (context, position) {
4 years ago
return taskPage(position);
4 years ago
},
4 years ago
itemCount: (signInfo != null &&
signInfo.taskList != null &&
signInfo.taskList.length > 0)
? (signInfo.taskList.length < 3
? 1
: (signInfo.taskList.length ~/ 3 +
(signInfo.taskList.length % 3 > 0 ? 1 : 0)))
: 1),
4 years ago
),
),
],
),
);
}
4 years ago
Widget taskPage(position) {
if (signInfo == null || signInfo.taskList == null) return Container();
4 years ago
return Container(
4 years ago
margin: EdgeInsets.only(left: 10.w, right: 10.w, top: 16.h),
4 years ago
child: Column(
children: [
4 years ago
tashItem(signInfo.taskList[position * 3 + 0]),
4 years ago
if (signInfo.taskList.length > (position * 3 + 1))
tashItem(signInfo.taskList[position * 3 + 1]),
if (signInfo.taskList.length > (position * 3 + 2))
tashItem(signInfo.taskList[position * 3 + 2]),
4 years ago
],
),
);
}
4 years ago
taskImg(String taskType) {
switch (taskType) {
4 years ago
case "bill_type_point_login":
return "assets/image/icon_integral_share.png";
break;
case "bill_type_point_order":
return "assets/image/icon_integral_order.png";
break;
case "bill_type_point_signin":
return "assets/image/icon_integral_sign.png";
break;
}
4 years ago
return "assets/image/icon_integral_share.png";
4 years ago
}
Widget tashItem(Task task) {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
4 years ago
alignment: Alignment.center,
child: Row(
children: [
Image.asset(
4 years ago
taskImg(task.type),
4 years ago
width: 24.w,
height: 24.h,
4 years ago
),
SizedBox(
4 years ago
width: 21.w,
4 years ago
),
Expanded(
flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
4 years ago
task.name,
4 years ago
style: TextStyle(
fontSize: 14.sp,
4 years ago
fontWeight: FontWeight.w400,
4 years ago
color: Color(0xFF353535),
),
4 years ago
),
SizedBox(
4 years ago
height: 7.h,
4 years ago
),
Row(
children: [
Text(
4 years ago
"+${double.tryParse(task.rewardValue).toInt()}",
4 years ago
style: TextStyle(
fontSize: 12.sp,
color: Color(0xFF727272),
),
4 years ago
),
SizedBox(
4 years ago
width: 20.w,
4 years ago
),
Text(
S.of(context).wancheng_(
"${task.complateNum ?? task.conplateNum}/${task.limitDay}"),
4 years ago
style: TextStyle(
fontSize: 12.sp,
4 years ago
fontWeight: FontWeight.w400,
4 years ago
color: Color(0xFF727272),
),
4 years ago
),
],
)
],
),
),
RoundButton(
4 years ago
text: task.limitDay == (task.complateNum ?? task.conplateNum)
4 years ago
? S.of(context).yiwancheng
: S.of(context).quwancheng,
4 years ago
textColor: Colors.white,
backgroup: task.limitDay == (task.complateNum ?? task.conplateNum)
4 years ago
? Color(0xFFA0A0A0)
: Color(0xFF32A060),
4 years ago
radius: 12,
4 years ago
fontSize: 14.sp,
4 years ago
fontWeight: FontWeight.bold,
4 years ago
padding: EdgeInsets.fromLTRB(12.w, 4.h, 12.w, 4.h),
4 years ago
)
],
),
);
}
Widget signInItem(position) {
if (position == 6) {
return Container(
padding: EdgeInsets.all(6),
decoration: BoxDecoration(
color: Color(0xFFF0F0F2),
borderRadius: BorderRadius.all(Radius.circular(4)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
4 years ago
Expanded(
4 years ago
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"0${position + 1}",
4 years ago
style: TextStyle(
4 years ago
color: Color(0xFF353535),
4 years ago
fontSize: 14.sp,
4 years ago
fontWeight: FontWeight.w500),
4 years ago
),
SizedBox(
4 years ago
height: 10.h,
4 years ago
),
Container(
alignment: Alignment.center,
child: Text(
S.of(context).shenmijifendali,
style: TextStyle(
color: Color(0xFF727272),
4 years ago
fontWeight: FontWeight.bold,
fontSize: 10.sp,
4 years ago
),
4 years ago
),
),
4 years ago
],
),
flex: 1,
4 years ago
),
Container(
alignment: Alignment.center,
child: Image.asset(
"assets/image/icon_gold_blessing.png",
4 years ago
width: 59.w,
height: 59.h,
4 years ago
),
),
],
),
);
} else {
return Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
4 years ago
color: (signInfo != null &&
signInfo.signInList != null &&
signInfo.signInList.length > position)
? Color(0xFF32A060)
: Color(0xFFF0F0F2),
4 years ago
borderRadius: BorderRadius.circular(4),
4 years ago
),
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"0${position + 1}",
style: TextStyle(
4 years ago
color: (signInfo != null &&
signInfo.signInList != null &&
signInfo.signInList.length > position)
? Colors.white
: Color(0xFF353535),
fontSize: 14.sp,
4 years ago
fontWeight: FontWeight.w500,
4 years ago
),
4 years ago
),
Container(
alignment: Alignment.center,
child: Image.asset(
"assets/image/icon_gold_coin.png",
4 years ago
width: 30.w,
height: 30.h,
4 years ago
),
),
Container(
alignment: Alignment.center,
4 years ago
margin: EdgeInsets.only(
4 years ago
top: 2.h,
4 years ago
),
4 years ago
child: Text(
4 years ago
(signInfo != null &&
signInfo.rewardList != null &&
signInfo.rewardList.length > position)
? "+${signInfo.rewardList[position]}"
: "+10",
4 years ago
style: TextStyle(
4 years ago
color: (signInfo != null &&
signInfo.signInList != null &&
signInfo.signInList.length > position)
? Colors.white
: Color(0xFF727272),
4 years ago
fontSize: 12.sp,
4 years ago
),
),
),
],
),
);
}
}
4 years ago
///立即签到
4 years ago
Widget inForPoints() {
return Container(
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 6.h),
padding: EdgeInsets.fromLTRB(20.w, 20.h, 20.w, 20.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
Text(
S.of(context).qiandaolingjifen,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16.sp,
color: Color(0xFF353535)),
4 years ago
),
4 years ago
SizedBox(
height: 10.h,
),
Text(
S.of(context).lianxuqiandaolingqushuangbeijifen,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 11.sp,
color: Color(0xFF727272),
4 years ago
),
),
SizedBox(
height: 32.h,
),
StaggeredGridView.countBuilder(
crossAxisCount: 4,
shrinkWrap: true,
itemCount: 7,
mainAxisSpacing: 8.h,
crossAxisSpacing: 18.w,
padding: EdgeInsets.only(bottom: 32.h),
physics: new NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return signInItem(position);
},
staggeredTileBuilder: (position) {
return StaggeredTile.count(position == 6 ? 2 : 1, 1.28);
}),
InkWell(
onTap: signIn,
child: Container(
alignment: Alignment.center,
child: RoundButton(
4 years ago
width: 106,
height: 34,
text: (signInfo != null && signInfo.todayHasSignin)
? S.of(context).yiqiandao
: S.of(context).lijiqiandao,
textColor: Colors.white,
backgroup: (signInfo != null && signInfo.todayHasSignin)
? Colors.grey
: Color(0xFF32A060),
fontSize: 16.sp,
4 years ago
fontWeight: FontWeight.w400,
padding: EdgeInsets.fromLTRB(16.w, 6.h, 16.w, 6.h),
radius: 4,
),
4 years ago
),
)
],
),
);
}
4 years ago
///立即签到
signIn() async {
4 years ago
if ((signInfo != null && signInfo.todayHasSignin)) {
4 years ago
SmartDialog.showToast("今日已签到了", alignment: Alignment.center);
4 years ago
return;
}
4 years ago
SmartDialog.showLoading(msg: S.of(context).zhengzaijiazai);
4 years ago
BaseData baseData = await apiService.signIn();
4 years ago
if (baseData != null && baseData.isSuccess) {
querySignInfo();
4 years ago
SmartDialog.show(
widget: SignInWidget("${signInfo.signInList.length + 1}",
"${signInfo.rewardList[signInfo.signInList.length]}"));
4 years ago
}
}
//上面的积分和VIP等级显示
4 years ago
Widget integralAndVip() {
return Container(
4 years ago
padding: EdgeInsets.only(top: 16.h, bottom: 16.h),
color: Color(0xFF3A405A),
4 years ago
child: Row(
children: [
Expanded(
flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
4 years ago
signInfo != null ? "${signInfo.point}" : "0",
4 years ago
style: TextStyle(
4 years ago
fontWeight: FontWeight.w500,
4 years ago
fontSize: 21.sp,
color: Colors.white,
),
4 years ago
),
SizedBox(
4 years ago
height: 6.h,
4 years ago
),
Text(
S.of(context).wodejifenzhi,
4 years ago
style: TextStyle(
fontSize: 12.sp,
4 years ago
fontWeight: FontWeight.w400,
4 years ago
color: Color(0xFFF2F2F2),
),
4 years ago
)
],
)),
Container(
4 years ago
width: 2.w,
height: 32.h,
4 years ago
color: Color(0xFFFFFFFF),
),
Expanded(
4 years ago
flex: 1,
child: InkWell(
onTap: () {
Navigator.of(context)
.pushNamed('/router/mine_vip_level_page', arguments: {
"rankLevel": rankLevel,
4 years ago
"createTime":
(userinfo != null) ? "${userinfo.createTime}" : "",
4 years ago
"points":
(userinfo != null) ? int.tryParse(userinfo.points) : 0,
});
},
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
4 years ago
(signInfo != null && signInfo.rank != null)
? "${signInfo.rank.rankName.replaceAll("会员", "")}"
: "",
4 years ago
style: TextStyle(
4 years ago
fontWeight: FontWeight.w500,
4 years ago
fontSize: 21.sp,
color: Colors.white,
),
4 years ago
),
SizedBox(
4 years ago
height: 6.h,
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
S.of(context).wodehuiyuandengji,
4 years ago
style: TextStyle(
fontSize: 12.sp,
4 years ago
fontWeight: FontWeight.w400,
4 years ago
color: Color(0xFFF2F2F2),
),
4 years ago
),
Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
size: 15,
4 years ago
),
4 years ago
],
4 years ago
),
4 years ago
],
4 years ago
),
),
),
4 years ago
],
),
);
}
}