location_permission_dialog.dart 7.3 KB

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