location_permission_dialog.dart 7.4 KB

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