permission_dialog.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import 'package:flutter/Material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  5. import 'package:get/get.dart';
  6. import '../resource/assets.gen.dart';
  7. import '../resource/colors.gen.dart';
  8. import '../utils/styles.dart';
  9. class PermissionDialog {
  10. static void showRequestDialog(
  11. String titleTxt, Widget desc, String sureTxt, String permissionDesc,
  12. {Future<bool> Function()? sureClick}) {
  13. const tag = 'PermissionDialog';
  14. SmartDialog.show(
  15. tag: tag,
  16. alignment: const Alignment(0, 0),
  17. builder: (_) {
  18. return Container(
  19. width: 300.w,
  20. decoration: BoxDecoration(
  21. color: Colors.white,
  22. borderRadius: BorderRadius.circular(12),
  23. ),
  24. child: Stack(
  25. children: [
  26. Container(
  27. padding: EdgeInsets.symmetric(horizontal: 19.w),
  28. child: IntrinsicHeight(
  29. child: Column(
  30. children: [
  31. SizedBox(height: 20.h),
  32. Text(titleTxt,
  33. style: TextStyle(
  34. fontWeight: FontWeight.bold,
  35. fontSize: 18.sp,
  36. color: Colors.black)),
  37. SizedBox(height: 14.h),
  38. desc,
  39. SizedBox(height: 30.h),
  40. GestureDetector(
  41. onTap: () async {
  42. if (sureClick != null) {
  43. Get.snackbar(
  44. animationDuration: Duration(milliseconds: 0),
  45. '权限请求',
  46. permissionDesc,
  47. snackPosition: SnackPosition.TOP,
  48. backgroundColor:
  49. Colors.black.withOpacity(0.8),
  50. colorText: Colors.white,
  51. duration:
  52. null, // 设置 duration 为 null,使得 Snackbar 持久显示
  53. );
  54. bool shouldDismiss = await sureClick();
  55. // 显示一个Snackbar,提示用户权限请求的原因
  56. Get.closeAllSnackbars();
  57. if (shouldDismiss) {
  58. SmartDialog.dismiss(tag: tag);
  59. }
  60. // close snackbar
  61. }
  62. },
  63. child: Container(
  64. decoration: Styles.getActivateButtonDecoration(50.r),
  65. width: 130.w,
  66. height: 40.w,
  67. child: Center(
  68. child: Text(sureTxt,
  69. style: TextStyle(
  70. fontSize: 16.sp, color: Colors.white)),
  71. ),
  72. ),
  73. ),
  74. SizedBox(height: 24.h),
  75. ],
  76. ),
  77. ),
  78. ),
  79. Positioned(
  80. top: 17.w,
  81. right: 18.w,
  82. child: GestureDetector(
  83. onTap: () {
  84. SmartDialog.dismiss(tag: tag);
  85. },
  86. child: Assets.images.iconCustomDialogClose.image(
  87. width: 24.w,
  88. height: 24.w,
  89. ),
  90. ),
  91. )
  92. ],
  93. ));
  94. });
  95. }
  96. static Widget buildStorageView() {
  97. return RichText(
  98. textAlign: TextAlign.center,
  99. text: TextSpan(
  100. style: TextStyle(fontSize: 15.sp, color: ColorName.black80),
  101. children: const <TextSpan>[
  102. TextSpan(
  103. text: '使用该功能App需要访问您设备权限',
  104. ),
  105. TextSpan(
  106. text: '“照片和媒体”',
  107. style: TextStyle(
  108. fontWeight: FontWeight.bold, color: ColorName.black90)),
  109. TextSpan(
  110. text: ',开启权限后,您即可上传图片并体验相关服务。',
  111. ),
  112. ]),
  113. );
  114. }
  115. }