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.

387 lines
12 KiB

2 years ago
import 'package:bot_toast/bot_toast.dart';
import 'package:flustars/flustars.dart';
2 years ago
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2 years ago
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:permission_handler/permission_handler.dart';
2 years ago
import 'package:project_telephony/base/base_style.dart';
2 years ago
import 'package:project_telephony/ui/login/login_page.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:project_telephony/ui/user/content_authority_page.dart';
2 years ago
import 'package:project_telephony/ui/user/members_page.dart';
2 years ago
import 'package:project_telephony/ui/user/privacy_rights_page.dart';
2 years ago
import 'package:project_telephony/ui/widget/image_scaffold.dart';
import 'package:project_telephony/ui/widget/plone_bottom.dart';
import 'package:project_telephony/utils/headers.dart';
2 years ago
import 'package:provider/provider.dart';
2 years ago
import 'package:shared_preferences/shared_preferences.dart';
2 years ago
import 'package:telephony/telephony.dart';
2 years ago
import '../../constants/api.dart';
import '../../model/network/api_client.dart';
import '../../providers/user_provider.dart';
2 years ago
import '../../utils/hive_store.dart';
2 years ago
import '../../utils/toast/cloud_toast.dart';
import '../../utils/user_tool.dart';
2 years ago
import '../home/call.dart';
import 'content_details_page.dart';
2 years ago
2 years ago
import '../home/home_page.dart';
2 years ago
2 years ago
class UserPage extends StatefulWidget {
const UserPage({Key? key}) : super(key: key);
@override
_UserPageState createState() => _UserPageState();
}
2 years ago
final Telephony telephony = Telephony.instance;
2 years ago
class _UserPageState extends State<UserPage> {
// bool vle = PermissionStatus.denied.isGranted;
//bool vle =PermissionStatus.denied.isGranted;
2 years ago
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
2 years ago
2 years ago
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
bool isVip = false;
String? endDate;
2 years ago
late bool vle;
@override
void initState() {
super.initState();
2 years ago
if ( UserTool.userProvider.isLogin) {
2 years ago
if (UserTool.userProvider.userInfo.end<=DateTime.now().millisecondsSinceEpoch ) {
isVip = false;
2 years ago
vle =false;
2 years ago
} else {
2 years ago
vle =true;
2 years ago
isVip = true;
}
2 years ago
endDate=DateUtil.formatDateMs(UserTool.userProvider.userInfo.end * 1000, format: DateFormats.y_mo_d);
2 years ago
}else{
vle = false;
}
}
2 years ago
@override
Widget build(BuildContext context) {
return CloudScaffold(
2 years ago
2 years ago
systemStyle: const SystemUiOverlayStyle(
statusBarIconBrightness: Brightness.dark,
// systemNavigationBarColor: Colors.white,
),
path: Assets.images.bg.path,
bodyColor: Colors.white,
extendBody: true,
2 years ago
2 years ago
body: Column(children: [
_getUser(),
2 years ago
72.hb,
2 years ago
_getBanner(),
120.hb,
2 years ago
_getSwitch2(),
2 years ago
_getSwitch(Assets.icons.privacy.path, "隐私政策", false),
_getSwitch(Assets.icons.permissions.path, "权限说明", false),
_getSwitch(Assets.icons.sms.path, "短信标签", false),
2 years ago
// const Spacer(),
2 years ago
182.hb,
2 years ago
UserTool. userProvider.isLogin
2 years ago
? PloneBottom(
border: false,
onTap: () async {
2 years ago
var cancel = CloudToast.loading;
var base = await apiClient.request(API.app.logout,
showMessage: true);
2 years ago
if (base.code == 0) {
UserTool.userProvider.logout();
Get.offAll(const TabNavigator());
2 years ago
}
cancel();
},
textColor: const Color(0xFF1890FF),
color1: const Color(0xFFEBF5FF),
color2: const Color(0xFFEBF5FF),
text: "退出登录",
)
: const SizedBox()
2 years ago
]),
);
}
//头像
_getUser() {
2 years ago
return Container(
margin: EdgeInsets.only(left: 64.w, right: 64.w, top: 216.w),
child: Row(
children: [
GestureDetector(
onTap: () {
2 years ago
if(!userProvider.isLogin){
Get.to(() => const LoginPage());
}
2 years ago
},
child: Column(
2 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2 years ago
UserTool.userProvider.isLogin ?UserTool.userProvider.userInfo.name : "登录/注册",
// UserTool.userProvider.userInfo.name ,
2 years ago
style: TextStyle(
fontSize: BaseStyle.fontSize48,
color: BaseStyle.color333333,
fontWeight: FontWeight.bold),
),
24.hb,
Text(
2 years ago
UserTool.userProvider.isLogin ? "欢迎您登录短信帮手" : "登录获取更多信息",
2 years ago
style: TextStyle(
fontSize: BaseStyle.fontSize28,
color: BaseStyle.color333333),
)
],
2 years ago
),
2 years ago
),
const Spacer(),
GestureDetector(
onTap: () async {
// var value = await CloudImagePicker.pickSingleImage(title: '选择图片');
// if (value != null) {
// BotToast.showText(text: '头像成功');
// setState(() {});
// }//暂时不开放头像更改
2 years ago
},
child: ClipOval(
child: Image.asset(
2 years ago
UserTool.userProvider.isLogin?Assets.images.portraitDeep.path:Assets.images.portrait.path,
2 years ago
height: 128.w,
width: 128.w,
fit: BoxFit.cover,
2 years ago
),
2 years ago
),
)
],
2 years ago
),
);
}
//banner
_getBanner() {
return SizedBox(
// margin: EdgeInsets.symmetric(horizontal: 32.w),
height: 144.w,
child: Stack(children: [
Align(
child: SizedBox(
2 years ago
width: 622.w,
2 years ago
child: Image.asset(
Assets.images.banner.path,
fit: BoxFit.fill,
),
)),
Positioned(
child: Container(
2 years ago
padding: EdgeInsets.symmetric(horizontal: 112.w, vertical: 24.w),
// margin: EdgeInsets.symmetric(horizontal: 64.w, vertical: 16.w),
// padding: EdgeInsets.symmetric(),
2 years ago
child: Row(
children: [_getText(), const Spacer(), _getBotton()],
),
))
]),
);
}
//banner botton
_getBotton() {
return GestureDetector(
onTap: () {
2 years ago
if(userProvider.isLogin){
Get.to(() => const MembersPage());
}else{
BotToast.showText(text: '您还未登录,请先登录!');
}
2 years ago
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 16.w),
decoration: BoxDecoration(
2 years ago
borderRadius: BorderRadius.circular(30.w),
2 years ago
gradient: const LinearGradient(
colors: [Color(0xFFFFF6D8), Color(0xFFFFEAB0)],
begin: Alignment.centerLeft,
end: Alignment.centerRight)),
child: Text(
isVip ? "立即续费" : "立即购买",
2 years ago
style: TextStyle(
color: const Color(0xFF001F3F), fontSize: BaseStyle.fontSize24),
)),
);
}
//banner 文字
_getText() {
return Column(
2 years ago
crossAxisAlignment: CrossAxisAlignment.start,
2 years ago
children: [
_getVip(),
16.hb,
Text(
isVip ? "$endDate到期" : "解锁全部功能",
2 years ago
style: TextStyle(color: Colors.white, fontSize: BaseStyle.fontSize24),
)
],
);
}
_getVip() {
return Row(
children: [
2 years ago
Text(
"VIP",
style: TextStyle(
color: const Color(0xFFFFEAB0),
fontFamily: "BlackItalic",
fontSize: 32.sp),
2 years ago
),
Container(
width: 8.w,
height: 8.w,
2 years ago
alignment: Alignment.center,
margin: EdgeInsets.symmetric(horizontal: 8.w),
2 years ago
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: const Color(0xFFFFEAB0),
),
),
Text(
isVip ? "已成为会员" : "未开通会员",
style: const TextStyle(
2 years ago
color: Color(
0xFFFFEAB0,
),
fontWeight: FontWeight.w700),
2 years ago
)
],
);
}
//内容
2 years ago
_getSwitch2(){
return Container(
padding: EdgeInsets.symmetric(horizontal: 32.w),
child: ListTile(
// onTap: (() {}),
leading: Image.asset(
Assets.icons.switch1.path,
height: 54.w,
width: 56.w,
fit: BoxFit.fill,
),
title: Text(
"功能开关",
style: TextStyle(
color: BaseStyle.color333333,
fontSize: BaseStyle.fontSize34,
fontWeight: FontWeight.bold),
),
trailing: Switch(
value: vle,
onChanged: (value) async {
2 years ago
final service = FlutterBackgroundService();
var isRunning = await service.isRunning();
2 years ago
final SharedPreferences prefs = await _prefs;
2 years ago
// if(!value){
//
// }
// await prefs.setBool("kg", value);
// print("这是数据${prefs.getBool("kg")}");
2 years ago
setState(() {
if(!isVip){
vle=value;
2 years ago
// prefs.setBool("kg", vle);
// initializeService();
2 years ago
if(vle){
print("true");
2 years ago
prefs.remove("kg");
prefs.setBool("kg", vle);
service.startService();
// WidgetsFlutterBinding.ensureInitialized();
// initializeService();
// UserTool.userProvider.setKg(vle)
// initializeService();
// initializeService();
2 years ago
BotToast.showText(text: " 你开启了该功能");
2 years ago
// initializeService();
2 years ago
// print("这是数据${prefs.getBool("kg")}");
}else{
print("false");
2 years ago
prefs.remove("kg");
prefs.setBool("kg", vle);
service.invoke("stopService");
// exit(0);
// UserTool.userProvider.setKg(vle);
// prefs.setBool("kg", false);
// initializeService();
2 years ago
BotToast.showText(text: "你已经关闭该功能");
// print("这是数据${prefs.getBool("kg")}");
}
}else{
BotToast.showText(text: "还没有开通会员,不可使用改功能");
}
});
}),
));
}
2 years ago
_getSwitch(String url, String name, bool pd) {
2 years ago
return GestureDetector(
2 years ago
onTap: () async {
if (!pd) {
switch (name) {
case "短信标签":
Get.to(() => ContentDetailsPage(
content:
2 years ago
UserTool.userProvider.isLogin ? UserTool.userProvider.userInfo.tag : "",
ploneBack: (String textContent) {
// print("这是数据" + textContent);
// textList.setAll(index, {textContent});
},
));
break;
case "隐私政策":
Get.to(() => const ContentAuthorityPage());
break;
case "权限说明":
Get.to(() => PrivacyRightsPage(
name: name,
));
break;
default:
break;
}
}
2 years ago
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 32.w),
child: ListTile(
// onTap: (() {}),
leading: Image.asset(
url,
height: 54.w,
width: 56.w,
fit: BoxFit.fill,
),
title: Text(
name,
style: TextStyle(
color: BaseStyle.color333333,
fontSize: BaseStyle.fontSize34,
fontWeight: FontWeight.bold),
),
2 years ago
trailing:const Icon(Icons.keyboard_arrow_right)),
2 years ago
),
);
2 years ago
}
}