check.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import 'dart:async';
  2. import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
  3. import 'package:amap_location_flutter_plugin/amap_location_option.dart';
  4. import 'package:amap_map_fluttify/amap_map_fluttify.dart';
  5. // import 'package:flustars/flustars.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:liftmanager/internal/sign/model/sign_config_item.dart';
  9. import 'package:liftmanager/internal/sign/model/sign_list_entity.dart';
  10. import 'package:liftmanager/internal/sign/sign_router.dart';
  11. import 'package:liftmanager/res/resources.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/toast.dart';
  14. import 'package:liftmanager/widgets/app_bar.dart';
  15. import 'package:permission_handler/permission_handler.dart';
  16. class ExpertCheckPage extends StatefulWidget {
  17. Function(double lat, double lon, String address) backFun;
  18. ExpertCheckPage({this.backFun});
  19. @override
  20. State<StatefulWidget> createState() {
  21. return ExpertCheckPageState();
  22. }
  23. }
  24. class ExpertCheckPageState extends State<ExpertCheckPage> {
  25. Map<String, Object> _locationResult;
  26. StreamSubscription<Map<String, Object>> _locationListener;
  27. AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
  28. // 计时器。
  29. // Timer _timer;
  30. // String _nowTimeStr = "";
  31. LatLng latLng = LatLng(0, 0);
  32. String currentAddress = "";
  33. SignConfigItem configItem = SignConfigItem();
  34. List<SignListItem> list = [];
  35. BuildContext mContext;
  36. AmapController _controller;
  37. @override
  38. void initState() {
  39. super.initState();
  40. _locationListener = _locationPlugin
  41. .onLocationChanged()
  42. .listen((Map<String, Object> result) {
  43. setState(() {
  44. _locationPlugin.stopLocation();
  45. _locationResult = result;
  46. // address latitude longitude
  47. _locationResult.forEach((key, value) {
  48. if (key == 'address') {
  49. currentAddress = '$value';
  50. setState(() {});
  51. } else if (key == 'latitude') {
  52. latLng.latitude = double.parse('$value');
  53. setState(() {});
  54. } else if (key == 'longitude') {
  55. latLng.longitude = double.parse('$value');
  56. setState(() {});
  57. }
  58. print(111);
  59. print('key:$key :');
  60. print('value:$value :');
  61. });
  62. });
  63. });
  64. mContext = context;
  65. getLocation();
  66. }
  67. void _setLocationOption() {
  68. if (null != _locationPlugin) {
  69. AMapLocationOption locationOption = new AMapLocationOption();
  70. ///是否单次定位
  71. locationOption.onceLocation = true;
  72. ///是否需要返回逆地理信息
  73. locationOption.needAddress = true;
  74. ///逆地理信息的语言类型
  75. locationOption.geoLanguage = GeoLanguage.DEFAULT;
  76. ///设置Android端连续定位的定位间隔
  77. locationOption.locationInterval = 20000;
  78. ///设置Android端的定位模式<br>
  79. ///可选值:<br>
  80. ///<li>[AMapLocationMode.Battery_Saving]</li>
  81. ///<li>[AMapLocationMode.Device_Sensors]</li>
  82. ///<li>[AMapLocationMode.Hight_Accuracy]</li>
  83. locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
  84. ///设置iOS端的定位最小更新距离<br>
  85. locationOption.distanceFilter = -1;
  86. ///设置iOS端期望的定位精度
  87. /// 可选值:<br>
  88. /// <li>[DesiredAccuracy.Best] 最高精度</li>
  89. /// <li>[DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 </li>
  90. /// <li>[DesiredAccuracy.NearestTenMeters] 10米 </li>
  91. /// <li>[DesiredAccuracy.Kilometer] 1000米</li>
  92. /// <li>[DesiredAccuracy.ThreeKilometers] 3000米</li>
  93. locationOption.desiredAccuracy = DesiredAccuracy.NearestTenMeters;
  94. ///设置iOS端是否允许系统暂停定位
  95. locationOption.pausesLocationUpdatesAutomatically = false;
  96. ///将定位参数设置给定位插件
  97. _locationPlugin.setLocationOption(locationOption);
  98. }
  99. }
  100. @override
  101. void didChangeDependencies() {
  102. super.didChangeDependencies();
  103. mContext.dependOnInheritedWidgetOfExactType();
  104. }
  105. getLocation() async {
  106. if (await requestPermission()) {
  107. if (null != _locationPlugin) {
  108. ///开始定位之前设置定位参数
  109. _setLocationOption();
  110. _locationPlugin.startLocation();
  111. }
  112. }
  113. }
  114. @override
  115. void dispose() {
  116. if (null != _locationListener) {
  117. _locationListener.cancel();
  118. }
  119. ///销毁定位
  120. if (null != _locationPlugin) {
  121. _locationPlugin.destroy();
  122. }
  123. super.dispose();
  124. }
  125. getSignAdd() {
  126. if (currentAddress.length == 0) {
  127. toasts("定位正在初始化,请重试。");
  128. return;
  129. }
  130. widget.backFun(latLng.latitude, latLng.longitude, currentAddress);
  131. Navigator.of(context).pop();
  132. }
  133. Future<bool> requestPermission() async {
  134. final permissions = await PermissionHandler()
  135. .requestPermissions([PermissionGroup.location]);
  136. if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  137. // toasts("已经定位.");
  138. return true;
  139. } else {
  140. toasts('需要定位权限!');
  141. return false;
  142. }
  143. }
  144. @override
  145. Widget build(BuildContext context) {
  146. return Scaffold(
  147. appBar: MyAppBar(
  148. centerTitle: "定位打卡",
  149. ),
  150. body: Container(
  151. color: Colors.white,
  152. child: Column(
  153. children: <Widget>[
  154. Container(
  155. height: ScreenUtil().setHeight(250),
  156. child: Stack(
  157. children: <Widget>[
  158. AmapView(
  159. mapType: MapType.Standard,
  160. showZoomControl: false,
  161. centerCoordinate: latLng,
  162. zoomLevel: 17,
  163. maskDelay: Duration(milliseconds: 500),
  164. onMapCreated: (controller) async {
  165. _controller = controller;
  166. await _controller?.showMyLocation(MyLocationOption(
  167. myLocationType: MyLocationType.Locate,
  168. ));
  169. },
  170. ),
  171. Positioned(
  172. top: ScreenUtil().setHeight(140),
  173. left: ScreenUtil().setWidth(130),
  174. child: ClipRRect(
  175. borderRadius: BorderRadius.circular(4),
  176. child: Container(
  177. width: ScreenUtil().setWidth(222),
  178. padding: EdgeInsets.all(5),
  179. color: Colours.blue_app_main,
  180. child: Text(
  181. " 当前位置:${currentAddress ?? ''} ",
  182. style: TextStyle(color: Colors.white),
  183. maxLines: 1,
  184. overflow: TextOverflow.ellipsis,
  185. ),
  186. ),
  187. ))
  188. //
  189. ],
  190. )),
  191. Container(
  192. // padding: EdgeInsets.only(left: 10),
  193. alignment: Alignment.centerLeft,
  194. height: 45,
  195. decoration: BoxDecoration(
  196. border: Border(
  197. bottom: BorderSide(width: 0.5, color: Colours.line),
  198. ),
  199. ),
  200. child: Row(
  201. children: [
  202. Container(
  203. // margin: EdgeInsets.only(left: 10),
  204. height: 13, width: 2, color: Colours.blue_app_main,
  205. ),
  206. SizedBox(
  207. width: 10,
  208. ),
  209. Text(
  210. "打卡信息",
  211. style: TextStyle(fontSize: 14, color: Colours.text),
  212. ),
  213. ],
  214. )),
  215. Container(
  216. child: Row(
  217. children: [
  218. SizedBox(
  219. width: 5,
  220. ),
  221. Icon(
  222. const IconData(0xe638, fontFamily: "Iconfont"),
  223. size: 17.0,
  224. color: Colours.blue_app_main,
  225. ),
  226. Text(
  227. '$currentAddress',
  228. style: TextStyle(color: Colours.blue_app_main),
  229. ),
  230. ],
  231. ),
  232. ),
  233. Expanded(child: Container()),
  234. GestureDetector(
  235. onTap: () {
  236. getSignAdd();
  237. },
  238. child: Container(
  239. height: 110,
  240. width: 110,
  241. decoration: BoxDecoration(
  242. color: Colours.blue_app_main,
  243. boxShadow: [
  244. ///阴影颜色/位置/大小等
  245. BoxShadow(
  246. color: Colors.grey[300], offset: Offset(1, 1),
  247. ///模糊阴影半径
  248. blurRadius: 5,
  249. ),
  250. BoxShadow(
  251. color: Colors.grey[300],
  252. offset: Offset(-1, -1),
  253. blurRadius: 5),
  254. BoxShadow(
  255. color: Colors.grey[300],
  256. offset: Offset(1, -1),
  257. blurRadius: 5),
  258. BoxShadow(
  259. color: Colors.grey[300],
  260. offset: Offset(-1, 1),
  261. blurRadius: 5)
  262. ],
  263. borderRadius: BorderRadius.circular(73)),
  264. child: Column(
  265. mainAxisAlignment: MainAxisAlignment.center,
  266. children: <Widget>[
  267. Text(
  268. "打卡",
  269. style: TextStyle(
  270. fontSize: 14,
  271. fontWeight: FontWeight.w500,
  272. color: Colors.white),
  273. ),
  274. ],
  275. ),
  276. ),
  277. ),
  278. SizedBox(
  279. height: ScreenUtil().setHeight(30),
  280. )
  281. ],
  282. ),
  283. ),
  284. );
  285. }
  286. }