SteamCloudGame_Car/lib/tools/me/my_page.dart
2024-12-28 15:57:33 +08:00

657 lines
29 KiB
Dart

import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../beans/user_info_bean.dart';
import '../../common/EventBusUtil.dart';
import '../../common/func.dart';
import '../../dialog/exchange_dialog.dart';
import '../../dialog/sign_dialog.dart';
import '../../network/NetworkConfig.dart';
import 'me_model.dart';
class MyPage extends StatefulWidget {
const MyPage({super.key});
@override
State<MyPage> createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
late StreamSubscription subscription;
final MeModel _viewModel = MeModel();
late UserInfoBean userInfoBean;
late StreamSubscription<RefreshUserdata> _event;
bool _isInitialized = false;
late BuildContext exchangeContext;
@override
void initState() {
// TODO: implement initState
super.initState();
_event = EventBusUtil.listen((event) {
_viewModel.getUserInfo();
});
subscription = _viewModel.streamController.stream.listen((event) {
String code = event['code'];
if (code.isNotEmpty) {
switch (code) {
case "getUserInfo":
EasyLoading.dismiss();
userInfoBean = event['data'];
_isInitialized = true;
break;
case "useRedemptionCode":
EasyLoading.dismiss();
EventBusUtil.fire(RefreshUserdata());
Navigator.pop(exchangeContext);
EasyLoading.showToast(event['data']);
break;
case "codeError":
EasyLoading.showToast(event['data']);
break;
case "sevenSignToday": //签到
EasyLoading.showToast(event['data']);
EventBusUtil.fire(RefreshUserdata());
_viewModel.getSevenSignList();
_viewModel.getUserInfo();
break;
default:
EasyLoading.showToast(event['data']);
break;
}
setState(() {});
}
});
FunctionUtil.loading();
_viewModel.getUserInfo();
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
subscription.cancel();
_event.cancel();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final l14 = size.width / 25.714285714285;
final t18 = size.width / 20;
final w20 = size.width / 18;
final l11 = size.width / 32.727272727272;
final l4 = size.width / 90;
final h8 = size.width / 45;
final t36 = size.width / 10;
final h32 = size.width / 11.25;
final c5 = size.width / 72;
final s6 = size.width / 60;
final l38 = size.width / 9.4736842105263;
final s4 = size.width / 90;
final l2 = size.width / 180;
final h21 = size.width / 17.142857142857;
final l3 = size.width / 120;
final h6 = size.width / 60;
final t14 = size.width / 25.714285714285;
return _isInitialized
? Scaffold(
backgroundColor: const Color(0xFF17181A),
body: SingleChildScrollView(
child: Column(
children: [
// SizedBox(
// height: h282,
// child: Stack(
// alignment: Alignment.center,
// children: [
// Positioned(
// top: 0,
// child: Image(width: size.width, fit: BoxFit.fill, image: AssetImage('assets/images/me_bg.png')),
// ),
// Positioned(
// left: l14,
// top: t110,
// child: ClipOval(
// child: CachedNetworkImage(
// width: w57,
// height: w57,
// imageUrl: '${userInfoBean.userIcon}',
// errorWidget: (context, url, error) => const Icon(Icons.error),
// )),
// ),
// Positioned(
// left: l85,
// top: t110,
// child: Text(
// "${userInfoBean.nickName}",
// style: TextStyle(fontSize: s18, color: Colors.white),
// )),
// Positioned(
// left: l85,
// top: t147,
// child: GestureDetector(
// onTap: () {
// Navigator.pushNamed(context, "/EditInfoPage");
// },
// child: Row(
// children: [
// Text(
// "编辑个人信息",
// style: TextStyle(fontSize: l11, color: Color(0xFF909090)),
// ),
// Container(
// margin: EdgeInsets.only(left: l4),
// child: Image(
// width: l4,
// height: h8,
// image: AssetImage('assets/images/ic_arrow.png'),
// ),
// ),
// ],
// ),
// )),
// Positioned(
// top: t203,
// child: !NetworkConfig.isChecking
// ? Container(
// padding: EdgeInsets.only(left: l14, right: l14),
// child: Container(
// width: w330,
// height: h79,
// decoration: BoxDecoration(
// gradient: const LinearGradient(
// begin: Alignment.centerLeft,
// end: Alignment.centerRight,
// colors: [
// Color(0xFF0978FF),
// Color(0xFF39ADFE),
// ],
// ),
// borderRadius: BorderRadius.all(Radius.circular(l11)),
// ),
// child: Stack(
// alignment: Alignment.center,
// children: [
// Positioned(
// left: l23,
// top: t22,
// child: Text(
// "已游玩时长",
// style: TextStyle(fontSize: l11, color: Color(0xFFE2F3FF)),
// )),
// Positioned(
// left: l23,
// top: t41,
// child: Text(
// "${userInfoBean.userPlayGameTime} 分钟",
// style: TextStyle(fontSize: s16, color: Colors.white),
// )),
// Positioned(
// right: l23,
// child: Image(
// width: w37,
// height: w37,
// image: const AssetImage('assets/images/ic_game_time.png'),
// ),
// )
// ],
// ),
// ),
// )
// : Container(),
// ),
// ],
// ),
// ),
Container(
width: size.width,
height: h32,
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top + t36, left: l11, right: l11),
decoration: BoxDecoration(
color: Color(0xFF202530),
borderRadius: BorderRadius.all(Radius.circular(c5)),
),
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
left: l11,
child: ClipOval(
child: CachedNetworkImage(
width: w20,
height: w20,
imageUrl: '${userInfoBean.userIcon}',
errorWidget: (context, url, error) => const Icon(Icons.error),
)),
),
Positioned(
left: l38,
top: h8,
child: Text(
"${userInfoBean.nickName}",
style: TextStyle(fontSize: s6, color: Colors.white),
)),
Positioned(
left: l38,
top: t18,
child: GestureDetector(
onTap: () {
Navigator.pushNamed(context, "/EditInfoPage");
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"编辑个人信息",
style: TextStyle(fontSize: s4, color: Color(0xFF909090)),
),
Container(
margin: EdgeInsets.only(left: l2),
child: Image(
width: l2,
height: l4,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
)),
Positioned(
right: l11,
top: h8,
child: Text(
"已游玩时长",
style: TextStyle(fontSize: s4, color: Color(0xFF8F8F8F)),
)),
Positioned(
right: l11,
top: t18,
child: Text(
"${userInfoBean.userPlayGameTime} 分钟",
style: TextStyle(fontSize: s6, color: Colors.white),
)),
],
),
),
Container(
margin: EdgeInsets.only(top: t14, left: l11, right: l11),
decoration: BoxDecoration(
color: Color(0xFF202530),
borderRadius: BorderRadius.all(Radius.circular(c5)),
),
child: Column(
children: [
///每日签到
!NetworkConfig.isChecking
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
FunctionUtil.popDialog2(
context,
SignDialog(
list: NetworkConfig.signData!.list!,
onTap: () {
if (NetworkConfig.signData!.isSign!) {
EasyLoading.showToast("今日已签到");
return;
}
FunctionUtil.loading();
_viewModel.sevenSignToday();
},
));
},
child: SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"每日签到",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
)
: Container(),
///任务中心
// SizedBox(
// height: h60,
// child: Row(
// children: [
// Container(
// margin: EdgeInsets.only(left: l23),
// child: Image(
// width: w20,
// height: w20,
// image: AssetImage('assets/images/ic_task.png'),
// ),
// ),
// Container(
// margin: EdgeInsets.only(left: l14),
// child: const Text(
// "任务中心",
// style: TextStyle(fontSize: 14, color: Color(0xFFD6D6D7)),
// ),
// ),
// Expanded(child: Container()),
// Container(
// margin: EdgeInsets.only(right: l23),
// child: const Image(
// width: 4,
// height: 8,
// image: AssetImage('assets/images/ic_arrow.png'),
// ),
// ),
// ],
// ),
// ),
],
),
),
///游玩历史
!NetworkConfig.isChecking
? GestureDetector(
onTap: () {
Navigator.pushNamed(context, "/GameHistoryPage");
},
child: Container(
margin: EdgeInsets.only(top: t14, left: l11, right: l11),
decoration: BoxDecoration(
color: Color(0xFF202530),
borderRadius: BorderRadius.all(Radius.circular(c5)),
),
child: Column(
children: [
SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"游玩历史",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
],
),
),
)
: Container(),
///包月卡
// Container(
// margin: EdgeInsets.only(top: t18, left: l14, right: l14),
// decoration: const BoxDecoration(
// color: Color(0xFF202530),
// borderRadius: BorderRadius.all(Radius.circular(11)),
// ),
// child: Column(
// children: [
// SizedBox(
// height: h60,
// child: Row(
// children: [
// Container(
// margin: EdgeInsets.only(left: l23),
// child: Image(
// width: w20,
// height: w20,
// image: const AssetImage('assets/images/ic_night.png'),
// ),
// ),
// Container(
// margin: EdgeInsets.only(left: l14),
// child: const Text(
// "包夜卡",
// style: TextStyle(fontSize: 14, color: Color(0xFFD6D6D7)),
// ),
// ),
// Expanded(child: Container()),
// Container(
// margin: EdgeInsets.only(right: l23),
// child: const Image(
// width: 4,
// height: 8,
// image: AssetImage('assets/images/ic_arrow.png'),
// ),
// ),
// ],
// ),
// ),
// ],
// ),
// ),
Container(
margin: EdgeInsets.only(top: t18, left: l14, right: l14, bottom: w20),
decoration: const BoxDecoration(
color: Color(0xFF202530),
borderRadius: BorderRadius.all(Radius.circular(11)),
),
child: Column(
children: [
///资产记录
!NetworkConfig.isChecking
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pushNamed(context, "/PropertyPage");
},
child: SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"资产记录",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
)
: Container(),
///兑换码
!NetworkConfig.isChecking
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
exchangeContext = context;
return ExchangeDialog(
onTap: (value) {
FunctionUtil.loading();
_viewModel.useRedemptionCode(value);
},
);
});
},
child: SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"兑换码",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
)
: Container(),
///反馈
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pushNamed(context, '/FeedbackPage');
},
child: SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"反馈",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
),
///我的收藏
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pushNamed(context, "/MyCollectPage");
},
child: SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"我的收藏",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
),
///设置
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pushNamed(context, "/SettingPage");
},
child: SizedBox(
height: h21,
child: Row(
children: [
Container(
margin: EdgeInsets.only(left: l11),
child: Text(
"设置",
style: TextStyle(fontSize: s6, color: Color(0xFFD6D6D7)),
),
),
Expanded(child: Container()),
Container(
margin: EdgeInsets.only(right: l11),
child: Image(
width: l3,
height: h6,
image: AssetImage('assets/images/ic_arrow.png'),
),
),
],
),
),
),
],
),
),
],
),
),
)
: Container();
}
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}