app-starlock/lib/tools/appFirstEnterHandle.dart
2025-01-08 08:50:55 +08:00

279 lines
9.3 KiB
Dart
Executable File

import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart';
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/login/login/app_get_version.dart';
import 'package:star_lock/login/login/starLock_login_logic.dart';
import 'package:star_lock/main.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/tools/storage.dart';
import 'package:star_lock/tools/wechat/customer_tool.dart';
import '../versionUndate/versionUndateTool.dart';
class AppFirstEnterHandle {
Future<void> getAppFirstEnter(String flagStr) async {
final dynamic getFlag = await Storage.getString(flagStr);
switch (flagStr) {
case isAgreePrivacy: // 隐私协议
if (getFlag != isAgreePrivacy) {
final bool? isAgree = await showPrivacyAgreementAlert();
if (isAgree ?? false) {
await privacySDKInitialization();
}
}
if (Get.isRegistered<StarLockLoginLogic>()) {
Get.find<StarLockLoginLogic>().flushedDeviceInfo();
}
break;
case isAgreePosition: // 位置权限
if (getFlag != isAgreePosition) {
showPositionAlert();
}
break;
case isAgreeCamera: // 相机权限
if (getFlag != isAgreeCamera) {
showCameraAlert();
}
break;
case isShowUpdateVersion: // 版本更新
if (getFlag != isShowUpdateVersion) {
VersionUndateTool();
}
break;
default:
break;
}
}
//隐私协议弹窗
Future<bool?> showPrivacyAgreementAlert() async {
return await showCupertinoDialog(
context: Get.context!,
builder: (BuildContext context) {
return PopScope(
canPop: false,
child: F.sw(
skyCall: () => _defaultPrivacyAgreementAlert(context),
xhjCall: () => _xhjPrivacyAgreementAlert(context)));
},
);
}
//默认布局
Widget _defaultPrivacyAgreementAlert(BuildContext context) {
return CupertinoAlertDialog(
title: Text('${'用户协议和隐私政策概要'.tr}\n'),
content: Text.rich(
TextSpan(
text: '感谢您使用本应用。我们非常重视您的个人信息和隐私保护,在使用本产品之前,请认真阅读'.tr,
style: const TextStyle(fontSize: 16.0),
children: <InlineSpan>[
TextSpan(
text: '《用户协议》'.tr,
style: const TextStyle(
color: Colors.blue, decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
// 处理用户协议点击事件
Get.toNamed(Routers.webviewShowPage,
arguments: <String, String>{
'url': XSConstantMacro.userAgreementURL,
'title': '用户协议'.tr
});
},
),
TextSpan(text: ''.tr),
TextSpan(
text: '《隐私政策》'.tr,
style: const TextStyle(
color: Colors.blue, decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
// 处理隐私政策点击事件
Get.toNamed(Routers.webviewShowPage,
arguments: <String, String>{
'url': XSConstantMacro.privacyPolicyURL,
'title': '隐私政策'.tr
});
},
),
TextSpan(
text: '的全部内容。点击“同意”即表示您同意并接受全部条款。若选择不同意,将无法使用我们的产品和服务,并会退出应用。'
.tr),
],
),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text(
'不同意'.tr,
style: const TextStyle(color: Colors.black),
),
onPressed: _exitApp,
),
CupertinoDialogAction(
child: Text(
'同意'.tr,
style: const TextStyle(color: Colors.blue),
),
onPressed: () {
Storage.setString(isAgreePrivacy, isAgreePrivacy);
Navigator.of(context).pop(true);
getAppFirstEnter(isShowUpdateVersion);
},
),
],
);
}
//xhj 布局
Widget _xhjPrivacyAgreementAlert(BuildContext context) {
return AlertDialog(
title: Text('协议概要'.tr),
backgroundColor: Colors.white,
content: Text.rich(
TextSpan(
text: '感谢您使用本应用。我们非常重视您的个人信息和隐私保护,在使用本产品之前,请认真阅读'.tr,
style: const TextStyle(fontSize: 16.0),
children: <InlineSpan>[
TextSpan(
text: '《用户协议》'.tr,
style: TextStyle(
color: AppColors.mainColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
// 处理用户协议点击事件
Get.toNamed(Routers.webviewShowPage,
arguments: <String, String>{
'url': XSConstantMacro.userAgreementURL,
'title': '用户协议'.tr
});
},
),
TextSpan(text: ''.tr),
TextSpan(
text: '《隐私政策》'.tr,
style: TextStyle(
color: AppColors.mainColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
// 处理隐私政策点击事件
Get.toNamed(Routers.webviewShowPage,
arguments: <String, String>{
'url': XSConstantMacro.privacyPolicyURL,
'title': '隐私政策'.tr
});
},
),
TextSpan(
text: '的全部内容。点击“同意”即表示您同意并接受全部条款。若选择不同意,将无法使用我们的产品和服务,并会退出应用。'
.tr),
],
),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text(
'不同意'.tr,
style: const TextStyle(color: Colors.black),
),
onPressed: _exitApp,
),
CupertinoDialogAction(
child: Text(
'同意'.tr,
style: TextStyle(color: AppColors.mainColor),
),
onPressed: () {
Storage.setString(isAgreePrivacy, isAgreePrivacy);
Navigator.of(context).pop(true);
getAppFirstEnter(isShowUpdateVersion);
},
),
],
);
}
//位置权限弹窗
void showPositionAlert() {
showCupertinoDialog(
context: Get.context!,
builder: (BuildContext context) {
return PopScope(
canPop: false,
child: CupertinoAlertDialog(
title: Text('位置权限'.tr),
content: Text('请开启位置权限,应用需要位置权限才可以完成智能锁和网关的蓝牙操作'.tr),
actions: <Widget>[
CupertinoDialogAction(
child: Text('取消'.tr),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text('确定'.tr),
onPressed: () {
Storage.setString(isAgreePosition, isAgreePosition);
Navigator.of(context).pop();
},
),
],
));
},
);
}
//相机权限弹窗
void showCameraAlert() {
showCupertinoDialog(
context: Get.context!,
builder: (BuildContext context) {
return PopScope(
canPop: false,
child: CupertinoAlertDialog(
title: Text('相机/相册权限'.tr),
content: Text('请开启本地存储权限,允许应用读写设备上的照片及文件'.tr),
actions: <Widget>[
CupertinoDialogAction(
child: Text('取消'.tr),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text('确定'.tr),
onPressed: () {
Storage.setString(isAgreeCamera, isAgreeCamera);
Navigator.of(context).pop();
},
),
],
));
},
);
}
// _launchURL(String url) async {
// if (await canLaunchUrl(Uri.parse(url))) {
// await launchUrl(Uri.parse(url));
// } else {
// throw '无法打开链接 $url';
// }
// }
void _exitApp() {
exit(0); // 退出应用程序
}
}