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.
378 lines
12 KiB
378 lines
12 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_order.dart'; |
|
import 'package:huixiang/retrofit/data/base_data.dart'; |
|
import 'package:huixiang/retrofit/data/rank.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_view.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'; |
|
import 'mine_view/wallet_coupon_view.dart'; |
|
|
|
class MinePage extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _MinePage(); |
|
} |
|
} |
|
|
|
class _MinePage extends State<MinePage> with AutomaticKeepAliveClientMixin { |
|
ApiService apiService; |
|
UserInfo userInfo; |
|
List<Rank> ranks = []; |
|
final RefreshController _refreshController = RefreshController(); |
|
|
|
_toUserInfo() async { |
|
SharedPreferences shared = await SharedPreferences.getInstance(); |
|
if (shared.getString("token") == null || shared.getString("token") == "") { |
|
Navigator.of(context) |
|
.pushNamed('/router/login_page', arguments: {"login": "login"}); |
|
return; |
|
} |
|
await Navigator.of(context).pushNamed('/router/user_info_page'); |
|
setState(() {}); |
|
} |
|
|
|
@override |
|
void dispose() { |
|
super.dispose(); |
|
if (_refreshController != null) |
|
_refreshController.dispose(); |
|
} |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
|
|
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(); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
super.build(context); |
|
return Scaffold( |
|
backgroundColor: Color(0xFFF7F7F7), |
|
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(() {}); |
|
}, |
|
child: SingleChildScrollView( |
|
child: Container( |
|
child: Stack( |
|
alignment: Alignment.centerRight, |
|
children: [ |
|
FutureBuilder( |
|
future: queryUserInfo(), |
|
builder: (context, snapshot) { |
|
return Column( |
|
children: [ |
|
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(); |
|
}, |
|
), |
|
|
|
///关注度/粉丝/发布 |
|
attention(), |
|
|
|
///我的 VIP等级信息 |
|
MineVipView( |
|
tag: "vip", |
|
ranks: ranks, |
|
userInfo: userInfo, |
|
rank: (userInfo != null) |
|
? int.tryParse(userInfo.points) |
|
: 0, |
|
rankMax: (userInfo != null && |
|
userInfo.memberRankVo != null) |
|
? userInfo.memberRankVo.rankOrigin |
|
: 0, |
|
createTime: (userInfo != null) |
|
? userInfo.createTime |
|
: "", |
|
), |
|
], |
|
), |
|
), |
|
|
|
/// 钱包或领券中心 |
|
WalletCoupon(), |
|
|
|
MineOrderView(), |
|
|
|
///我的 下面item |
|
MineItem(), |
|
], |
|
); |
|
}, |
|
), |
|
// buildNotice(), |
|
], |
|
), |
|
), |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
|
|
///横向的提示 |
|
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.png", |
|
width: 20.w, |
|
height: 20.h, |
|
fit: BoxFit.contain, |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
///关注度/粉丝/发布 |
|
Widget attention(){ |
|
return Container( |
|
margin: EdgeInsets.only(left: 16,right: 17,top: 10), |
|
child:GestureDetector( |
|
onTap:(){ |
|
Navigator.of(context).pushNamed( |
|
'/router/communityFollow', |
|
arguments: {}, |
|
); |
|
}, |
|
child: Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
children: [ |
|
Text( |
|
"关注", |
|
style: TextStyle( |
|
color: Color(0xFF000000), |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
Text( |
|
"45", |
|
style: TextStyle( |
|
color: Color(0xFF000000), |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
], |
|
), |
|
Row( |
|
children: [ |
|
Text( |
|
"粉丝", |
|
style: TextStyle( |
|
color: Color(0xFF000000), |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
Text( |
|
"666", |
|
style: TextStyle( |
|
color: Color(0xFF000000), |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
], |
|
), |
|
Row( |
|
children: [ |
|
Text( |
|
"发布", |
|
style: TextStyle( |
|
color: Color(0xFF000000), |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
Text( |
|
"666", |
|
style: TextStyle( |
|
color: Color(0xFF000000), |
|
fontSize: 15.sp, |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
), |
|
); |
|
} |
|
|
|
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; |
|
}
|
|
|