import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; import 'package:star_lock/tools/storage.dart'; import '../versionUndate/versionUndateTool.dart'; class AppFirstEnterHandle { Future getAppFirstEnter(BuildContext widgetContext, String flagStr) async { var getFlag = await Storage.getString(flagStr); switch (flagStr) { case isAgreePrivacy: // 隐私协议 { if (getFlag != isAgreePrivacy) showPrivacyAgreementAlert(widgetContext); } break; case isAgreePosition: // 位置权限 { if (getFlag != isAgreePosition) showPositionAlert(widgetContext); } break; case isAgreeCamera: // 相机权限 { if (getFlag != isAgreeCamera) showCameraAlert(widgetContext); } break; case isShowUpdateVersion: // 版本更新 { if (getFlag != isShowUpdateVersion) VersionUndateTool(); } break; default: { print('没有匹配的flagStr'); } break; } } //隐私协议弹窗 void showPrivacyAgreementAlert(BuildContext widgetContext) { showCupertinoDialog( context: widgetContext, builder: (context) { return PopScope( canPop: false, child: CupertinoAlertDialog( title: const Text('用户协议和隐私政策概要\n'), content: Text.rich( TextSpan( text: '感谢您使用本应用。我们非常重视您的个人信息和隐私保护,在使用本产品之前,请认真阅读', style: const TextStyle(fontSize: 16.0), children: [ TextSpan( text: '《用户协议》', style: const TextStyle( color: Colors.blue, decoration: TextDecoration.underline), recognizer: TapGestureRecognizer() ..onTap = () { // 处理用户协议点击事件 Get.toNamed(Routers.webviewShowPage, arguments: { "url": XSConstantMacro.userAgreementURL, "title": '用户协议' }); }, ), const TextSpan(text: '和'), TextSpan( text: '《隐私政策》', style: const TextStyle( color: Colors.blue, decoration: TextDecoration.underline), recognizer: TapGestureRecognizer() ..onTap = () { // 处理隐私政策点击事件 Get.toNamed(Routers.webviewShowPage, arguments: { "url": XSConstantMacro.privacyPolicyURL, "title": '隐私政策' }); }, ), const TextSpan( text: '的全部内容。点击“同意”即表示您同意并接受全部条款。若选择不同意,将无法使用我们的产品和服务,并会退出应用。'), ], ), ), actions: [ CupertinoDialogAction( child: const Text( '不同意', style: TextStyle(color: Colors.black), ), onPressed: () { _exitApp(); }, ), CupertinoDialogAction( child: const Text( '同意', style: TextStyle(color: Colors.blue), ), onPressed: () { Storage.setString(isAgreePrivacy, isAgreePrivacy); Navigator.of(context).pop(); getAppFirstEnter(context, isShowUpdateVersion); }, ), ], )); }, ); } //位置权限弹窗 void showPositionAlert(BuildContext widgetContext) { showCupertinoDialog( context: widgetContext, builder: (context) { return PopScope( canPop: false, child: CupertinoAlertDialog( title: const Text('位置权限'), content: const Text('请开启位置权限,应用需要位置权限才可以完成智能锁和网关的蓝牙操作'), actions: [ CupertinoDialogAction( child: const Text('取消'), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( child: const Text('确定'), onPressed: () { Storage.setString(isAgreePosition, isAgreePosition); Navigator.of(context).pop(); }, ), ], )); }, ); } //相机权限弹窗 void showCameraAlert(BuildContext widgetContext) { showCupertinoDialog( context: widgetContext, builder: (context) { return PopScope( canPop: false, child: CupertinoAlertDialog( title: const Text('相机/相册权限'), content: const Text('请开启本地存储权限,允许应用读写设备上的照片及文件'), actions: [ CupertinoDialogAction( child: const Text('取消'), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( child: const Text('确定'), onPressed: () { Storage.setString(isAgreeCamera, isAgreeCamera); Navigator.of(context).pop(); }, ), ], )); }, ); } //微信公众号二维码弹窗 void showQRImageAlert(BuildContext widgetContext, String qrCodeUrl) { showCupertinoDialog( context: widgetContext, builder: (context) { return PopScope( canPop: false, child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.network( qrCodeUrl, width: 1.sw - 40.w, height: 1.sw - 40.w, ), SizedBox( height: 20.h, ), //点击屏幕任意位置关闭弹窗 GestureDetector( onTap: () { Navigator.of(context).pop(); }, child: Image.asset('images/icon_massSend_delete.png'), ), ], ))); }, ); } // _launchURL(String url) async { // if (await canLaunchUrl(Uri.parse(url))) { // await launchUrl(Uri.parse(url)); // } else { // throw '无法打开链接 $url'; // } // } void _exitApp() { exit(0); // 退出应用程序 } }