|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/main.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/flutter_utils.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/custom_image.dart';
|
|
|
|
import 'package:huixiang/view_widget/login_tips.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/order_card_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();
|
|
|
|
_refreshController.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
eventBus.on<EventType>().listen((event) {
|
|
|
|
print("EventType: ${event.type}");
|
|
|
|
if (event.type < 3) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
if (event.type == 3) {
|
|
|
|
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: () {
|
|
|
|
// queryUserInfo
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
children: [
|
|
|
|
FutureBuilder(
|
|
|
|
future: queryUserInfo(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
///我的 用户信息
|
|
|
|
MineView(
|
|
|
|
userInfo,
|
|
|
|
() {
|
|
|
|
_toUserInfo();
|
|
|
|
},
|
|
|
|
() {
|
|
|
|
toIntegralPage();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
///我的 VIP等级信息
|
|
|
|
MineVipView(
|
|
|
|
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 : "",
|
|
|
|
),
|
|
|
|
|
|
|
|
/// 订单或会员卡
|
|
|
|
OrderCard(),
|
|
|
|
|
|
|
|
///我的 下面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: FontWeight.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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|