张延森 3 år sedan
förälder
incheckning
26b38b9651

+ 6
- 3
android/app/build.gradle Visa fil

57
     dependencies {
57
     dependencies {
58
 //        implementation 'com.google.android.material:material:1.5.0'
58
 //        implementation 'com.google.android.material:material:1.5.0'
59
         implementation('com.amap.api:3dmap:9.1.0')
59
         implementation('com.amap.api:3dmap:9.1.0')
60
-//        implementation('com.amap.api:location:6.1.0')
60
+        implementation('com.amap.api:location:6.1.0')
61
     }
61
     }
62
 
62
 
63
     buildTypes {
63
     buildTypes {
64
+        debug {
65
+            minifyEnabled true
66
+        }
64
         release {
67
         release {
65
             // TODO: Add your own signing config for the release build.
68
             // TODO: Add your own signing config for the release build.
66
             // Signing with the debug keys for now, so `flutter run --release` works.
69
             // Signing with the debug keys for now, so `flutter run --release` works.
67
             signingConfig signingConfigs.debug
70
             signingConfig signingConfigs.debug
68
 
71
 
69
             //关闭混淆, 否则在运行release包后可能出现运行崩溃, TODO后续进行混淆配置
72
             //关闭混淆, 否则在运行release包后可能出现运行崩溃, TODO后续进行混淆配置
70
-            minifyEnabled false //删除无用代码
71
-            shrinkResources false //删除无用资源
73
+            minifyEnabled true //删除无用代码
74
+//            shrinkResources false //删除无用资源
72
         }
75
         }
73
     }
76
     }
74
 }
77
 }

+ 16
- 7
android/app/proguard-rules.pro Visa fil

6
 #-keep class io.flutter.**  { *; }
6
 #-keep class io.flutter.**  { *; }
7
 #-keep class io.flutter.plugins.**  { *; }
7
 #-keep class io.flutter.plugins.**  { *; }
8
 
8
 
9
-#高德地图SDK配置
10
--keep   class com.amap.api.maps.**{*;}
11
--keep   class com.autonavi.**{*;}
12
--keep   class com.amap.api.trace.**{*;}
13
-
14
-#高德等位SDK配置
9
+-keep class com.amap.api.**{*;}
10
+#3D 地图 V5.0.0之后
11
+-keep class com.amap.api.maps.**{*;}
12
+-keep class com.autonavi.**{*;}
13
+-keep class com.amap.api.trace.**{*;}
14
+#定位
15
 -keep class com.amap.api.location.**{*;}
15
 -keep class com.amap.api.location.**{*;}
16
 -keep class com.amap.api.fence.**{*;}
16
 -keep class com.amap.api.fence.**{*;}
17
 -keep class com.loc.**{*;}
17
 -keep class com.loc.**{*;}
18
--keep class com.autonavi.aps.amapapi.model.**{*;}
18
+-keep class com.autonavi.aps.amapapi.model.**{*;}
19
+
20
+##搜索
21
+#-keep class com.amap.api.services.**{*;}
22
+##2D地图
23
+#-keep class com.amap.api.maps2d.**{*;}
24
+#-keep class com.amap.api.mapcore2d.**{*;}
25
+##导航
26
+#-keep class com.amap.api.navi.**{*;}
27
+#-keep class com.autonavi.**{*;}

+ 0
- 1
lib/models/Store.dart Visa fil

1
-// TODO Implement this library.

+ 0
- 15
lib/models/User.dart Visa fil

1
-
2
-import 'package:farmer_client/models/entities/person.dart';
3
-import 'package:get/get.dart';
4
-
5
-class User extends GetxController {
6
-  Person? _person;
7
-  Person? get person => _person;
8
-  set person (Person? p) {
9
-    _person = p;
10
-    update();
11
-  }
12
-
13
-  bool get isLogin => _person != null;
14
-
15
-}

+ 32
- 20
lib/models/app.dart Visa fil

1
 
1
 
2
+import 'dart:async';
2
 import 'dart:io';
3
 import 'dart:io';
3
 
4
 
5
+import 'package:amap_flutter_location/amap_flutter_location.dart';
4
 import 'package:farmer_client/models/entities/person.dart';
6
 import 'package:farmer_client/models/entities/person.dart';
