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.

310 lines
11 KiB

4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:huixiang/data/base_list_data.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/data/rank.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/flutter_utils.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/mine_vip_view.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:huixiang/view_widget/my_appbar.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class MineVipLevelPage extends StatefulWidget {
4 years ago
final Map<String, dynamic> arguments;
MineVipLevelPage({required this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _MineVipLevelPage();
}
}
class _MineVipLevelPage extends State<MineVipLevelPage> {
ApiService? apiService;
4 years ago
List<Rank> ranks = [];
3 years ago
final SwiperController controller = SwiperController();
4 years ago
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) {
apiService = ApiService(Dio(), context: context, token: value.getString("token"));
4 years ago
queryVipLevel();
});
}
queryVipLevel() async {
BaseListData<Rank>? rankData = await apiService?.rankList().catchError((onError) {
return Future.value(null);
});
if (rankData?.isSuccess ?? false) {
4 years ago
ranks.clear();
ranks.addAll(rankData!.data ?? []);
4 years ago
setState(() {
controller.move((widget.arguments?["rankLevel"] - 1), animation: false);
4 years ago
});
} else {
SmartDialog.showToast("${rankData?.msg}", alignment: Alignment.center);
4 years ago
}
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
title: S.of(context).wodehuiyuandengji,
titleColor: Colors.black,
titleSize: 18.sp,
background: Color(0xFFFFFFFF),
leadingColor: Colors.black,
4 years ago
),
4 years ago
body: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
children: [
3 years ago
Container(
3 years ago
height: (MediaQuery.of(context).size.width) / 1.78 * AppUtils.textScale(context),
4 years ago
child: Swiper(
viewportFraction: 0.95,
loop: false,
4 years ago
physics: BouncingScrollPhysics(),
4 years ago
controller: controller,
itemBuilder: (context, position) {
3 years ago
return MineVipView(
vipLevel: !(ranks.isNotEmpty) ? widget.arguments["rankLevel"] : position + 1,
3 years ago
curLevel: widget.arguments["rankLevel"],
tag: (widget.arguments["rankLevel"] == (position + 1) || !(ranks.isNotEmpty)) ? "vip" : "",
3 years ago
padding: 6.w,
rank: !(ranks.isNotEmpty) ? 0 : widget.arguments["points"]??0,
rankMax: !(ranks.isNotEmpty) ? 0 : (position < (ranks.length - 1))
? (ranks[position + 1].rankOrigin ?? 0)
: (ranks[position].rankOrigin ?? 0),
3 years ago
createTime: widget.arguments["createTime"],
);
4 years ago
},
itemCount: (ranks.isNotEmpty) ? ranks.length : 1,
4 years ago
),
4 years ago
),
4 years ago
Container(
4 years ago
margin: EdgeInsets.fromLTRB(0, 16.h, 0, 0),
padding: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 16.h),
4 years ago
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
4 years ago
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
4 years ago
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).huiyuandengjishuoming,
style: TextStyle(
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
fontSize: 16.sp,
color: Colors.black,
),
4 years ago
),
SizedBox(
4 years ago
height: 12.h,
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
Container(
4 years ago
width: 6.w,
height: 6.h,
margin: EdgeInsets.fromLTRB(4.w, 7.h, 4.w, 7.h),
4 years ago
decoration: BoxDecoration(
4 years ago
borderRadius: BorderRadius.circular(3),
color: Color(0xFF32A060),
4 years ago
),
),
4 years ago
Expanded(
child: Text(
S.of(context).chenggongdengluzhuce,
style: TextStyle(
textBaseline: TextBaseline.alphabetic,
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.regular,
4 years ago
color: Color(0xFF353535),
),
4 years ago
),
4 years ago
flex: 1,
4 years ago
),
],
),
SizedBox(
4 years ago
height: 20.h,
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
4 years ago
S.of(context).huiyuandengji,
4 years ago
textAlign: TextAlign.center,
style: TextStyle(
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
fontSize: 14.sp,
4 years ago
color: Color(0xFF353535),
),
),
flex: 1,
),
Expanded(
child: Text(
4 years ago
S.of(context).jifen,
4 years ago
textAlign: TextAlign.center,
style: TextStyle(
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
fontSize: 14.sp,
4 years ago
color: Color(0xFF353535),
),
),
flex: 1,
),
],
),
SizedBox(
4 years ago
height: 8.h,
4 years ago
),
4 years ago
Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
children: ranks != null
? ranks.map((e) {
3 years ago
return levelItem(
e,
ranks[ranks.indexOf(e)].rankOrigin,
ranks.indexOf(e) == (ranks.length - 1)
? 0
: ranks[ranks.indexOf(e) + 1].rankOrigin);
}).toList()
4 years ago
: [],
4 years ago
),
SizedBox(
4 years ago
height: 32.h,
4 years ago
),
Text(
S.of(context).jifendejisuanshuoming,
style: TextStyle(
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
fontSize: 16.sp,
color: Colors.black,
),
4 years ago
),
SizedBox(
4 years ago
height: 12.h,
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
4 years ago
width: 6.w,
height: 6.h,
margin: EdgeInsets.fromLTRB(4.w, 7.h, 4.w, 7.h),
4 years ago
decoration: BoxDecoration(
4 years ago
borderRadius: BorderRadius.circular(3),
color: Color(0xFF32A060),
4 years ago
),
),
Text(
S.of(context).yonghuxiaofeijifen,
style: TextStyle(
4 years ago
textBaseline: TextBaseline.alphabetic,
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Color(0xFF353535),
),
4 years ago
),
],
),
SizedBox(
4 years ago
height: 12.h,
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
4 years ago
width: 6.w,
height: 6.h,
margin: EdgeInsets.fromLTRB(4.w, 7.h, 4.w, 7.h),
4 years ago
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
4 years ago
color: Color(0xFF32A060),
4 years ago
),
),
Expanded(
child: Text(
S.of(context).youhuiquanwufajileijifen,
style: TextStyle(
4 years ago
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.semi_bold,
4 years ago
color: Color(0xFF353535),
),
4 years ago
),
flex: 1,
),
],
),
],
),
),
4 years ago
],
),
4 years ago
),
);
}
4 years ago
4 years ago
Widget levelItem(Rank rank, rankOrigin, rankOriginMax) {
4 years ago
return Container(
margin: EdgeInsets.symmetric(vertical: 8.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
rank.rankName ?? "",
4 years ago
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.regular,
4 years ago
color: Color(0xFF353535),
),
),
flex: 1,
),
Expanded(
child: Text(
4 years ago
"$rankOrigin - ${rankOriginMax == 0 ? "无限" : rankOriginMax}",
4 years ago
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.sp,
3 years ago
fontWeight: MyFontWeight.regular,
4 years ago
color: Color(0xFF353535),
),
),
flex: 1,
),
],
),
);
}
4 years ago
}