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.

190 lines
5.9 KiB

3 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/retrofit/data/rank.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/login_tips_dialog.dart';
import 'package:shared_preferences/shared_preferences.dart';
class MineVipEntry extends StatelessWidget {
int vipLevel;
int curLevel;
final int rankMax;
final int rank;
final String createTime;
final String tag;
final double padding;
final UserInfo userInfo;
final List<Rank> ranks;
MineVipEntry(
{this.vipLevel = 1,
this.ranks,
this.tag,
this.userInfo,
this.padding = 16,
this.curLevel = 1,
this.rankMax = 0,
this.rank = 0,
this.createTime = ""});
String topLeft = "";
String levelText = "普通用户";
@override
Widget build(BuildContext context) {
if (userInfo != null &&
userInfo.memberRankVo != null &&
ranks != null &&
ranks.length > 0) {
curLevel = (ranks.indexWhere((element) => element.id == userInfo.memberRankVo.id) + 1);
vipLevel = curLevel;
}
if (curLevel == vipLevel) {
topLeft = S.of(context).dangqiandengji;
} else if (vipLevel < curLevel) {
topLeft = S.of(context).shangyidengji;
} else {
topLeft = S.of(context).zanweikaitong;
}
switch (vipLevel) {
case 1:
{
levelText = "${S.of(context).yinkahuiyuan}";
break;
}
case 2:
{
levelText = "${S.of(context).jinkahuiyuan}";
break;
}
case 3:
{
levelText = "${S.of(context).gongchuanghuiyuan}";
break;
}
}
Widget widget = Container(
width: double.infinity,
3 years ago
padding: EdgeInsets.only(top: 12.h, bottom: 22.h, left: 12.w, right: 12.w),
3 years ago
margin: EdgeInsets.only(top: 23.h,left: 13.5.w,right: 13.5.w,bottom:15.h),
3 years ago
decoration: BoxDecoration(
color: Color(0xFF3D3D5D),
3 years ago
borderRadius: BorderRadius.circular(6),
3 years ago
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Image.asset(
"assets/image/vip_logo.webp",
width: 24,
height: 24,
),
SizedBox(
3 years ago
width: 5.w,
3 years ago
),
Expanded(
child: Text(
levelText,
style: TextStyle(
3 years ago
fontSize: 16.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFFFFEAD2)),
)),
Container(
padding: EdgeInsets.fromLTRB(9.w, 4.h, 8.w, 4.h),
decoration: BoxDecoration(
color: Color(0xFFFFECD2),
borderRadius: BorderRadius.circular(10),
),
child: Text(
S.of(context).chakanquanyi,
style: TextStyle(
fontSize: 12.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF92755D),
),
),
)
],
),
SizedBox(
3 years ago
height: 16.h,
3 years ago
),
Container(
3 years ago
height: 4.h,
3 years ago
child: ClipRRect(
borderRadius: BorderRadius.circular(6.5),
child: LinearProgressIndicator(
value: rankMax > (rank ?? 0)
? ((vipLevel < curLevel)
? rankMax / rankMax
: (rank ?? 0) / rankMax)
: 0,
backgroundColor: Color(0xFF222233),
color: Color(0xFFFFECD2),
),
),
),
SizedBox(
3 years ago
height: 8.h,
3 years ago
),
Text(
rank > rankMax
? S.of(context).dangqiandengji
: "消费金额¥${rank.toStringAsFixed(2).toString()}${S.of(context).xiayidengji}还需¥${(rankMax - (rank ?? 0)).toStringAsFixed(2)}",
style: TextStyle(
color: Color(0xFFFFEAD2),
fontWeight: MyFontWeight.regular,
fontSize: 14.sp,
),
)
],
));
return GestureDetector(
onTap: () {
if (userInfo != null) {
SharedPreferences.getInstance().then((value) {
if (value.getString("token") == null ||
value.getString("token") == "") {
LoginTipsDialog().show(context);
return;
}
// Navigator.of(context)
// .pushNamed('/router/mine_vip_level_page', arguments: {
// "rankLevel": curLevel,
// "createTime": (userInfo != null) ? "${userInfo.createTime}" : "",
// "points": (userInfo != null) ? int.tryParse(userInfo.points) : 0,
// });
Navigator.of(context)
.pushNamed('/router/mine_vip_core', arguments: {
"rankLevel": curLevel,
"userInfo": userInfo.masterCardRankName,
"createTime": (userInfo != null) ? "${userInfo.createTime}" : "",
"expendAmount":
double.tryParse(userInfo?.expendAmount ?? "0").toInt(),
});
});
}
},
child: widget,
);
}
}