import 'package:flutter/Material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import '../resource/assets.gen.dart'; import '../resource/colors.gen.dart'; import '../utils/styles.dart'; class PermissionDialog { static void showRequestDialog( String titleTxt, Widget desc, String sureTxt, String permissionDesc, {Future Function()? sureClick}) { const tag = 'PermissionDialog'; 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, 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)), ), ), ), 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, ), ), ) ], )); }); } static Widget buildStorageView() { return RichText( textAlign: TextAlign.center, text: TextSpan( style: TextStyle(fontSize: 15.sp, color: ColorName.black80), children: const [ TextSpan( text: '使用该功能App需要访问您设备权限', ), TextSpan( text: '“照片和媒体”', style: TextStyle( fontWeight: FontWeight.bold, color: ColorName.black90)), TextSpan( text: ',开启权限后,您即可上传图片并体验相关服务。', ), ]), ); } }