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.

568 lines
18 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/main.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/user_info.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
4 years ago
import 'package:huixiang/utils/event_type.dart';
import 'package:huixiang/view_widget/classic_header.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';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
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) => {
4 years ago
apiService = ApiService(Dio(),
context: context, token: value.getString('token')),
4 years ago
if (value.containsKey('user'))
{
userinfo = UserInfo.fromJson(jsonDecode(value.getString('user'))),
},
4 years ago
queryUserInfo()
},
);
4 years ago
eventBus.on<EventType>().listen((event) {
setState(() {});
});
4 years ago
}
4 years ago
UserInfo userinfo;
4 years ago
int rankLevel = 1;
4 years ago
List<Rank> ranks = [];
4 years ago
4 years ago
queryUserInfo() async {
4 years ago
showCupertinoDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return LoadingView();
});
4 years ago
BaseData baseDate = await apiService.queryInfo().catchError((onError) {
_refreshController.refreshFailed();
});
4 years ago
4 years ago
BaseData rankData = await apiService.rankList().catchError((onError) {
_refreshController.refreshFailed();
});
4 years ago
if (rankData != null && rankData.isSuccess) {
4 years ago
ranks.clear();
4 years ago
ranks.addAll((rankData.data as List<dynamic>)
.map((e) => Rank.fromJson(e))
.toList());
4 years ago
}
4 years ago
4 years ago
if (Navigator.canPop(context)) Navigator.of(context).pop();
4 years ago
if (baseDate != null && baseDate.isSuccess) {
4 years ago
userinfo = UserInfo.fromJson(baseDate.data);
4 years ago
if (userinfo != null &&
userinfo.memberRankVo != null &&
ranks != null &&
ranks.length > 0) {
rankLevel = (ranks.indexWhere(
(element) => element.id == userinfo.memberRankVo.id) +
1);
4 years ago
}
4 years ago
SharedPreferences.getInstance().then(
(value) => {
value.setString('user', jsonEncode(baseDate.data)),
},
);
4 years ago
_refreshController.refreshCompleted();
4 years ago
} else {
4 years ago
_refreshController.refreshFailed();
4 years ago
Fluttertoast.showToast(msg: baseDate.msg);
4 years ago
}
4 years ago
if (mounted) setState(() {});
4 years ago
}
4 years ago
RefreshController _refreshController = RefreshController();
4 years ago
4 years ago
@override
Widget build(BuildContext context) {
4 years ago
super.build(context);
4 years ago
return Scaffold(
backgroundColor: Color(0xFFF7F7F7),
body: Container(
4 years ago
padding: EdgeInsets.only(bottom: 76.h),
4 years ago
margin: EdgeInsets.only(top: 40.h),
4 years ago
child: SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
4 years ago
physics: BouncingScrollPhysics(),
4 years ago
onRefresh: queryUserInfo,
child: SingleChildScrollView(
child: Container(
child: Stack(
alignment: Alignment.centerRight,
children: [
Column(
children: [
InkWell(
onTap: _toUserInfo,
child: mineView(),
4 years ago
),
4 years ago
GestureDetector(
onTap: () {
4 years ago
Navigator.of(context).pushNamed(
'/router/mine_vip_level_page',
arguments: {
"rankLevel": rankLevel,
"points": (userinfo != null)
? int.tryParse(userinfo.points)
: 0,
});
4 years ago
},
child: MineVipView(
4 years ago
rankLevel,
curLevel: rankLevel,
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 : "",
),
),
orderOrCard(),
mineList(context),
],
),
buildNotice(),
],
),
4 years ago
),
),
),
),
);
}
4 years ago
///横向的提示
4 years ago
Widget buildNotice() {
return Container(
4 years ago
margin: EdgeInsets.only(top: 130.h),
4 years ago
child: Stack(
children: [
Container(
4 years ago
height: 33.h,
margin: EdgeInsets.only(left: 12.w),
padding: EdgeInsets.only(left: 16.w),
4 years ago
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
4 years ago
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0,
)
4 years ago
],
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,
4 years ago
fontSize: 12.sp,
4 years ago
color: Colors.black),
),
Icon(
Icons.keyboard_arrow_right,
color: Colors.black,
size: 16,
)
],
),
),
Container(
4 years ago
margin: EdgeInsets.only(top: 5.h, bottom: 4.h),
4 years ago
padding: EdgeInsets.all(2),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
4 years ago
color: Colors.black.withAlpha(25),
offset: Offset(0, 1),
blurRadius: 12,
spreadRadius: 0,
)
4 years ago
],
shape: BoxShape.circle,
// borderRadius: BorderRadius.all(Radius.circular(2)),
),
child: Image.asset(
"assets/image/icon_mine_motorcycle.png",
4 years ago
width: 20.w,
height: 20.h,
4 years ago
fit: BoxFit.contain,
),
),
],
),
);
}
4 years ago
///我的下面的条目列表
4 years ago
Widget mineList(BuildContext context) {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
padding: EdgeInsets.fromLTRB(20.w, 12.h, 20.w, 12.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(
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(
4 years ago
S.of(context).lingquanzhongxin,
"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(
4 years ago
margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
4 years ago
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
icon,
4 years ago
width: 28.w,
height: 28.h,
4 years ago
),
SizedBox(
4 years ago
width: 12.w,
4 years ago
),
Expanded(
4 years ago
flex: 1,
child: Text(
text,
style: TextStyle(
fontWeight: FontWeight.bold,
4 years ago
fontSize: 16.sp,
4 years ago
color: Color(0xFF353535),
),
),
),
4 years ago
Icon(
Icons.keyboard_arrow_right,
size: 20,
color: Colors.black,
)
],
),
);
}
4 years ago
///订单或者卡包试图
4 years ago
Widget orderOrCard() {
return Container(
4 years ago
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w, 8.h),
padding: EdgeInsets.fromLTRB(20.w, 12.h, 20.w, 12.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: 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.w,
height: 32.h,
4 years ago
),
SizedBox(
4 years ago
width: 12.w,
4 years ago
),
Text(
4 years ago
S.of(context).kaquan,
4 years ago
style: TextStyle(
4 years ago
fontWeight: FontWeight.bold,
4 years ago
fontSize: 16.sp,
4 years ago
color: Color(0xFF353535),
),
4 years ago
)
],
),
),
),
Container(
4 years ago
width: 2.w,
height: 32.h,
margin: EdgeInsets.only(left: 20.w, right: 20.w),
4 years ago
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.w,
height: 32.h,
4 years ago
),
SizedBox(
4 years ago
width: 12.w,
4 years ago
),
Text(
S.of(context).dingdan,
style: TextStyle(
4 years ago
fontWeight: FontWeight.bold,
4 years ago
fontSize: 16.sp,
4 years ago
color: Color(0xFF353535),
),
4 years ago
)
],
),
),
),
],
),
);
}
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(
4 years ago
userinfo == null ? "" : userinfo.headimg,
4 years ago
radius: BorderRadius.all(Radius.circular(4)),
4 years ago
width: 84.w,
height: 84.h,
4 years ago
fit: BoxFit.cover,
4 years ago
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
4 years ago
),
SizedBox(
4 years ago
width: 16.w,
4 years ago
),
Expanded(
flex: 1,
child: Container(
4 years ago
height: 84.h,
4 years ago
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
child: Text(
userinfo == null ? "" : "${userinfo.nickname}",
style: TextStyle(
4 years ago
fontSize: 16.sp,
4 years ago
fontWeight: FontWeight.bold,
color: Color(0xFF353535)),
),
flex: 1,
),
InkWell(
onTap: () {
4 years ago
// Navigator.of(context).pushNamed('/router/ui_test');
4 years ago
},
child: Image.asset(
"assets/image/icon_scan_qr_code.png",
4 years ago
width: 24.w,
height: 24.h,
4 years ago
),
),
],
),
Text(
4 years ago
userinfo == null ? "NO.0" : "NO.${userinfo.vipNo}",
4 years ago
style: TextStyle(
4 years ago
fontSize: 12.sp,
4 years ago
color: Color(0xFF2F2F2F),
),
4 years ago
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/icon_an_crown.png",
4 years ago
width: 13.w,
height: 13.h,
4 years ago
),
SizedBox(
4 years ago
width: 8.h,
4 years ago
),
Text(
4 years ago
userinfo == null || userinfo.memberRankVo == null
? ""
: "${userinfo.memberRankVo.rankName}",
4 years ago
style: TextStyle(
4 years ago
fontSize: 12.sp,
4 years ago
fontWeight: FontWeight.bold,
color: Color(0xFF353535),
),
4 years ago
),
Expanded(
child: GestureDetector(
onTap: () {
Navigator.of(context)
.pushNamed('/router/integral_page');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
S.of(context).jifenxiangqing,
style: TextStyle(
4 years ago
color: Colors.black,
fontSize: 12.sp,
fontWeight: FontWeight.bold,
),
4 years ago
),
Icon(
Icons.keyboard_arrow_right,
size: 16,
color: Colors.black,
)
],
),
),
),
],
)
],
),
),
),
],
),
);
}
4 years ago
@override
bool get wantKeepAlive => true;
4 years ago
}