location_permission_dialog.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import 'dart:io';
  2. import 'package:flutter/material.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 'package:location/resource/assets.gen.dart';
  7. import 'package:location/resource/string.gen.dart';
  8. import 'package:location/utils/common_expand.dart';
  9. import '../utils/common_style.dart';
  10. class LocationPermissionDialog {
  11. static const String _tag = "LocationPermissionDialog";
  12. static void show({required VoidCallback onNextStep}) {
  13. SmartDialog.show(
  14. tag: _tag,
  15. builder: (_) {
  16. if (Platform.isAndroid) {
  17. return CupertinoLocationView(onNextStep: onNextStep);
  18. } else {
  19. return CupertinoLocationView(onNextStep: onNextStep);
  20. }
  21. });
  22. }
  23. static void dismiss() {
  24. SmartDialog.dismiss(tag: _tag);
  25. }
  26. }
  27. class AndroidLocationView extends Dialog {
  28. const AndroidLocationView({super.key});
  29. }
  30. class CupertinoLocationView extends Dialog {
  31. final VoidCallback onNextStep;
  32. const CupertinoLocationView({super.key, required this.onNextStep});
  33. @override
  34. Widget build(BuildContext context) {
  35. return IntrinsicHeight(
  36. child: Container(
  37. width: 300.w,
  38. decoration: BoxDecoration(
  39. color: Colors.white,
  40. borderRadius: BorderRadius.circular(10.w),
  41. ),
  42. child: Column(
  43. children: [
  44. AspectRatio(
  45. aspectRatio: 900 / 438,
  46. child: Assets.images.bgDialogLocationPermissionIos
  47. .image(width: double.infinity),
  48. ),
  49. SizedBox(height: 34.w),
  50. SizedBox(
  51. width: 210.w,
  52. child: RichText(
  53. textAlign: TextAlign.center,
  54. text: TextSpan(
  55. style: TextStyle(fontSize: 14.sp, color: '#404040'.color),
  56. children: [
  57. TextSpan(text: '为保位置展示在地图上,需要允许使用'),
  58. TextSpan(
  59. text: '位置权限',
  60. style: TextStyle(
  61. color: '#1448CC'.color,
  62. fontWeight: FontWeight.bold)),
  63. ]),
  64. ),
  65. ),
  66. SizedBox(height: 19.w),
  67. GestureDetector(
  68. onTap: () {
  69. LocationPermissionDialog.dismiss();
  70. onNextStep.call();
  71. },
  72. child: Container(
  73. width: 252.w,
  74. height: 36.w,
  75. decoration: getPrimaryBtnDecoration(46.w),
  76. child: Center(
  77. child: Text(StringName.nextStep,
  78. style: TextStyle(
  79. fontSize: 16.sp,
  80. color: Colors.white,
  81. fontWeight: FontWeight.bold)),
  82. ),
  83. ),
  84. ),
  85. SizedBox(height: 23.w),
  86. ],
  87. ),
  88. ),
  89. );
  90. }
  91. }
  92. class LocationAlwaysPermissionDialog {
  93. static const String _tag = "LocationAlwaysPermissionDialog";
  94. static void show({required VoidCallback onNextStep}) {
  95. SmartDialog.show(
  96. tag: _tag,
  97. alignment: Alignment.bottomCenter,
  98. builder: (_) {
  99. if (Platform.isAndroid) {
  100. return CupertinoLocationAlwaysView(onNextStep: onNextStep);
  101. } else {
  102. return CupertinoLocationAlwaysView(onNextStep: onNextStep);
  103. }
  104. });
  105. }
  106. static void dismiss() {
  107. SmartDialog.dismiss(tag: _tag);
  108. }
  109. }
  110. class CupertinoLocationAlwaysView extends Dialog {
  111. final VoidCallback onNextStep;
  112. final RxInt _currentPage = 0.obs;
  113. int get currentPage => _currentPage.value;
  114. final PageController pageController = PageController(initialPage: 0);
  115. final List<Widget> pageList = [
  116. Assets.images.imgDialogLocationAlwaysTip1.image(width: double.infinity),
  117. Assets.images.imgDialogLocationAlwaysTip2.image(width: double.infinity),
  118. Assets.images.imgDialogLocationAlwaysTip3.image(width: double.infinity),
  119. ];
  120. CupertinoLocationAlwaysView({super.key, required this.onNextStep});
  121. @override
  122. Widget build(BuildContext context) {
  123. return IntrinsicHeight(
  124. child: Container(
  125. width: double.infinity,
  126. decoration: BoxDecoration(
  127. color: Colors.white,
  128. borderRadius: BorderRadius.only(
  129. topLeft: Radius.circular(16.w),
  130. topRight: Radius.circular(16.w),
  131. ),
  132. ),
  133. child: Column(
  134. mainAxisAlignment: MainAxisAlignment.center,
  135. children: [
  136. SizedBox(height: 28.w),
  137. Container(
  138. margin: EdgeInsets.symmetric(horizontal: 16.w),
  139. child: RichText(
  140. text: TextSpan(
  141. style: TextStyle(fontSize: 20.sp, color: '#333333'.color),
  142. children: [
  143. TextSpan(
  144. text: '应用使用需开启',
  145. style: TextStyle(fontWeight: FontWeight.bold)),
  146. TextSpan(
  147. text: '精准位置',
  148. style: TextStyle(
  149. color: '#1448CC'.color,
  150. fontWeight: FontWeight.bold)),
  151. TextSpan(
  152. text: '权限',
  153. style: TextStyle(fontWeight: FontWeight.bold))
  154. ]),
  155. ),
  156. ),
  157. Text(StringName.locationBackgroundAlwaysDesc,
  158. style: TextStyle(fontSize: 14.sp, color: '#666666'.color)),
  159. SizedBox(height: 24.w),
  160. SizedBox(
  161. width: 304.w,
  162. height: 230.w,
  163. child: PageView(
  164. onPageChanged: (index) {
  165. _currentPage.value = index;
  166. },
  167. controller: pageController,
  168. children: pageList,
  169. ),
  170. ),
  171. SizedBox(height: 8.w),
  172. indicator(),
  173. SizedBox(height: 30.w),
  174. GestureDetector(
  175. onTap: () => onNextClick(),
  176. child: Container(
  177. decoration: getPrimaryBtnDecoration(46.w),
  178. width: 312.w,
  179. height: 44.w,
  180. child: Center(
  181. child: Text(StringName.nextStep,
  182. style: TextStyle(fontSize: 15.sp, color: Colors.white)),
  183. ),
  184. ),
  185. ),
  186. SizedBox(height: 28.w),
  187. ],
  188. ),
  189. ),
  190. );
  191. }
  192. Widget indicator() {
  193. return Obx(() {
  194. return Row(
  195. mainAxisAlignment: MainAxisAlignment.center,
  196. children: List.generate(pageList.length, (index) {
  197. return Container(
  198. margin: EdgeInsets.symmetric(horizontal: 3.w),
  199. width: 6.w,
  200. height: 6.w,
  201. decoration: BoxDecoration(
  202. color: currentPage == index ? '#A7A7A7'.color : '#E5E5E5'.color,
  203. shape: BoxShape.circle,
  204. ),
  205. );
  206. }),
  207. );
  208. });
  209. }
  210. void onNextClick() async {
  211. double? index = pageController.page;
  212. if (index == pageList.length - 1) {
  213. LocationAlwaysPermissionDialog.dismiss();
  214. onNextStep.call();
  215. return;
  216. }
  217. await pageController.nextPage(
  218. duration: const Duration(milliseconds: 300), curve: Curves.easeInOut);
  219. }
  220. }