7
+import 'package:farmer_client/widgets/Modal.dart';
5
 import 'package:get/get.dart';
8
 import 'package:get/get.dart';
6
-import 'package:location/location.dart';
7
-import '../services/user.dart';
8
 import '../utils/location.dart';
9
 import '../utils/location.dart';
9
 
10
 
10
 class AppController extends GetxController {
11
 class AppController extends GetxController {
12
   static AppController t = Get.find();
13
   static AppController t = Get.find();
13
 
14
 
14
   final user = Rx<Person>(Person());
15
   final user = Rx<Person>(Person());
15
-  final location = Rxn<LocationData>();
16
+  final location = Rxn<Map<String, Object>>();
16
   final testInt = 1.obs;
17
   final testInt = 1.obs;
17
 
18
 
19
+  AMapFlutterLocation? _location;
20
+  StreamSubscription<Map<String, Object>>? _locationListener;
21
+
18
   get locationStr {
22
   get locationStr {
19
     if (null == location.value) return null;
23
     if (null == location.value) return null;
20
-    return location.value!.longitude.toString() + "," + location.value!.latitude.toString();
24
+
25
+    double longitude = location.value!['longitude'] as double;
26
+    double latitude = location.value!['latitude'] as double;
27
+
28
+    return longitude.toString() + "," + latitude.toString();
21
   }
29
   }
22
 
30
 
23
   @override
31
   @override
26
 
34
 
27
     // 尝试获取 location
35
     // 尝试获取 location
28
     requireLocation().then((loc) async {
36
     requireLocation().then((loc) async {
29
-      var _data = await loc.getLocation();
30
-      location(_data);
37
+      _location = loc;
31
 
38
 
32
       // 监听位置变化
39
       // 监听位置变化
33
-      loc.onLocationChanged.listen((LocationData currentLocation) {
34
-        location(currentLocation);
40
+      _locationListener = loc.onLocationChanged().listen((Map<String, Object> result) {
41
+        location(result);
35
       });
42
       });
43
+      loc.startLocation();
36
     }).catchError((e) {
44
     }).catchError((e) {
37
       print(e);
45
       print(e);
38
 
46
 
39
-      var message = e.message.toString().contains('CANCELED')
40
-          ? '您取消了, 确定后将退出程序'
41
-          : e.message;
42
-
43
-      // Get.dialog();
44
-      // Get.defaultDialog(
45
-      //   title: '提示',
46
-      //   middleText: message,
47
-      //   radius: 8,
48
-      //   textConfirm: '确定',
49
-      //   onConfirm: () => exit(1),
50
-      // );
47
+      showAlert(
48
+        title: '获取定位失败',
49
+        message: e.message,
50
+        onConfirm: () => exit(1),
51
+      );
51
     });
52
     });
52
 
53
 
53
     // // 尝试获取一次人员信息
54
     // // 尝试获取一次人员信息
58
     // });
59
     // });
59
   }
60
   }
60
 
61
 
62
+  @override
63
+  void onClose() {
64
+    if (null != _locationListener) {
65
+      _locationListener?.cancel();
66
+    }
67
+
68
+    if (null != _location) {
69
+      _location?.destroy();
70
+    }
71
+  }
72
+
61
 }
73
 }

+ 1
- 1
lib/pages/home/index.dart Visa fil

20
       //   return Modal(type: 'dialog', title: '测试', message: '这是一段 message !', onConfirm: () => print('hahahaha'),);
20
       //   return Modal(type: 'dialog', title: '测试', message: '这是一段 message !', onConfirm: () => print('hahahaha'),);
21
       // } );
21
       // } );
22
       // Get.dialog(Modal(type: 'dialog', title: '测试', message: '这是一段 message !', onConfirm: () => print('hahahaha'),));
22
       // Get.dialog(Modal(type: 'dialog', title: '测试', message: '这是一段 message !', onConfirm: () => print('hahahaha'),));
23
-      modal.showDialog(title: '测试', content: SizedBox(width: 300, height: 300,), onConfirm: () => false);
23
+      modal.showDialog(title: '测试', content: SizedBox(width: 400, height: 300,), onConfirm: () => false);
24
     }, 2000);
24
     }, 2000);
25
     
25
     
26
     return const HomePage();
26
     return const HomePage();

