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.
 
 
 
 
 
 

640 lines
21 KiB

import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/mine/mine_view/mine_calendar.dart';
import 'package:huixiang/mine/mine_view/mine_order.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/msg_stats.dart';
import 'package:huixiang/retrofit/data/rank.dart';
import 'package:huixiang/retrofit/data/social_info.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/event_type.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/login_tips_dialog.dart';
import 'package:huixiang/view_widget/mine_vip_entry.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dio/dio.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'mine_view/mine_item.dart';
import 'mine_view/mine_view.dart';
class MinePage extends StatefulWidget {
MinePage(Key key): super(key: key);
@override
State<StatefulWidget> createState() {
return MinePageState();
}
}
class MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin {
ApiService apiService;
UserInfo userInfo;
List<Rank> ranks = [];
SocialInfo infoNumber;
final RefreshController _refreshController = RefreshController();
int totalMsg = 0;
_toUserInfo() async {
SharedPreferences shared = await SharedPreferences.getInstance();
if (shared.getString("token") == null || shared.getString("token") == "") {
Navigator.of(context)
.pushNamed('/router/new_login_page', arguments: {"login": "login"});
return;
}
// await Navigator.of(context).pushNamed('/router/user_info_page');
await Navigator.of(context).pushNamed('/router/personal_page',arguments:{"memberId":"0",});
setState(() {});
}
@override
void dispose() {
super.dispose();
if (_refreshController != null) _refreshController.dispose();
}
@override
void initState() {
super.initState();
querySocialInfo();
queryMsgStats();
eventBus.on<EventType>().listen((event) {
print("EventType: ${event.type}");
if (event.type < 3) {
if (mounted) setState(() {});
}
if (event.type == 3) {
if (mounted) setState(() {});
}
});
}
queryUserInfo() async {
// EasyLoading.show(status: S.of(context).zhengzaijiazai);
final SharedPreferences value = await SharedPreferences.getInstance();
if (value.containsKey('user') &&
value.getString('user') != null &&
value.getString('user') != "") {
userInfo = UserInfo.fromJson(jsonDecode(value.getString('user')));
}
apiService = ApiService(
Dio(),
context: context,
token: value.getString('token'),
showLoading: false,
);
BaseData<List<Rank>> rankData =
await apiService.rankList().catchError((onError) {
_refreshController.refreshFailed();
});
if (rankData != null && rankData.isSuccess) {
ranks.clear();
ranks.addAll(rankData.data);
}
BaseData<UserInfo> baseDate =
await apiService.queryInfo().catchError((onError) {
_refreshController.refreshFailed();
});
if (baseDate != null && baseDate.isSuccess) {
userInfo = baseDate.data;
SharedPreferences.getInstance().then(
(value) => {
value.setString('user', jsonEncode(baseDate.data)),
},
);
_refreshController.refreshCompleted();
} else {
_refreshController.refreshFailed();
}
// EasyLoading.dismiss();
}
_onRefresh() {
// queryUserInfo();
querySocialInfo();
queryMsgStats();
}
///个人社交信息(粉丝/关注数量/成就数量)
querySocialInfo() async {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
showLoading: false,
);
BaseData<SocialInfo> baseData =
await apiService.socialInfo().catchError((onError) {
_refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
infoNumber = baseData.data;
_refreshController.refreshCompleted();
}
EasyLoading.dismiss();
}
///消息数量
queryMsgStats() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<List<MsgStats>> baseData = await apiService.stats().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
totalMsg = 0;
baseData.data.forEach((element) {
totalMsg += element.number;
});
});
}
EasyLoading.dismiss();
}
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
backgroundColor: Color(0xFFF9FAF7),
body: Container(
padding: EdgeInsets.only(bottom: 76.h),
// margin: EdgeInsets.only(top: 40.h),
child: SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
onRefresh: () {
setState(() {
_onRefresh();
});
},
child: SingleChildScrollView(
child: Container(
child: Stack(
// alignment: Alignment.centerRight,
children: [
Container(
height: 317,
decoration: BoxDecoration(
color: Color(0xFF32A060)
),
),
FutureBuilder(
future: queryUserInfo(),
builder: (context, snapshot) {
return Column(
children: [
Stack(
children: [
Container(
child: Column(
children: [
///我的 用户信息
MineView(
userInfo,
() {
_toUserInfo();
},
() {
toIntegralPage();
},
(){
setState(() {
totalMsg =0;
});
},
totalMsg,
infoNumber
),
///我的 VIP等级信息
MineVipEntry(
tag: "vip",
ranks: ranks,
userInfo: userInfo,
rank: double.tryParse(
userInfo?.expendAmount ?? "0")
.toInt(),
rankMax:
userInfo?.memberRankVo?.nextOrigin ?? 0,
createTime: userInfo?.createTime ?? "",
),
],
),
),
Container(
margin: EdgeInsets.only(top: 265.h),
child: Column(
children: [
///我的订单
MineOrderView(),
///推广图
spreadImage(),
///我的 下面item
MineItem(),
///我的成就
attainment(),
///绿色足迹
MineCalendar()
],
),
)
],
)
// ///关注度/粉丝/发布
// attention(),
//
// /// 钱包或领券中心
// WalletCoupon(),
],
);
},
),
// buildNotice(),
],
),
),
),
),
),
);
}
///我的成就
Widget attainment() {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: (){
Navigator.of(context).pushNamed(
'/router/mine_attainment_page',
arguments: {"userInfo": userInfo},
);
},
child:Container(
margin: EdgeInsets.only(left:14,right:14,bottom:10),
padding: EdgeInsets.only(left:12, top:12, right:10,bottom: 12),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 3,
spreadRadius: 0,
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
S.of(context).wodechengjiu,
style: TextStyle(
fontWeight: MyFontWeight.bold,
fontSize: 15.sp,
color: Color(0xFF0D0D0D),
),
),
SizedBox(height: 9.h,),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset(
"assets/image/icon_attainment.webp",
width:54,
height:54,
fit: BoxFit.cover,
),
SizedBox(width: 7.w,),
Expanded(child:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"已解锁${infoNumber != null
? infoNumber.achievementNumber.toString()
: "0"}个成就",
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 14.sp,
color: Color(0xFF262626),
),
),
SizedBox(height:4.w,),
Text(
"完成任务解锁更多成就",
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
color: Color(0xFF4D4D4D),
),
),
],
)),
Container(
width: 60.w,
height: 19.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Color(0xFF32A060),
width: 1,
),
),
child: Text(
"全部成就",
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 12.sp,
color: Color(0xFF32A060),
),
),
)
],
)
],
),
),
);
}
///推广图
Widget spreadImage() {
return Container(
margin: EdgeInsets.only(right:14.w,bottom:10.h,left: 14.w),
child: GestureDetector(
onTap: (){
Navigator.of(context).pushNamed('/router/welfare_page');
},
child:ClipRRect(
child:Image.asset(
"assets/image/welfare_spread.webp",
width:double.infinity,
fit: BoxFit.fill,
height:80.h,
),
borderRadius: BorderRadius.circular(6.w),
),
),
);
}
///横向的提示
Widget buildNotice() {
return Container(
margin: EdgeInsets.only(top: 130.h),
child: Stack(
children: [
Container(
height: 33.h,
margin: EdgeInsets.only(left: 12.w),
padding: EdgeInsets.only(left: 16.w),
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: MyFontWeight.bold,
fontSize: 12.sp,
color: Colors.black,
),
),
Icon(
Icons.keyboard_arrow_right,
color: Colors.black,
size: 16,
)
],
),
),
Container(
margin: EdgeInsets.only(top: 5.h, bottom: 4.h),
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,
),
child: Image.asset(
"assets/image/icon_mine_motorcycle.webp",
width: 20.w,
height: 20.h,
fit: BoxFit.contain,
),
),
],
),
);
}
///关注度/粉丝/成就数量
Widget attention() {
return Container(
margin: EdgeInsets.only(left: 16, top: 10, right: 16),
// padding: EdgeInsets.only(top: 16,bottom: 16),
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: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/communityFollow',
arguments: {},
);
},
child: Container(
color: Colors.transparent,
padding: EdgeInsets.all(16),
child: Column(
children: [
Text(
infoNumber != null ? infoNumber.follow.toString() : "0",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 15.sp,
fontWeight: MyFontWeight.medium,
),
),
SizedBox(
height: 4,
),
Text(
S.of(context).guanzhu,
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
),
],
)),
),
),
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/communityFollow',
arguments: {},
);
},
child: Container(
color: Colors.transparent,
padding: EdgeInsets.all(16),
child: Column(
children: [
Text(
infoNumber != null ? infoNumber.fans.toString() : "0",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 15.sp,
fontWeight: MyFontWeight.medium,
),
),
SizedBox(
height: 4,
),
Text(
S.of(context).fensi,
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
),
],
)),
),
),
Expanded(
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pushNamed(
'/router/mine_attainment_page',
arguments: {"userInfo": userInfo},
);
},
child: Container(
color: Colors.transparent,
padding: EdgeInsets.all(16),
child: Column(
children: [
Text(
infoNumber != null
? infoNumber.achievementNumber.toString()
: "0",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 15.sp,
fontWeight: MyFontWeight.medium,
),
),
SizedBox(
height: 4,
),
Text(
S.of(context).chengjiu,
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
)),
)
],
),
);
}
toIntegralPage() async {
SharedPreferences shared = await SharedPreferences.getInstance();
if (shared.getString("token") == null || shared.getString("token") == "") {
LoginTipsDialog().show(context);
return;
}
await Navigator.of(context).pushNamed('/router/integral_page');
setState(() {});
}
@override
bool get wantKeepAlive => true;
}