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.

515 lines
16 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:fluttertoast/fluttertoast.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/user_info.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/loading_view.dart';
4 years ago
import 'package:huixiang/view_widget/mine_vip_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dio/dio.dart';
class MinePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MinePage();
}
}
4 years ago
class _MinePage extends State<MinePage> with AutomaticKeepAliveClientMixin {
4 years ago
ApiService apiService;
_toUserInfo() async {
await Navigator.of(context).pushNamed('/router/user_info_page');
4 years ago
queryUserInfo();
4 years ago
}
@override
void initState() {
super.initState();
4 years ago
SharedPreferences.getInstance().then(
(value) => {
apiService = ApiService(Dio(), token: value.getString('token')),
4 years ago
userinfo = UserInfo.fromJson(jsonDecode(value.getString('user'))),
4 years ago
queryUserInfo()
},
);
4 years ago
}
4 years ago
UserInfo userinfo;
4 years ago
4 years ago
queryUserInfo() async {
4 years ago
var ranks = [
"青铜会员",
"白银会员",
"黄金会员",
"钻石会员",
"至尊会员",
];
4 years ago
showCupertinoDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return LoadingView();
});
4 years ago
BaseData baseDate = await apiService.queryInfo();
4 years ago
if(Navigator.canPop(context))
Navigator.of(context).pop();
4 years ago
if (baseDate.isSuccess) {
4 years ago
userinfo = UserInfo.fromJson(baseDate.data);
4 years ago
SharedPreferences.getInstance().then(
(value) => {
value.setString('user', jsonEncode(baseDate.data)),
},
);
vipLevel = ranks.indexOf(userinfo.memberRankVo.rankName) + 1;
} else {
Fluttertoast.showToast(msg: baseDate.msg);
4 years ago
}
4 years ago
setState(() {});
}
4 years ago
int vipLevel = 1;
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFFF7F7F7),
body: Container(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Container(
margin: EdgeInsets.only(top: 40),
child: Stack(
alignment: Alignment.centerRight,
children: [
Column(
children: [
InkWell(
onTap: _toUserInfo,
child: mineView(),
),
GestureDetector(
onTap: () {
Navigator.of(context)
.pushNamed('/router/mine_vip_level_page');
},
4 years ago
child: MineVipView(
4 years ago
vipLevel,
curLevel: vipLevel,
4 years ago
rank: (userinfo != null)
? int.tryParse(userinfo.points)
: 0,
rankMax:
(userinfo != null && userinfo.memberRankVo != null)
? userinfo.memberRankVo.rankOrigin
: 0,
createTime:
(userinfo != null) ? userinfo.createTime : "",
4 years ago
),
4 years ago
),
orderOrCard(),
4 years ago
mineList(context),
4 years ago
],
),
buildNotice(),
],
),
),
),
),
);
}
4 years ago
///横向的提示
4 years ago
Widget buildNotice() {
return Container(
margin: EdgeInsets.only(top: 130),
child: Stack(
children: [
Container(
height: 33,
margin: EdgeInsets.only(left: 12),
padding: EdgeInsets.only(left: 16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0)
],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(2),
bottomLeft: Radius.circular(2),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
S.of(context).ninyouyigedingdanyaolingqu,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12,
color: Colors.black),
),
Icon(
Icons.keyboard_arrow_right,
color: Colors.black,
size: 16,
)
],
),
),
Container(
margin: EdgeInsets.only(top: 5, bottom: 4),
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0)
],
shape: BoxShape.circle,
// borderRadius: BorderRadius.all(Radius.circular(2)),
),
child: Image.asset(
"assets/image/icon_mine_motorcycle.png",
width: 20,
height: 20,
fit: BoxFit.contain,
),
),
],
),
);
}
4 years ago
///我的下面的条目列表
4 years ago
Widget mineList(BuildContext context) {
4 years ago
return Container(
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(20, 12, 20, 12),
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(
children: [
InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/mine_wallet');
},
child: mineItem(
S.of(context).wodeqianbao,
"assets/image/icon_mine_wallet.png",
),
),
InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/exchange_history_page');
},
child: mineItem(
S.of(context).duihuanlishi,
"assets/image/icon_mine_records_of_consumption.png",
),
),
InkWell(
onTap: () {
4 years ago
Navigator.of(context).pushNamed('/router/roll_center_page');
},
4 years ago
child: mineItem(
S.of(context).linjuanzhongxin,
"assets/image/icon_mine_invoice_assistant.png",
),
4 years ago
),
InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/manage_address_page');
},
child: mineItem(
S.of(context).guanlidizhi,
"assets/image/icon_location_address.png",
),
4 years ago
),
InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/setting_page');
4 years ago
},
child: mineItem(
S.of(context).shezhi,
"assets/image/icon_mine_setting.png",
),
),
// mineItem(
// S.of(context).bangzhuyufankui,
// "assets/image/icon_mine_feedback.png",
// ),
4 years ago
],
),
);
}
4 years ago
///我的页面下面条目
4 years ago
Widget mineItem(text, icon) {
return Container(
margin: EdgeInsets.only(top: 8, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
icon,
width: 28,
height: 28,
),
SizedBox(
width: 12,
),
Expanded(
flex: 1,
child: Text(
text,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Color(0xFF353535)),
)),
Icon(
Icons.keyboard_arrow_right,
size: 20,
color: Colors.black,
)
],
),
);
}
4 years ago
///订单或者卡包试图
4 years ago
Widget orderOrCard() {
return Container(
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(20, 12, 20, 12),
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: Row(
children: [
Expanded(
flex: 1,
child: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/mine_card');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/icon_mine_card.png",
4 years ago
width: 32,
height: 32,
4 years ago
),
SizedBox(
width: 12,
),
Text(
S.of(context).kabao,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Color(0xFF353535)),
)
],
),
),
),
Container(
width: 2,
height: 32,
margin: EdgeInsets.only(left: 20, right: 20),
color: Color(0xFFABABAB),
),
Expanded(
flex: 1,
child: GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/order_history_page');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/icon_mine_order.png",
4 years ago
width: 32,
height: 32,
4 years ago
),
SizedBox(
width: 12,
),
Text(
S.of(context).dingdan,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Color(0xFF353535)),
)
],
),
),
),
],
),
);
}
4 years ago
///我的信息部分
4 years ago
Widget mineView() {
return Container(
margin: EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
4 years ago
MImage(
userinfo == null ? "" : userinfo.headimg,
radius: BorderRadius.all(Radius.circular(4)),
4 years ago
width: 84,
height: 84,
fit: BoxFit.cover,
4 years ago
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
4 years ago
),
SizedBox(
width: 16,
),
Expanded(
flex: 1,
child: Container(
height: 84,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
child: Text(
userinfo == null ? "" : "${userinfo.nickname}",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Color(0xFF353535)),
),
flex: 1,
),
InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/ui_test');
},
child: Image.asset(
"assets/image/icon_scan_qr_code.png",
width: 24,
height: 24,
),
),
],
),
SizedBox(
height: 16,
),
Text(
4 years ago
userinfo == null ? "NO.0" : "NO.${userinfo.vipNo}",
4 years ago
style: TextStyle(fontSize: 12, color: Color(0xFF2F2F2F)),
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/icon_an_crown.png",
width: 13,
height: 13,
),
SizedBox(
width: 8,
),
Text(
4 years ago
userinfo == null || userinfo.memberRankVo == null
? ""
: "${userinfo.memberRankVo.rankName}",
4 years ago
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Color(0xFF353535)),
),
Expanded(
child: GestureDetector(
onTap: () {
Navigator.of(context)
.pushNamed('/router/integral_page');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
S.of(context).jifenxiangqing,
style: TextStyle(
color: Colors.black,
fontSize: 12,
fontWeight: FontWeight.bold),
),
Icon(
Icons.keyboard_arrow_right,
size: 16,
color: Colors.black,
)
],
),
),
),
],
)
],
),
),
),
],
),
);
}
4 years ago
@override
bool get wantKeepAlive => true;
4 years ago
}