lib/widgets/amap/const_config.dart → lib/utils/amap/const_config.dart Visa fil


+ 38
- 15
lib/utils/location.dart Visa fil

1
-import 'package:location/location.dart';
1
+import 'dart:async';
2
+
3
+import 'package:amap_flutter_location/amap_flutter_location.dart';
4
+import 'package:amap_flutter_location/amap_location_option.dart';
5
+import 'package:permission_handler/permission_handler.dart';
6
+
7
+import 'amap/const_config.dart';
2
 
8
 
3
 Future requireLocation() async {
9
 Future requireLocation() async {
4
-  Location location = Location();
5
-  bool _serviceEnabled;
6
-  PermissionStatus _permissionGranted;
7
-
8
-  _serviceEnabled = await location.serviceEnabled();
9
-  if (!_serviceEnabled) {
10
-    _serviceEnabled = await location.requestService();
11
-    if (!_serviceEnabled) {
12
-      throw Exception("请开启系统定位功能");
13
-    }
14
-  }
10
+  AMapLocationOption locationOption = AMapLocationOption();
11
+  final AMapFlutterLocation location = AMapFlutterLocation();
12
+  location.setLocationOption(locationOption);
15
 
13
 
16
-  _permissionGranted = await location.hasPermission();
14
+  /// 设置是否已经包含高德隐私政策并弹窗展示显示用户查看,如果未包含或者没有弹窗展示,高德定位SDK将不会工作
15
+  ///
16
+  /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
17
+  /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b>
18
+  ///
19
+  /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
20
+  ///
21
+  /// [hasContains] 隐私声明中是否包含高德隐私政策说明
22
+  ///
23
+  /// [hasShow] 隐私权政策是否弹窗展示告知用户
24
+  AMapFlutterLocation.updatePrivacyShow(true, true);
25
+
26
+  /// 设置是否已经取得用户同意,如果未取得用户同意,高德定位SDK将不会工作
27
+  ///
28
+  /// 高德SDK合规使用方案请参考官网地址:https://lbs.amap.com/news/sdkhgsy
29
+  ///
30
+  /// <b>必须保证在调用定位功能之前调用, 建议首次启动App时弹出《隐私政策》并取得用户同意</b>
31
+  ///
32
+  /// [hasAgree] 隐私权政策是否已经取得用户同意
33
+  AMapFlutterLocation.updatePrivacyAgree(true);
34
+
35
+  // 判断定位权限
36
+  PermissionStatus _permissionGranted = await Permission.location.status;
17
   if (_permissionGranted == PermissionStatus.denied) {
37
   if (_permissionGranted == PermissionStatus.denied) {
18
-    _permissionGranted = await location.requestPermission();
38
+    // 如果未允许, 尝试申请一次
39
+    _permissionGranted = await Permission.location.request();
19
     if (_permissionGranted != PermissionStatus.granted) {
40
     if (_permissionGranted != PermissionStatus.granted) {
20
       throw Exception("请设置允许当前程序定位功能");
41
       throw Exception("请设置允许当前程序定位功能");
21
     }
42
     }
22
   }
43
   }
23
 
44
 
45
+  AMapFlutterLocation.setApiKey(ConstConfig.amapApiKeys.androidKey!, ConstConfig.amapApiKeys.iosKey!);
46
+
24
   return location;
47
   return location;
25
-}
48
+}

+ 1
- 1
lib/widgets/amap/amap.dart Visa fil

2
 import 'package:amap_flutter_base/amap_flutter_base.dart';
2
 import 'package:amap_flutter_base/amap_flutter_base.dart';
3
 import 'package:flutter/widgets.dart';
3
 import 'package:flutter/widgets.dart';
4
 
4
 
5
-import 'const_config.dart';
5
+import 'package:farmer_client/utils/amap/const_config.dart';
6
 
6
 
7
 // https://developer.amap.com/api/flutter/guide/map-flutter-plug-in/map-flutter-info
7
 // https://developer.amap.com/api/flutter/guide/map-flutter-plug-in/map-flutter-info
