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.
612 lines
19 KiB
612 lines
19 KiB
import 'dart:convert'; |
|
|
|
import 'package:dio/dio.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_swiper/flutter_swiper.dart'; |
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/rank.dart'; |
|
import 'package:huixiang/retrofit/data/sign_info.dart'; |
|
import 'package:huixiang/retrofit/data/task.dart'; |
|
import 'package:huixiang/retrofit/data/user_info.dart'; |
|
import 'package:huixiang/retrofit/retrofit_api.dart'; |
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
class IntegralPage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _IntegralPage(); |
|
} |
|
} |
|
|
|
class _IntegralPage extends State<IntegralPage> { |
|
ApiService apiService; |
|
SignInfo signInfo; |
|
|
|
UserInfo userinfo; |
|
List<Rank> ranks = []; |
|
int rankLevel = 1; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
|
|
SharedPreferences.getInstance().then((value) { |
|
apiService = |
|
ApiService(Dio(), context: context, token: value.getString("token")); |
|
userinfo = UserInfo.fromJson(jsonDecode(value.getString("user"))); |
|
querySignInfo(); |
|
}); |
|
} |
|
|
|
querySignInfo() async { |
|
BaseData baseData = await apiService.signInInfo(); |
|
|
|
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); |
|
} |
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
signInfo = SignInfo.fromJson(baseData.data); |
|
setState(() {}); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: AppBar( |
|
title: Text( |
|
S.of(context).jifenxiangqing, |
|
style: TextStyle(color: Colors.white), |
|
), |
|
centerTitle: false, |
|
backgroundColor: Color(0xFF3A405A), |
|
elevation: 0, |
|
actions: [ |
|
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: 18.sp, |
|
fontWeight: FontWeight.bold, |
|
), |
|
), |
|
), |
|
) |
|
], |
|
leading: GestureDetector( |
|
onTap: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
child: Container( |
|
alignment: Alignment.centerRight, |
|
margin: EdgeInsets.only(left: 10.w), |
|
padding: EdgeInsets.all(6), |
|
child: Icon( |
|
Icons.arrow_back_ios, |
|
color: Colors.white, |
|
size: 24, |
|
), |
|
), |
|
), |
|
titleSpacing: 2, |
|
leadingWidth: 56.w, |
|
), |
|
body: SingleChildScrollView( |
|
child: Container( |
|
child: Stack( |
|
children: [ |
|
Positioned( |
|
child: Container( |
|
height: 122.h, |
|
color: Color(0xFF3A405A), |
|
), |
|
top: 0, |
|
left: 0, |
|
right: 0, |
|
), |
|
Column( |
|
children: [ |
|
integralAndVip(), |
|
inForPoints(), |
|
integralTask(), |
|
], |
|
), |
|
], |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
Widget integralTask() { |
|
return Container( |
|
width: double.infinity, |
|
margin: EdgeInsets.all(16), |
|
padding: EdgeInsets.fromLTRB(10.w, 20.h, 10.w, 20.h), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
borderRadius: BorderRadius.all(Radius.circular(8)), |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Colors.black.withAlpha(12), |
|
offset: Offset(0, 3), |
|
blurRadius: 14, |
|
spreadRadius: 0, |
|
) |
|
]), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Container( |
|
margin: EdgeInsets.only(left: 10.w), |
|
child: Text( |
|
S.of(context).zuorenwudejifen, |
|
style: TextStyle( |
|
color: Color(0xFF353535), |
|
fontWeight: FontWeight.bold, |
|
fontSize: 16.sp, |
|
), |
|
), |
|
), |
|
Container( |
|
child: AspectRatio( |
|
aspectRatio: 1.6, |
|
child: Swiper( |
|
loop: false, |
|
physics: BouncingScrollPhysics(), |
|
pagination: SwiperPagination( |
|
alignment: Alignment.bottomCenter, |
|
builder: DotSwiperPaginationBuilder( |
|
size: 8, |
|
activeSize: 8, |
|
space: 5, |
|
activeColor: Colors.black, |
|
color: Colors.black.withAlpha(76), |
|
), |
|
), |
|
itemBuilder: (context, position) { |
|
return taskPage(position); |
|
}, |
|
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), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget taskPage(position) { |
|
if (signInfo == null || signInfo.taskList == null) return Container(); |
|
return Container( |
|
margin: EdgeInsets.only(left: 10.w, right: 10.w, top: 16.h), |
|
child: Column( |
|
children: [ |
|
tashItem(signInfo.taskList[position * 3 + 0]), |
|
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]), |
|
], |
|
), |
|
); |
|
} |
|
|
|
taskImg(String taskType) { |
|
switch (taskType) { |
|
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; |
|
} |
|
return "assets/image/icon_integral_share.png"; |
|
} |
|
|
|
Widget tashItem(Task task) { |
|
return Container( |
|
margin: EdgeInsets.only(top: 8.h, bottom: 8.h), |
|
alignment: Alignment.center, |
|
child: Row( |
|
children: [ |
|
Image.asset( |
|
taskImg(task.type), |
|
width: 24.w, |
|
height: 24.h, |
|
), |
|
SizedBox( |
|
width: 21.w, |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
task.name, |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
SizedBox( |
|
width: 7, |
|
), |
|
Row( |
|
children: [ |
|
Text( |
|
"+${double.tryParse(task.rewardValue).toInt()}", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF727272), |
|
), |
|
), |
|
SizedBox( |
|
width: 20.w, |
|
), |
|
Text( |
|
S.of(context).wancheng_( |
|
"${task.complateNum ?? task.conplateNum}/${task.limitDay}"), |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF727272), |
|
), |
|
), |
|
], |
|
) |
|
], |
|
), |
|
), |
|
RoundButton( |
|
text: task.limitDay == (task.complateNum ?? task.conplateNum) |
|
? S.of(context).yiwancheng |
|
: S.of(context).quwancheng, |
|
textColor: Colors.white, |
|
backgroup: task.limitDay == (task.complateNum ?? task.conplateNum) |
|
? Color(0xFFA0A0A0) |
|
: Color(0xFF32A060), |
|
radius: 12, |
|
fontSize: 14.sp, |
|
fontWeight: FontWeight.bold, |
|
padding: EdgeInsets.fromLTRB(12.w, 2.h, 12.w, 2.h), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
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: [ |
|
Expanded( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"0${position + 1}", |
|
style: TextStyle( |
|
color: Color(0xFF353535), |
|
fontSize: 14.sp, |
|
fontWeight: FontWeight.bold), |
|
), |
|
SizedBox( |
|
height: 10.h, |
|
), |
|
Container( |
|
alignment: Alignment.center, |
|
child: Text( |
|
S.of(context).shenmijifendali, |
|
style: TextStyle( |
|
color: Color(0xFF727272), |
|
fontSize: 12.sp, |
|
), |
|
), |
|
), |
|
], |
|
), |
|
flex: 1, |
|
), |
|
Container( |
|
alignment: Alignment.center, |
|
child: Image.asset( |
|
"assets/image/icon_gold_blessing.png", |
|
width: 59.w, |
|
height: 59.h, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} else { |
|
return Container( |
|
padding: EdgeInsets.all(4), |
|
decoration: BoxDecoration( |
|
color: (signInfo != null && |
|
signInfo.signInList != null && |
|
signInfo.signInList.length > position) |
|
? Color(0xFF32A060) |
|
: Color(0xFFF0F0F2), |
|
borderRadius: BorderRadius.all(Radius.circular(4)), |
|
), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Text( |
|
"0${position + 1}", |
|
style: TextStyle( |
|
color: (signInfo != null && |
|
signInfo.signInList != null && |
|
signInfo.signInList.length > position) |
|
? Colors.white |
|
: Color(0xFF353535), |
|
fontSize: 14.sp, |
|
fontWeight: FontWeight.bold), |
|
), |
|
Container( |
|
alignment: Alignment.center, |
|
child: Image.asset( |
|
"assets/image/icon_gold_coin.png", |
|
width: 30.w, |
|
height: 30.h, |
|
), |
|
), |
|
Container( |
|
alignment: Alignment.center, |
|
margin: EdgeInsets.only( |
|
top: 2.h, |
|
), |
|
child: Text( |
|
(signInfo != null && |
|
signInfo.rewardList != null && |
|
signInfo.rewardList.length > position) |
|
? "+${signInfo.rewardList[position]}" |
|
: "+10", |
|
style: TextStyle( |
|
color: (signInfo != null && |
|
signInfo.signInList != null && |
|
signInfo.signInList.length > position) |
|
? Colors.white |
|
: Color(0xFF727272), |
|
fontSize: 12.sp, |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
} |
|
|
|
///立即签到 |
|
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, |
|
children: [ |
|
Text( |
|
S.of(context).qiandaolingjifen, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 16.sp, |
|
color: Color(0xFF353535)), |
|
), |
|
Text( |
|
S.of(context).lianxuqiandaolingqushuangbeijifen, |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 11.sp, |
|
color: Color(0xFF727272), |
|
), |
|
), |
|
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( |
|
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, |
|
padding: EdgeInsets.fromLTRB(16.w, 6.h, 16.w, 6.h), |
|
radius: 4, |
|
), |
|
), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
///立即签到 |
|
signIn() async { |
|
if ((signInfo != null && signInfo.todayHasSignin)) { |
|
SmartDialog.showToast("今日已签到了"); |
|
return; |
|
} |
|
BaseData baseData = await apiService.signIn(); |
|
if (baseData != null && baseData.isSuccess) { |
|
querySignInfo(); |
|
SmartDialog.showToast("签到成功"); |
|
} |
|
} |
|
|
|
//上面的积分和VIP等级显示 |
|
Widget integralAndVip() { |
|
return Container( |
|
padding: EdgeInsets.only(top: 16.h, bottom: 16.h), |
|
color: Color(0xFF3A405A), |
|
child: Row( |
|
children: [ |
|
Expanded( |
|
flex: 1, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
signInfo != null ? "${signInfo.point}" : "0", |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 21.sp, |
|
color: Colors.white, |
|
), |
|
), |
|
SizedBox( |
|
height: 6.h, |
|
), |
|
Text( |
|
S.of(context).wodejifenzhi, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFFF2F2F2), |
|
), |
|
) |
|
], |
|
)), |
|
Container( |
|
width: 2.w, |
|
height: 32.h, |
|
color: Color(0xFFFFFFFF), |
|
), |
|
Expanded( |
|
flex: 1, |
|
child: InkWell( |
|
onTap: () { |
|
Navigator.of(context) |
|
.pushNamed('/router/mine_vip_level_page', arguments: { |
|
"rankLevel": rankLevel, |
|
"points": |
|
(userinfo != null) ? int.tryParse(userinfo.points) : 0, |
|
}); |
|
}, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
(signInfo != null && signInfo.rank != null) |
|
? "${signInfo.rank.rankName.replaceAll("会员", "")}" |
|
: "", |
|
style: TextStyle( |
|
fontWeight: FontWeight.bold, |
|
fontSize: 21.sp, |
|
color: Colors.white, |
|
), |
|
), |
|
SizedBox( |
|
height: 6.h, |
|
), |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
S.of(context).wodehuiyuandengji, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFFF2F2F2), |
|
), |
|
), |
|
Icon( |
|
Icons.keyboard_arrow_right, |
|
color: Colors.white, |
|
size: 15, |
|
), |
|
], |
|
), |
|
], |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|