|
|
@@ -1,3 +1,5 @@
|
|
|
+import 'dart:async';
|
|
|
+
|
|
|
import 'package:flutter/Material.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
@@ -8,113 +10,136 @@ import '../resource/colors.gen.dart';
|
|
|
import '../utils/styles.dart';
|
|
|
|
|
|
class PermissionDialog {
|
|
|
- static void showRequestDialog(
|
|
|
- String titleTxt, Widget desc, String sureTxt, String permissionDesc,
|
|
|
- {Future<bool> Function()? sureClick}) {
|
|
|
+ static Future<bool> showRequestDialog(
|
|
|
+ String titleTxt,
|
|
|
+ Widget desc,
|
|
|
+ String sureTxt,
|
|
|
+ String permissionDesc, {
|
|
|
+ Future<bool> Function()? sureClick,
|
|
|
+
|
|
|
+ }) async {
|
|
|
const tag = 'PermissionDialog';
|
|
|
+ final completer = Completer<bool>();
|
|
|
+
|
|
|
SmartDialog.show(
|
|
|
- tag: tag,
|
|
|
- alignment: const Alignment(0, 0),
|
|
|
- builder: (_) {
|
|
|
- return Container(
|
|
|
- width: 300.w,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: Colors.white,
|
|
|
- borderRadius: BorderRadius.circular(12),
|
|
|
- ),
|
|
|
- child: Stack(
|
|
|
- children: [
|
|
|
- Container(
|
|
|
- padding: EdgeInsets.symmetric(horizontal: 19.w),
|
|
|
- child: IntrinsicHeight(
|
|
|
- child: Column(
|
|
|
- children: [
|
|
|
- SizedBox(height: 20.h),
|
|
|
- Text(titleTxt,
|
|
|
+ tag: tag,
|
|
|
+ alignment: const Alignment(0, 0),
|
|
|
+ builder: (_) {
|
|
|
+ return Container(
|
|
|
+ width: 300.w,
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: Colors.white,
|
|
|
+ borderRadius: BorderRadius.circular(12),
|
|
|
+ ),
|
|
|
+ child: Stack(
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 19.w),
|
|
|
+ child: IntrinsicHeight(
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ SizedBox(height: 20.h),
|
|
|
+ Text(
|
|
|
+ titleTxt,
|
|
|
+ style: TextStyle(
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ fontSize: 18.sp,
|
|
|
+ color: Colors.black,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ SizedBox(height: 14.h),
|
|
|
+ desc,
|
|
|
+ SizedBox(height: 30.h),
|
|
|
+ GestureDetector(
|
|
|
+ onTap: () async {
|
|
|
+ if (sureClick != null) {
|
|
|
+ // 显示权限说明
|
|
|
+ Get.snackbar(
|
|
|
+ '权限请求',
|
|
|
+ permissionDesc,
|
|
|
+ animationDuration: Duration(milliseconds: 0),
|
|
|
+ snackPosition: SnackPosition.TOP,
|
|
|
+ backgroundColor: Colors.black.withOpacity(0.8),
|
|
|
+ colorText: Colors.white,
|
|
|
+ duration: null,
|
|
|
+ );
|
|
|
+ // 权限请求逻辑
|
|
|
+ bool shouldDismiss = await sureClick();
|
|
|
+
|
|
|
+ Get.closeAllSnackbars();
|
|
|
+
|
|
|
+ if (shouldDismiss) {
|
|
|
+ SmartDialog.dismiss(tag: tag);
|
|
|
+ completer.complete(true);
|
|
|
+ } else {
|
|
|
+ // 保持弹窗,等待用户操作
|
|
|
+ completer.complete(false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SmartDialog.dismiss(tag: tag);
|
|
|
+ completer.complete(true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ child: Container(
|
|
|
+ decoration: Styles.getActivateButtonDecoration(50.r),
|
|
|
+ width: 130.w,
|
|
|
+ height: 40.w,
|
|
|
+ child: Center(
|
|
|
+ child: Text(
|
|
|
+ sureTxt,
|
|
|
style: TextStyle(
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
- fontSize: 18.sp,
|
|
|
- color: Colors.black)),
|
|
|
- SizedBox(height: 14.h),
|
|
|
- desc,
|
|
|
- SizedBox(height: 30.h),
|
|
|
- GestureDetector(
|
|
|
- onTap: () async {
|
|
|
- if (sureClick != null) {
|
|
|
- Get.snackbar(
|
|
|
- animationDuration: Duration(milliseconds: 0),
|
|
|
- '权限请求',
|
|
|
- permissionDesc,
|
|
|
- snackPosition: SnackPosition.TOP,
|
|
|
- backgroundColor:
|
|
|
- Colors.black.withOpacity(0.8),
|
|
|
- colorText: Colors.white,
|
|
|
- duration:
|
|
|
- null, // 设置 duration 为 null,使得 Snackbar 持久显示
|
|
|
- );
|
|
|
- bool shouldDismiss = await sureClick();
|
|
|
- // 显示一个Snackbar,提示用户权限请求的原因
|
|
|
- Get.closeAllSnackbars();
|
|
|
- if (shouldDismiss) {
|
|
|
- SmartDialog.dismiss(tag: tag);
|
|
|
- }
|
|
|
- // close snackbar
|
|
|
- }
|
|
|
- },
|
|
|
- child: Container(
|
|
|
- decoration: Styles.getActivateButtonDecoration(50.r),
|
|
|
- width: 130.w,
|
|
|
- height: 40.w,
|
|
|
- child: Center(
|
|
|
- child: Text(sureTxt,
|
|
|
- style: TextStyle(
|
|
|
- fontSize: 16.sp, color: Colors.white)),
|
|
|
+ fontSize: 16.sp,
|
|
|
+ color: Colors.white,
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
- SizedBox(height: 24.h),
|
|
|
- ],
|
|
|
+ ),
|
|
|
),
|
|
|
- ),
|
|
|
+ SizedBox(height: 24.h),
|
|
|
+ ],
|
|
|
),
|
|
|
- Positioned(
|
|
|
- top: 17.w,
|
|
|
- right: 18.w,
|
|
|
- child: GestureDetector(
|
|
|
- onTap: () {
|
|
|
- SmartDialog.dismiss(tag: tag);
|
|
|
- },
|
|
|
- child: Assets.images.iconCustomDialogClose.image(
|
|
|
- width: 24.w,
|
|
|
- height: 24.w,
|
|
|
- ),
|
|
|
- ),
|
|
|
- )
|
|
|
- ],
|
|
|
- ));
|
|
|
- });
|
|
|
- }
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Positioned(
|
|
|
+ top: 17.w,
|
|
|
+ right: 18.w,
|
|
|
+ child: GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ SmartDialog.dismiss(tag: tag);
|
|
|
+ completer.complete(false); // 用户主动关闭
|
|
|
+ },
|
|
|
+ child: Assets.images.iconCustomDialogClose.image(
|
|
|
+ width: 24.w,
|
|
|
+ height: 24.w,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ );
|
|
|
|
|
|
+ return completer.future;
|
|
|
+ }
|
|
|
|
|
|
static Widget buildStorageView() {
|
|
|
return RichText(
|
|
|
textAlign: TextAlign.center,
|
|
|
text: TextSpan(
|
|
|
- style: TextStyle(fontSize: 15.sp, color: ColorName.black80),
|
|
|
- children: const <TextSpan>[
|
|
|
- TextSpan(
|
|
|
- text: '使用该功能App需要访问您设备权限',
|
|
|
- ),
|
|
|
- TextSpan(
|
|
|
- text: '“照片和媒体”',
|
|
|
- style: TextStyle(
|
|
|
- fontWeight: FontWeight.bold, color: ColorName.black90)),
|
|
|
- TextSpan(
|
|
|
- text: ',开启权限后,您即可上传图片并体验相关服务。',
|
|
|
+ style: TextStyle(fontSize: 15.sp, color: ColorName.black80),
|
|
|
+ children: const <TextSpan>[
|
|
|
+ TextSpan(text: '使用该功能App需要访问您设备权限'),
|
|
|
+ TextSpan(
|
|
|
+ text: '“照片和媒体”',
|
|
|
+ style: TextStyle(
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ color: ColorName.black90,
|
|
|
),
|
|
|
- ]),
|
|
|
+ ),
|
|
|
+ TextSpan(text: ',开启权限后,您即可上传图片并体验相关服务。'),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|