permission_dialog.dart 4.7 KB

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