|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:flutter_boost/flutter_boost.dart';
|
|
import '../../ui/widget/button.dart';
|
import '../../utils/jump_page.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/user_util.dart';
|
import 'model/user/user_info.dart';
|
import 'ui/widget/ad_express.dart';
|
import 'ui/widget/images_widget.dart';
|
import 'utils/config_util.dart';
|
|
class MinePage extends StatefulWidget {
|
MinePage({Key? key, required this.title}) : super(key: key);
|
|
final String title;
|
|
@override
|
_MinePageState createState() => _MinePageState();
|
}
|
|
class _MinePageState extends State<MinePage>
|
with SingleTickerProviderStateMixin, PageVisibilityObserver {
|
static const Color COLOR_CONTENT = Color(0xFF999999);
|
static const Color COLOR_TITLE = Color(0xFF000000);
|
static const Color COLOR_PORTRAIT_BG = Color(0xFFDBDBDB);
|
static const Color COLOR_HIGHLIGHT = ColorConstant.theme;
|
|
int index = 1;
|
|
UserInfo? _user;
|
|
int goldCorn = 0;
|
String balance = "0.00";
|
|
int firstTeamCount = 0;
|
int secondTeamCount = 0;
|
int msgCount = 0;
|
|
@override
|
void initState() {
|
super.initState();
|
_refreshData();
|
}
|
|
void _refreshData() {
|
updateUserInfo();
|
}
|
|
void updateUserInfo() async {
|
if (!await UserUtil.isLogin()) {
|
setState(() {
|
_user = null;
|
});
|
return;
|
}
|
|
_user = await UserUtil.getUserInfo();
|
|
UserUtil.updateUserInfo(context).then((value) {
|
print("user:$value");
|
setState(() {
|
_user = value;
|
});
|
});
|
}
|
|
void jumpPage(String name,
|
{Map<String, dynamic>? params, bool needLogin = true}) async {
|
bool login = await UserUtil.isLogin();
|
if (!login && needLogin) {
|
jumpPage("LoginPage", needLogin: false);
|
return;
|
}
|
JumpPageUtil.jumpPage(name, context,
|
native: Constant.NATIVE, params: params, callback: (data) {
|
_refreshData();
|
});
|
}
|
|
@override
|
void didChangeDependencies() {
|
super.didChangeDependencies();
|
|
///注册监听器
|
PageVisibilityBinding.instance.addObserver(this, ModalRoute.of(context)!);
|
}
|
|
@override
|
void dispose() {
|
///移除监听器
|
PageVisibilityBinding.instance.removeObserver(this);
|
super.dispose();
|
}
|
|
@override
|
void onBackground() {
|
super.onBackground();
|
print("LifecycleTestPage - onBackground");
|
}
|
|
@override
|
void onForeground() {
|
super.onForeground();
|
print("LifecycleTestPage - onForeground");
|
}
|
|
@override
|
void onPageHide() {
|
super.onPageHide();
|
print("LifecycleTestPage - onPageHide");
|
}
|
|
@override
|
void onPageShow() {
|
super.onPageShow();
|
print("LifecycleTestPage - onPageShow");
|
_refreshData();
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Column(children: [
|
Expanded(
|
child: Stack(children: [
|
AspectRatio(
|
aspectRatio: 1.344,
|
child: Image.asset("assets/imgs/mine/ic_top_bg.png"),
|
),
|
SingleChildScrollView(
|
child: Column(
|
children: [
|
Container(
|
height: 100,
|
),
|
Container(
|
child: Stack(
|
children: [
|
Container(
|
alignment: Alignment.bottomRight,
|
color: Colors.white,
|
padding: EdgeInsets.only(bottom: 10),
|
margin: EdgeInsets.only(top: 28),
|
child: Column(
|
children: [
|
const SizedBox(
|
height: 15,
|
),
|
Container(
|
alignment: Alignment.topCenter,
|
color: Colors.white,
|
height: 100,
|
padding:
|
const EdgeInsets.fromLTRB(20, 25, 20, 20),
|
child: _user != null
|
? personInfoWidget()
|
:
|
//登录框
|
loginBtnWidget(),
|
),
|
Container(
|
color: Colors.white,
|
padding:
|
const EdgeInsets.only(left: 12, right: 12),
|
child: Row(
|
mainAxisSize: MainAxisSize.min,
|
mainAxisAlignment:
|
MainAxisAlignment.spaceAround,
|
children: [
|
Expanded(
|
child: InkWell(
|
onTap: () {
|
jumpPage("GoldCornPage");
|
},
|
child: Container(
|
alignment: Alignment.centerLeft,
|
child: AspectRatio(
|
aspectRatio: 2.048,
|
child: Stack(
|
alignment: Alignment.centerLeft,
|
children: [
|
ClipRRect(
|
borderRadius:
|
BorderRadius.circular(
|
12),
|
child: Image.asset(
|
"assets/imgs/mine/ic_goldcorn_bg.png")),
|
Wrap(children: [
|
const SizedBox(
|
width: 14,
|
),
|
Text.rich(TextSpan(
|
text: "$goldCorn",
|
style: const TextStyle(
|
color: Colors.white,
|
fontSize: 30),
|
children: const [
|
TextSpan(
|
text: "个",
|
style: TextStyle(
|
fontSize: 15))
|
]))
|
])
|
],
|
),
|
),
|
))),
|
const SizedBox(
|
width: 13.5,
|
),
|
Expanded(
|
child: InkWell(
|
onTap: () {
|
jumpPage("BalancePage");
|
},
|
child: Container(
|
alignment: Alignment.centerLeft,
|
child: AspectRatio(
|
aspectRatio: 2.048,
|
child: Stack(
|
alignment: Alignment.centerLeft,
|
children: [
|
ClipRRect(
|
borderRadius:
|
BorderRadius.circular(
|
12),
|
child: Image.asset(
|
"assets/imgs/mine/ic_money_bg.png")),
|
Wrap(
|
children: [
|
SizedBox(
|
width: 14,
|
),
|
Text.rich(TextSpan(
|
text: balance,
|
style: TextStyle(
|
color:
|
Colors.white,
|
fontSize: 30),
|
children: [
|
TextSpan(
|
text: "元",
|
style: TextStyle(
|
fontSize:
|
15))
|
]))
|
],
|
)
|
],
|
),
|
),
|
))),
|
],
|
),
|
),
|
//功能
|
Container(
|
height: 200,
|
margin: const EdgeInsets.fromLTRB(10, 20, 13, 16),
|
padding:
|
const EdgeInsets.fromLTRB(10, 10, 10, 10),
|
decoration: BoxDecoration(
|
color: Color(0xFFFAFAFA),
|
borderRadius: BorderRadius.circular(13)),
|
child: GridView(
|
padding: EdgeInsets.zero,
|
gridDelegate:
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
crossAxisCount: 4, mainAxisSpacing: 10),
|
physics: const NeverScrollableScrollPhysics(),
|
children: [
|
functionWidget(
|
"assets/imgs/mine/ic_fun_invite.png",
|
"邀请好友",
|
28.5, () {
|
jumpPage("InviteFriendsPage");
|
}),
|
functionWidget(
|
"assets/imgs/mine/ic_fun_help.png",
|
"帮助中心",
|
27, () {
|
ConfigUtil.getConfig(context, "helpLink")
|
.then((value) {
|
jumpPage("BrowserPage",
|
params: {
|
"url": value,
|
"title": "帮助中心"
|
},
|
needLogin: false);
|
});
|
}),
|
functionWidget(
|
"assets/imgs/mine/ic_fun_kefu.png",
|
"在线客服",
|
28.5, () {
|
ConfigUtil.getConfig(context, "kefu")
|
.then((value) {
|
jumpPage("BrowserPage",
|
params: {"url": value, "title": "客服"},
|
needLogin: false);
|
});
|
}),
|
functionWidget(
|
"assets/imgs/mine/ic_fun_about_us.png",
|
"关于我们",
|
25, () {
|
// MySharedPreferences.getInstance()
|
// .getString("aboutUsLink")
|
// .then((value) {
|
// if (!StringUtil.isNullOrEmpty(value)) {
|
jumpPage("AboutUsPage", needLogin: false);
|
// }
|
// });
|
}),
|
functionWidget(
|
"assets/imgs/mine/ic_fun_settings.png",
|
"设置",
|
24.5, () {
|
jumpPage("SettingPage", needLogin: false);
|
}),
|
],
|
),
|
),
|
|
Container(
|
margin:
|
const EdgeInsets.only(left: 12, right: 12),
|
width: MediaQuery.of(context).size.width - 12 * 2,
|
height:
|
(MediaQuery.of(context).size.width - 12 * 2) *
|
0.6,
|
alignment: Alignment.center,
|
child: CSJEXpressAd(
|
"948486374",
|
MediaQuery.of(context).size.width - 12 * 2,
|
(MediaQuery.of(context).size.width - 12 * 2) *
|
0.6),
|
)
|
],
|
)),
|
Container(
|
margin: EdgeInsets.only(left: 25),
|
child: portraitWidget(),
|
)
|
],
|
)),
|
],
|
)),
|
]))
|
]));
|
}
|
|
Widget portraitWidget() {
|
return InkWell(
|
onTap: () {
|
if (_user != null) {
|
jumpPage("PersonInfoPage");
|
}
|
},
|
child: Container(
|
width: 81,
|
height: 81,
|
padding: const EdgeInsets.all(4),
|
alignment: Alignment.center,
|
decoration: BoxDecoration(
|
color: Colors.white, borderRadius: BorderRadius.circular(40)),
|
child: ClipRRect(
|
borderRadius: BorderRadius.circular(40),
|
child: _user == null
|
? Container(
|
color: COLOR_PORTRAIT_BG,
|
alignment: Alignment.center,
|
child: Image.asset(
|
"assets/imgs/mine/icon_no_login_portrait.png",
|
height: 39,
|
),
|
)
|
: CommonImage(
|
(_user == null || _user!.portrait == null)
|
? "assets/imgs/ic_portrait_default.png"
|
: _user!.portrait!,
|
defaultWidget:
|
Image.asset("assets/imgs/ic_portrait_default.png")),
|
)));
|
}
|
|
Widget loginBtnWidget() {
|
return MyFillButton("登录", 13, width: 230, fontSize: 15, height: 41,
|
onClick: () {
|
jumpPage("LoginPage", needLogin: false);
|
}, color: COLOR_HIGHLIGHT);
|
}
|
|
Widget personInfoWidget() {
|
print("用户信息:${_user!.toJson()}");
|
return Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Text(_user!.nickname!,
|
maxLines: 1,
|
overflow: TextOverflow.ellipsis,
|
style: const TextStyle(
|
fontSize: 21,
|
color: COLOR_TITLE,
|
)),
|
Container(
|
height: 6,
|
),
|
],
|
);
|
}
|
|
Widget userContent(int number, String content, VoidCallback click,
|
{color: COLOR_CONTENT}) {
|
return InkWell(
|
onTap: () {
|
click();
|
},
|
child: Column(
|
mainAxisAlignment: MainAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
Text(
|
"$number",
|
style: TextStyle(color: color, fontSize: 18),
|
),
|
Text(
|
content,
|
style: TextStyle(color: color, fontSize: 10),
|
)
|
],
|
));
|
}
|
|
Widget functionWidget(
|
String icon, String text, double width, GestureTapCallback click) {
|
return InkWell(
|
onTap: () {
|
click();
|
},
|
child: Container(
|
padding: const EdgeInsets.only(top: 15, bottom: 14),
|
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
Image.asset(
|
icon,
|
width: width,
|
),
|
Container(
|
height: 10,
|
),
|
Text(
|
text,
|
style: const TextStyle(color: COLOR_CONTENT, fontSize: 12),
|
)
|
],
|
)),
|
);
|
}
|
}
|