import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import '../../api/user_api.dart';
|
|
import '../../model/user/user_info.dart';
|
import '../../ui/common/browser.dart';
|
import '../../ui/mine/advice.dart';
|
import '../../ui/mine/login.dart';
|
import '../../ui/mine/settings.dart';
|
import '../../utils/config_util.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.dart';
|
|
void main() {
|
runApp(MyApp());
|
}
|
|
class MyApp extends StatelessWidget {
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return MaterialApp(
|
title: 'Flutter Demo',
|
theme: ThemeData(
|
// This is the theme of your application.
|
//
|
// Try running your application with "flutter run". You'll see the
|
// application has a blue toolbar. Then, without quitting the app, try
|
// changing the primarySwatch below to Colors.green and then invoke
|
// "hot reload" (press "r" in the console where you ran "flutter run",
|
// or simply save your changes to "hot reload" in a Flutter IDE).
|
// Notice that the counter didn't reset back to zero; the application
|
// is not restarted.
|
primaryColor: Color.fromARGB(255, 150, 150, 150)),
|
home: MinePage(title: ''),
|
);
|
}
|
}
|
|
class MinePage extends StatefulWidget {
|
MinePage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_MinePageState createState() => _MinePageState();
|
}
|
|
class _MinePageState extends State<MinePage>
|
with AutomaticKeepAliveClientMixin {
|
UserInfo? userInfo = null;
|
bool isLogin = false;
|
bool isVIP = false;
|
List<Widget> list = [];
|
Widget? adView;
|
bool adDeleted = false;
|
final List<Functions> data = [
|
Functions("assets/imgs/mine/icon_mine_permission.png", "权限设置",
|
"permission", false),
|
];
|
|
void _onClick(Functions function) async {
|
if (function.needLogin) {
|
bool login = await UserUtil.isLogin();
|
if (!login) {
|
NavigatorUtil.navigateToNextPage(context, LoginPage(title: ""), (data) {
|
_getUserInfo();
|
});
|
return;
|
}
|
}
|
|
String? uid = await UserUtil.getUid();
|
|
switch (function.key) {
|
case "kefu":
|
ConfigUtil.getConfig(context, ConfigKey.kefu).then((value) {
|
if (!StringUtil.isNullOrEmpty(value)) {
|
NavigatorUtil.navigateToNextPage(
|
context, BrowserPage(title: "在线客服", url: value!), (data) {});
|
}
|
});
|
break;
|
|
case "advice":
|
NavigatorUtil.navigateToNextPage(
|
context, AdvicePage(title: ""), (data) {});
|
break;
|
case "protocol":
|
NavigatorUtil.navigateToNextPage(
|
context,
|
BrowserPage(
|
title: "用户协议",
|
url: Constant.PROTOCOL_URL,
|
),
|
(data) {});
|
break;
|
case "privacy":
|
NavigatorUtil.navigateToNextPage(
|
context,
|
BrowserPage(
|
title: "隐私政策",
|
url: Constant.PRIVACY_URL,
|
),
|
(data) {});
|
break;
|
case "setting":
|
NavigatorUtil.navigateToNextPage(context, SettingPage(title: ""),
|
(data) {
|
_getUserInfo();
|
});
|
|
break;
|
}
|
}
|
|
@override
|
void initState() {
|
data.forEach((item) {
|
list.add(InkWell(
|
child: Column(
|
children: [
|
Image.asset(item.icon, height: 31),
|
Container(
|
child: Text(
|
item.name,
|
style: new TextStyle(color: ColorConstant.theme),
|
),
|
margin: const EdgeInsets.fromLTRB(0, 13, 0, 0))
|
],
|
),
|
onTap: () {
|
_onClick(item);
|
},
|
));
|
});
|
|
//获取用户信息
|
_getUserInfo();
|
|
super.initState();
|
}
|
|
void _login() {
|
NavigatorUtil.navigateToNextPage(context, LoginPage(title: ""), (data) {
|
_getUserInfo();
|
});
|
}
|
|
void _loadAd() async {
|
if (adView != null) {
|
return;
|
}
|
if (adDeleted) {
|
return;
|
}
|
|
// Widget? ad = AdUtil.loadExpress(
|
// await AdUtil.getAdInfo(context, AdPosition.mineExpress),
|
// MediaQuery.of(context).size.width - 20,
|
// 200, (success, msg) {
|
// adDeleted = true;
|
// setState(() {
|
// adView = null;
|
// });
|
// });
|
//
|
// setState(() {
|
// adView = ad;
|
// });
|
}
|
|
void _getUserInfo() async {
|
var user = await UserUtil.getUserInfo();
|
if (user == null) {
|
setState(() {
|
isLogin = false;
|
userInfo = null;
|
});
|
return;
|
}
|
setState(() {
|
isLogin = true;
|
userInfo = user;
|
});
|
|
Map<String, dynamic>? result =
|
await UserApiUtil.getUserInfo(context, user.id!);
|
var code = result!["code"];
|
if (code == 0) {
|
UserInfo user = UserInfo.fromJson(result["data"]);
|
//保存用户信息
|
UserUtil.setUserInfo(user);
|
setState(() {
|
userInfo = user;
|
if (userInfo != null &&
|
userInfo!.vipExpireTime != null &&
|
userInfo!.vipExpireTime! > DateTime.now().millisecondsSinceEpoch) {
|
isVIP = true;
|
} else {
|
isVIP = false;
|
}
|
});
|
} else if (code == 80001) {
|
//账号被封禁
|
setState(() {
|
isLogin = false;
|
});
|
ToastUtil.toast("账号已被封禁",context);
|
await UserUtil.logout();
|
} else if (code == 80002) {
|
//账号被删除
|
setState(() {
|
isLogin = false;
|
});
|
ToastUtil.toast("账号已被删除",context);
|
await UserUtil.logout();
|
}
|
}
|
|
Widget getLoginContentView() {
|
if (isLogin) {
|
return getUserInfoWidget();
|
} else {
|
return getLoginBtnWidget();
|
}
|
}
|
|
Widget getLoginBtnWidget() {
|
return Expanded(
|
child: InkWell(
|
onTap: () {
|
_login();
|
},
|
child: Container(
|
margin: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
height: 38,
|
alignment: Alignment.center,
|
child: const Text(
|
"登录/注册",
|
style: TextStyle(color: Colors.white, fontSize: 15),
|
),
|
decoration: const BoxDecoration(
|
color: Color(0xFF0E96FF),
|
borderRadius: BorderRadius.all(Radius.elliptical(10, 10))),
|
),
|
));
|
}
|
|
Widget getUserInfoWidget() {
|
return Container(
|
height: 50,
|
padding: EdgeInsets.zero,
|
margin: const EdgeInsets.fromLTRB(10, 0, 0, 0),
|
alignment: Alignment.topLeft,
|
child: Flex(
|
direction: Axis.vertical,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
children: [
|
Text(
|
userInfo!.nickname!,
|
style: const TextStyle(color: Color(0xFF40C7FF), fontSize: 18),
|
),
|
Text(
|
"ID:" + userInfo!.id!.toString(),
|
style: const TextStyle(color: Color(0xFF40C7FF), fontSize: 12),
|
),
|
],
|
),
|
);
|
}
|
|
Widget _getVIPLeftTime() {
|
List<TextSpan> spanList = [const TextSpan(text: '剩余')];
|
if (userInfo != null && userInfo!.vipExpireTime != null) {
|
int leftTime =
|
userInfo!.vipExpireTime! - DateTime.now().millisecondsSinceEpoch;
|
leftTime = leftTime ~/ 1000;
|
if (leftTime >= 60 * 60 * 24) {
|
spanList.add(TextSpan(
|
text: '${leftTime ~/ (60 * 60 * 24)}',
|
style: const TextStyle(fontWeight: FontWeight.bold)));
|
spanList.add(const TextSpan(text: '天到期'));
|
} else if (leftTime >= 60 * 60) {
|
spanList.add(TextSpan(
|
text: '${leftTime ~/ (60 * 60)}',
|
style: const TextStyle(fontWeight: FontWeight.bold)));
|
spanList.add(const TextSpan(text: '小时到期'));
|
} else {
|
spanList.add(TextSpan(
|
text: '${leftTime ~/ (60)}',
|
style: const TextStyle(fontWeight: FontWeight.bold)));
|
spanList.add(const TextSpan(text: '分钟到期'));
|
}
|
}
|
|
return Text.rich(TextSpan(
|
children: spanList,
|
style: const TextStyle(color: Colors.white, fontSize: 17.5),
|
));
|
}
|
|
List<Widget> getVIPContent() {
|
List<Widget> list = [];
|
list.add(Image.asset(
|
"assets/imgs/mine/icon_vip.png",
|
width: 44,
|
));
|
if (isVIP&&userInfo!=null) {
|
list.add(Container(
|
margin: const EdgeInsets.fromLTRB(6, 0, 0, 0),
|
child: _getVIPLeftTime()));
|
} else {
|
list.add(Container(
|
margin: const EdgeInsets.fromLTRB(6, 0, 0, 0),
|
child: Image.asset(
|
"assets/imgs/mine/label_vip.png",
|
height: 20,
|
),
|
));
|
}
|
return list;
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
_loadAd();
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: SingleChildScrollView(
|
child: Column(
|
children: [
|
Container(
|
decoration: const BoxDecoration(
|
image: DecorationImage(
|
image:
|
AssetImage("assets/imgs/mine/ic_mine_top_bg.png"),
|
fit: BoxFit.cover)),
|
height: 350,
|
width: 400,
|
padding: const EdgeInsets.all(10),
|
child: Column(
|
children: [
|
//登录与用户信息
|
Container(
|
margin: EdgeInsets.fromLTRB(0, 105, 0, 0),
|
padding: EdgeInsets.all(15),
|
alignment: Alignment.centerLeft,
|
child: Container(
|
height: 50,
|
child: Flex(
|
direction: Axis.horizontal,
|
children: [
|
Image.asset(
|
"assets/imgs/mine/icon_mine_default_portrait.png",
|
width: 50,
|
),
|
//登录按钮
|
getLoginContentView(),
|
//信息
|
],
|
)),
|
height: 105,
|
decoration: const BoxDecoration(
|
color: Colors.white,
|
borderRadius:
|
BorderRadius.all(Radius.elliptical(10, 10)))),
|
//会员
|
Container(
|
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
|
height: 105,
|
width: 400,
|
child: Stack(
|
children: [
|
Container(
|
padding: const EdgeInsets.fromLTRB(18.5, 0, 0, 0),
|
child: Flex(
|
direction: Axis.vertical,
|
mainAxisAlignment: MainAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Flex(
|
direction: Axis.horizontal,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: getVIPContent(),
|
),
|
Container(
|
margin: const EdgeInsets.fromLTRB(0, 8, 0, 0),
|
child: const Text(
|
"定位守护亲友,黑科技保驾护航",
|
style: TextStyle(
|
fontSize: 15, color: Colors.white),
|
),
|
)
|
],
|
),
|
),
|
Positioned(
|
right: 0,
|
top: 17,
|
child: InkWell(
|
onTap: () {
|
//查看详情或开通
|
print(isVIP ? "查看详情" : "开通会员");
|
UserUtil.isLogin().then((value) {
|
if (!value) {
|
NavigatorUtil.navigateToNextPage(
|
context, LoginPage(title: ""),
|
(data) {
|
_getUserInfo();
|
});
|
}
|
});
|
},
|
child: InkWell(
|
onTap: () {
|
UserUtil.isLogin().then((value) {
|
if (!value) {
|
NavigatorUtil.navigateToNextPage(
|
context, LoginPage(title: ""),
|
(data) {
|
_getUserInfo();
|
});
|
return;
|
}
|
|
ConfigUtil.getConfig(context,
|
ConfigKey.vipLink)
|
.then((value) {
|
if (!StringUtil.isNullOrEmpty(
|
value)) {
|
NavigatorUtil.navigateToNextPage(
|
context,
|
BrowserPage(
|
title: "会员",
|
url: value!), (data) {
|
_getUserInfo();
|
});
|
}
|
});
|
});
|
},
|
child: Container(
|
width: 99,
|
height: 26,
|
alignment: Alignment.center,
|
child: Text(
|
isVIP ? "查看详情" : "立即开通",
|
style: const TextStyle(
|
color: Color(0xFFD4A880)),
|
),
|
decoration: const BoxDecoration(
|
color: Color(0xFFFAEAB9),
|
borderRadius: BorderRadius.only(
|
topLeft: Radius.circular(13),
|
bottomLeft:
|
Radius.circular(13)),
|
boxShadow: [
|
BoxShadow(
|
color: Color(0x4D0E96FF),
|
blurRadius: 2.0,
|
offset: Offset(0.0, 3.0),
|
//阴影y轴偏移量
|
spreadRadius: 0 //阴影扩散程度
|
)
|
],
|
)))))
|
],
|
),
|
decoration: const BoxDecoration(
|
boxShadow: [
|
BoxShadow(
|
color: Color(0x4D0E96FF),
|
blurRadius: 5.0,
|
offset: Offset(0.0, 8.0), //阴影y轴偏移量
|
spreadRadius: 0 //阴影扩散程度
|
)
|
],
|
gradient: LinearGradient(
|
stops: [.5, 1],
|
colors: [Color(0xFF4699FF), Color(0xFF00DEFF)]),
|
color: Colors.white,
|
borderRadius:
|
BorderRadius.all(Radius.elliptical(10, 10))))
|
],
|
),
|
),
|
|
Container(
|
child: adView ?? Container(),
|
margin: EdgeInsets.only(left: 10, right: 10),
|
),
|
//广告
|
|
//功能区域
|
Container(
|
height: 340,
|
margin: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
decoration: const BoxDecoration(
|
borderRadius: BorderRadius.all(Radius.elliptical(10, 10)),
|
color: Color(0xFFF4FFFF)),
|
child: GridView(
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
crossAxisCount: 4, mainAxisSpacing: 10),
|
physics: const NeverScrollableScrollPhysics(),
|
children: list),
|
),
|
],
|
)));
|
}
|
|
@override
|
bool get wantKeepAlive => true;
|
}
|
|
class Functions {
|
Functions(this.icon, this.name, this.key, this.needLogin);
|
|
String icon;
|
String name;
|
String key;
|
bool needLogin;
|
}
|