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.

464 lines
15 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_easyloading/flutter_easyloading.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/main.dart';
3 years ago
import 'package:huixiang/mine/mine_view/mine_order.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
4 years ago
import 'package:huixiang/retrofit/data/rank.dart';
3 years ago
import 'package:huixiang/retrofit/data/social_info.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';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/classic_header.dart';
3 years ago
import 'package:huixiang/view_widget/login_tips_dialog.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
3 years ago
import 'mine_view/mine_item.dart';
import 'mine_view/mine_view.dart';
3 years ago
import 'mine_view/wallet_coupon_view.dart';
3 years ago
4 years ago
class MinePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MinePage();
}
}
3 years ago
class _MinePage extends State<MinePage> with AutomaticKeepAliveClientMixin {
4 years ago
ApiService apiService;
3 years ago
UserInfo userInfo;
3 years ago
List<Rank> ranks = [];
3 years ago
SocialInfo infoNumber;
3 years ago
final RefreshController _refreshController = RefreshController();
4 years ago
_toUserInfo() async {
4 years ago
SharedPreferences shared = await SharedPreferences.getInstance();
if (shared.getString("token") == null || shared.getString("token") == "") {
3 years ago
Navigator.of(context)
.pushNamed('/router/login_page', arguments: {"login": "login"});
4 years ago
return;
}
3 years ago
// await Navigator.of(context).pushNamed('/router/user_info_page');
await Navigator.of(context).pushNamed('/router/personal_page',arguments:{"memberId":"0",});
3 years ago
setState(() {});
4 years ago
}
@override
void dispose() {
super.dispose();
if (_refreshController != null) _refreshController.dispose();
}
4 years ago
@override
void initState() {
super.initState();
3 years ago
querySocialInfo();
3 years ago
4 years ago
eventBus.on<EventType>().listen((event) {
print("EventType: ${event.type}");
if (event.type < 3) {
3 years ago
if (mounted) setState(() {});
4 years ago
}
if (event.type == 3) {
3 years ago
if (mounted) setState(() {});
}
4 years ago
});
}
4 years ago
3 years ago
queryUserInfo() async {
3 years ago
// EasyLoading.show(status: S.of(context).zhengzaijiazai);
4 years ago
3 years ago
final SharedPreferences value = await SharedPreferences.getInstance();
if (value.containsKey('user') &&
value.getString('user') != null &&
value.getString('user') != "") {
3 years ago
userInfo = UserInfo.fromJson(jsonDecode(value.getString('user')));
3 years ago
}
3 years ago
apiService = ApiService(
Dio(),
context: context,
token: value.getString('token'),
showLoading: false,
);
4 years ago
3 years ago
BaseData<List<Rank>> rankData =
await apiService.rankList().catchError((onError) {
_refreshController.refreshFailed();
});
4 years ago
if (rankData != null && rankData.isSuccess) {
4 years ago
ranks.clear();
3 years ago
ranks.addAll(rankData.data);
4 years ago
}
4 years ago
3 years ago
BaseData<UserInfo> baseDate =
await apiService.queryInfo().catchError((onError) {
_refreshController.refreshFailed();
});
4 years ago
if (baseDate != null && baseDate.isSuccess) {
3 years ago
userInfo = baseDate.data;
4 years ago
SharedPreferences.getInstance().then(
4 years ago
(value) => {
4 years ago
value.setString('user', jsonEncode(baseDate.data)),
},
);
4 years ago
_refreshController.refreshCompleted();
4 years ago
} else {
4 years ago
_refreshController.refreshFailed();
4 years ago
}
3 years ago
// EasyLoading.dismiss();
4 years ago
}
_onRefresh() {
3 years ago
// queryUserInfo();
querySocialInfo();
}
///个人社交信息(粉丝/关注数量/成就数量)
3 years ago
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();
});
3 years ago
if (baseData != null && baseData.isSuccess) {
infoNumber = baseData.data;
_refreshController.refreshCompleted();
3 years ago
}
EasyLoading.dismiss();
}
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),
3 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(),
3 years ago
onRefresh: () {
setState(() {
_onRefresh();
});
3 years ago
},
4 years ago
child: SingleChildScrollView(
child: Container(
child: Stack(
alignment: Alignment.centerRight,
children: [
3 years ago
FutureBuilder(
3 years ago
future: queryUserInfo(),
builder: (context, snapshot) {
return Column(
children: [
3 years ago
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.topRight,
colors: [
Color(0xFFE5F7FF),
Color(0xFFE8F5E9),
],
stops: [0.1, 0.8],
),
),
child: Column(
children: [
///我的 用户信息
MineView(
userInfo,
() {
_toUserInfo();
},
() {
toIntegralPage();
},
),
///我的 VIP等级信息
MineVipView(
tag: "vip",
ranks: ranks,
userInfo: userInfo,
rank: double.tryParse(
userInfo?.expendAmount ?? "0")
.toInt(),
rankMax:
userInfo?.memberRankVo?.nextOrigin ?? 0,
createTime: userInfo?.createTime ?? "",
3 years ago
),
],
),
3 years ago
),
///关注度/粉丝/发布
attention(),
3 years ago
/// 钱包或领券中心
WalletCoupon(),
3 years ago
3 years ago
MineOrderView(),
3 years ago
///我的 下面item
MineItem(),
],
);
},
),
4 years ago
// buildNotice(),
4 years ago
],
),
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(
4 years ago
S.of(context).ninyouyigedingdanyaolingqu,
4 years ago
style: TextStyle(
3 years ago
fontWeight: MyFontWeight.bold,
3 years ago
fontSize: 12.sp,
color: Colors.black,
),
4 years ago
),
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,
),
child: Image.asset(
"assets/image/icon_mine_motorcycle.webp",
4 years ago
width: 20.w,
height: 20.h,
4 years ago
fit: BoxFit.contain,
),
),
],
),
);
}
///关注度/粉丝/成就数量
Widget attention() {
3 years ago
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,
),
),
],
)),
3 years ago
),
),
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(
"成就",
style: TextStyle(
color: Color(0xFF000000),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
),
],
3 years ago
),
)),
)
],
3 years ago
),
);
}
4 years ago
toIntegralPage() async {
4 years ago
SharedPreferences shared = await SharedPreferences.getInstance();
if (shared.getString("token") == null || shared.getString("token") == "") {
3 years ago
LoginTipsDialog().show(context);
4 years ago
return;
}
await Navigator.of(context).pushNamed('/router/integral_page');
3 years ago
setState(() {});
4 years ago
}
4 years ago
@override
bool get wantKeepAlive => true;
4 years ago
}