8
 class AMap extends StatelessWidget {
8
 class AMap extends StatelessWidget {

+ 43
- 22
pubspec.lock Visa fil

15
       url: "https://pub.flutter-io.cn"
15
       url: "https://pub.flutter-io.cn"
16
     source: hosted
16
     source: hosted
17
     version: "3.0.0"
17
     version: "3.0.0"
18
+  amap_flutter_location:
19
+    dependency: "direct main"
20
+    description:
21
+      name: amap_flutter_location
22
+      url: "https://pub.flutter-io.cn"
23
+    source: hosted
24
+    version: "3.0.0"
18
   amap_flutter_map:
25
   amap_flutter_map:
19
     dependency: "direct main"
26
     dependency: "direct main"
20
     description:
27
     description:
70
       name: carousel_slider
77
       name: carousel_slider
71
       url: "https://pub.flutter-io.cn"
78
       url: "https://pub.flutter-io.cn"
72
     source: hosted
79
     source: hosted
73
-    version: "4.0.0"
80
+    version: "4.1.1"
74
   characters:
81
   characters:
75
     dependency: transitive
82
     dependency: transitive
76
     description:
83
     description:
273
       url: "https://pub.flutter-io.cn"
280
       url: "https://pub.flutter-io.cn"
274
     source: hosted
281
     source: hosted
275
     version: "1.0.1"
282
     version: "1.0.1"
276
-  location:
277
-    dependency: "direct main"
278
-    description:
279
-      name: location
280
-      url: "https://pub.flutter-io.cn"
281
-    source: hosted
282
-    version: "4.3.0"
283
-  location_platform_interface:
284
-    dependency: transitive
285
-    description:
286
-      name: location_platform_interface
287
-      url: "https://pub.flutter-io.cn"
288
-    source: hosted
289
-    version: "2.3.0"
290
-  location_web:
291
-    dependency: transitive
292
-    description:
293
-      name: location_web
294
-      url: "https://pub.flutter-io.cn"
295
-    source: hosted
296
-    version: "3.1.1"
297
   logging:
283
   logging:
298
     dependency: transitive
284
     dependency: transitive
299
     description:
285
     description:
385
       url: "https://pub.flutter-io.cn"
371
       url: "https://pub.flutter-io.cn"
386
     source: hosted
372
     source: hosted
387
     version: "2.0.5"
373
     version: "2.0.5"
374
+  permission_handler:
375
+    dependency: "direct main"
376
+    description:
377
+      name: permission_handler
378
+      url: "https://pub.flutter-io.cn"
379
+    source: hosted
380
+    version: "9.2.0"
381
+  permission_handler_android:
382
+    dependency: transitive
383
+    description:
384
+      name: permission_handler_android
385
+      url: "https://pub.flutter-io.cn"
386
+    source: hosted
387
+    version: "9.0.2+1"
388
+  permission_handler_apple:
389
+    dependency: transitive
390
+    description:
391
+      name: permission_handler_apple
392
+      url: "https://pub.flutter-io.cn"
393
+    source: hosted
394
+    version: "9.0.4"
395
+  permission_handler_platform_interface:
396
+    dependency: transitive
397
+    description:
398
+      name: permission_handler_platform_interface
399
+      url: "https://pub.flutter-io.cn"
400
+    source: hosted
401
+    version: "3.7.0"
402
+  permission_handler_windows:
403
+    dependency: transitive
404
+    description:
405
+      name: permission_handler_windows
406
+      url: "https://pub.flutter-io.cn"
407
+    source: hosted
408
+    version: "0.1.0"
388
   platform:
409
   platform:
389
     dependency: transitive
410
     dependency: transitive
390
     description:
411
     description:

+ 3
- 2
pubspec.yaml Visa fil

44
   flutter_screenutil: ^5.3.1
44
   flutter_screenutil: ^5.3.1
45
   get_storage: ^2.0.3
45
   get_storage: ^2.0.3
46
   fluttertoast: ^8.0.9
46
   fluttertoast: ^8.0.9
47
-  location: ^4.3.0
47
+#  location: ^4.3.0
48
   amap_flutter_map: ^3.0.0
48
   amap_flutter_map: ^3.0.0
49
-  #  amap_flutter_location: ^3.0.0
49
+  amap_flutter_location: ^3.0.0
50
   carousel_slider: ^4.0.0
50
   carousel_slider: ^4.0.0
51
+  permission_handler: ^9.2.0
51
 
52
 
52
 
53
 
53
 
54