diff --git a/android/app/build.gradle b/android/app/build.gradle index 1b70884..f7d9bc4 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -42,10 +42,14 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + //Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.akucommunity.aku_community_manager" minSdkVersion 21 targetSdkVersion 29 + ndk { + abiFilters 'arm64-v8a' + abiFilters 'armeabi-v7a' + } manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "99067fe33fa04aad88c3acac", //极光开发平台上注册的包名对应的appkey. @@ -82,4 +86,6 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.amap.api:3dmap:latest.integration' + implementation 'com.amap.api:location:latest.integration' } diff --git a/lib/main.dart b/lib/main.dart index cf40da1..c2077a2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,7 +5,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; // Package imports: -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -22,8 +21,8 @@ import 'package:aku_community_manager/ui/splash/splash_page.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - await AmapCore.init(''); - await AmapLocation.instance.init(iosKey: ''); + // await AmapCore.init(''); + // await AmapLocation.instance.init(iosKey: ''); JPush jpush = new JPush(); DevUtil.setDev(true); jpush.addEventHandler( diff --git a/lib/provider/app_provider.dart b/lib/provider/app_provider.dart index ffa9200..5fc923e 100644 --- a/lib/provider/app_provider.dart +++ b/lib/provider/app_provider.dart @@ -1,4 +1,6 @@ // Flutter imports: +import 'package:amap_flutter_location/amap_flutter_location.dart'; +import 'package:amap_flutter_location/amap_location_option.dart'; import 'package:flutter/material.dart'; // Project imports: @@ -26,4 +28,26 @@ class AppProvider extends ChangeNotifier { _recentUsedApp.clear(); notifyListeners(); } + + Map _location; + Map get location => _location; + AMapFlutterLocation _flutterLocation; + + startLocation() { + _flutterLocation = AMapFlutterLocation(); + _flutterLocation.onLocationChanged().listen((event) { + _location = event; + if (_location != null) { + stopLocation(); + } + }); + _flutterLocation.setLocationOption( + AMapLocationOption(onceLocation: true, needAddress: true)); + _flutterLocation.startLocation(); + } + + stopLocation() { + _flutterLocation.stopLocation(); + _flutterLocation.destroy(); + } } diff --git a/lib/ui/manage_pages/inspection_manage/qr_scanner_page.dart b/lib/ui/manage_pages/inspection_manage/qr_scanner_page.dart index b56ebc2..df0ed92 100644 --- a/lib/ui/manage_pages/inspection_manage/qr_scanner_page.dart +++ b/lib/ui/manage_pages/inspection_manage/qr_scanner_page.dart @@ -1,6 +1,5 @@ import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; diff --git a/lib/ui/splash/splash_page.dart b/lib/ui/splash/splash_page.dart index 6f6ef71..99cf8e2 100644 --- a/lib/ui/splash/splash_page.dart +++ b/lib/ui/splash/splash_page.dart @@ -1,6 +1,7 @@ // Flutter imports: import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/models/manager/item_num_model.dart'; +import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/utils/dev_util.dart'; @@ -9,11 +10,11 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; // Package imports: -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:get/get.dart' hide Response; import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:jpush_flutter/jpush_flutter.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:power_logger/power_logger.dart'; // Project imports: @@ -39,7 +40,14 @@ class _SplashPageState extends State { } //初始化AMap - await AmapLocation.instance.init(iosKey: 'ios key'); + // await AmapLocation.instance.init(iosKey: 'ios key'); + await Permission.locationWhenInUse.request(); + } + + Future _initOp() async { + await _originOp(); + final appProvider = Provider.of(context, listen: false); + appProvider.startLocation(); } @override @@ -49,7 +57,7 @@ class _SplashPageState extends State { if (mounted) PowerLogger.start(context, debug: DevUtil.isDev); }); Future.delayed(Duration(milliseconds: 2000), () async { - await _originOp(); + await _initOp(); Get.off(HomePage()); }); } diff --git a/lib/ui/tool_pages/warning/warning_page.dart b/lib/ui/tool_pages/warning/warning_page.dart index 521c199..7d486a7 100644 --- a/lib/ui/tool_pages/warning/warning_page.dart +++ b/lib/ui/tool_pages/warning/warning_page.dart @@ -1,22 +1,30 @@ // Flutter imports: import 'dart:ui'; +import 'package:aku_community_manager/provider/app_provider.dart'; import 'package:flutter/material.dart'; // Package imports: import 'package:aku_ui/common_widgets/aku_cupertino_button.dart'; import 'package:aku_ui/common_widgets/aku_material_button.dart'; -import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:get/get.dart'; // Project imports: import 'package:aku_community_manager/style/app_style.dart'; -import 'package:aku_community_manager/tools/permission_tool.dart'; import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/tool_pages/warning/warning_detail_page.dart'; -import 'package:aku_community_manager/ui/tool_pages/warning/warning_sub_page.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:amap_flutter_base/amap_flutter_base.dart'; +import 'package:amap_flutter_map/amap_flutter_map.dart'; + +class PermissonUtil { + static Future getLocationPermisson() async { + return await Permission.locationWhenInUse.request().isGranted; + } +} class WarningPage extends StatefulWidget { WarningPage({Key key}) : super(key: key); @@ -26,11 +34,22 @@ class WarningPage extends StatefulWidget { } class _WarningPageState extends State { - AmapController _amapController; - Location _location; + AMapController _mapController; + @override + void initState() { + super.initState(); + PermissonUtil.getLocationPermisson(); + } + + @override + void dispose() { + _mapController?.disponse(); + super.dispose(); + } @override Widget build(BuildContext context) { + final appProvider = Provider.of(context, listen: false); return AkuScaffold( title: '一键报警', actions: [ @@ -50,16 +69,24 @@ class _WarningPageState extends State { ], body: Stack( children: [ - AmapView( - zoomLevel: 15, - showZoomControl: false, - showCompass: false, - showScaleControl: false, - onMapCreated: (controller) async { - _amapController = controller; - _amapController.showMyLocation(MyLocationOption()); - _getLocation(); + AMapWidget( + onMapCreated: (controller) { + LatLng _target = LatLng( + appProvider.location['latitude'], + appProvider.location['longitude'], + ); + + _mapController = controller; + _mapController.moveCamera( + CameraUpdate.newCameraPosition( + CameraPosition(target: _target, zoom: 18), + ), + ); }, + myLocationStyleOptions: MyLocationStyleOptions(true, + circleFillColor: + Theme.of(context).primaryColor.withOpacity(0.2), + circleStrokeColor: Theme.of(context).primaryColor), ), ///首部地址栏 @@ -99,7 +126,9 @@ class _WarningPageState extends State { AkuBox.w(10), Expanded( child: Text( - _location?.address ?? '加载中', + (appProvider.location == null) + ? '加载中……' + : appProvider.location['address'], style: TextStyle( color: AppStyle.minorTextColor, fontSize: 28.sp, @@ -210,7 +239,15 @@ class _WarningPageState extends State { child: AkuCupertinoButton( minWidth: 0, onPressed: () { - _getLocation(); + LatLng _target = LatLng( + appProvider.location['latitude'], + appProvider.location['longitude'], + ); + _mapController.moveCamera( + CameraUpdate.newCameraPosition( + CameraPosition(target: _target, zoom: 18), + ), + ); }, child: Container( alignment: Alignment.center, @@ -241,17 +278,17 @@ class _WarningPageState extends State { ); } - _getLocation() { - _location = null; - setState(() {}); - PermissionTool.getLocationPermission().then((state) { - if (state) { - AmapLocation.instance.fetchLocation().then((location) { - _amapController.setCenterCoordinate(location.latLng); - _location = location; - setState(() {}); - }); - } - }); - } + // _getLocation() { + // _location = null; + // setState(() {}); + // PermissionTool.getLocationPermission().then((state) { + // if (state) { + // AmapLocation.instance.fetchLocation().then((location) { + // _amapController.setCenterCoordinate(location.latLng); + // _location = location; + // setState(() {}); + // }); + // } + // }); + // } } diff --git a/pubspec.lock b/pubspec.lock index 9afea14..75ee099 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -17,34 +17,29 @@ packages: url: "http://test.akuhotel.com:8099/aku_fe/aku_ui.git" source: git version: "0.0.1" - amap_core_fluttify: - dependency: transitive - description: - name: amap_core_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.12.0" - amap_location_fluttify: - dependency: transitive + amap_flutter_base: + dependency: "direct main" description: - name: amap_location_fluttify + name: amap_flutter_base url: "https://pub.flutter-io.cn" source: hosted - version: "0.18.0" - amap_map_fluttify: + version: "1.0.2" + amap_flutter_location: dependency: "direct main" description: - name: amap_map_fluttify + name: amap_flutter_location url: "https://pub.flutter-io.cn" source: hosted - version: "0.29.0" - amap_search_fluttify: - dependency: transitive + version: "1.0.1" + amap_flutter_map: + dependency: "direct main" description: - name: amap_search_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.14.0" + path: "." + ref: nullsafety + resolved-ref: "5c50cf60d2157cc2779a171ca65c327d571389a7" + url: "http://159.75.73.143:8080/third_packages/amap_flutter_map" + source: git + version: "2.0.2-nullsafety" analyzer: dependency: transitive description: @@ -164,13 +159,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.0.0" - core_location_fluttify: - dependency: transitive - description: - name: core_location_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.4.1" crypto: dependency: transitive description: @@ -324,13 +312,6 @@ packages: description: flutter source: sdk version: "0.0.0" - foundation_fluttify: - dependency: transitive - description: - name: foundation_fluttify - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.9.10+1" get: dependency: "direct main" description: @@ -528,21 +509,7 @@ packages: name: path_provider url: "https://pub.flutter-io.cn" source: hosted - version: "1.6.9" - path_provider_macos: - dependency: transitive - description: - name: path_provider_macos - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.0.4+8" - path_provider_platform_interface: - dependency: transitive - description: - name: path_provider_platform_interface - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.0.4" + version: "1.2.0" pedantic: dependency: transitive description: @@ -556,14 +523,14 @@ packages: name: permission_handler url: "https://pub.flutter-io.cn" source: hosted - version: "5.0.1+1" + version: "6.1.1" permission_handler_platform_interface: dependency: transitive description: name: permission_handler_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "2.0.1" + version: "3.1.2" pin_input_text_field: dependency: "direct main" description: @@ -584,7 +551,7 @@ packages: name: plugin_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.3" + version: "2.0.0" power_logger: dependency: "direct main" description: @@ -660,6 +627,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" + stream_transform: + dependency: transitive + description: + name: stream_transform + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.0.0" string_scanner: dependency: transitive description: @@ -694,42 +668,42 @@ packages: name: url_launcher url: "https://pub.flutter-io.cn" source: hosted - version: "5.7.10" + version: "6.0.3" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+4" + version: "2.0.0" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+9" + version: "2.0.0" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.flutter-io.cn" source: hosted - version: "1.0.9" + version: "2.0.2" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.flutter-io.cn" source: hosted - version: "0.1.5+1" + version: "2.0.0" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+3" + version: "2.0.0" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bff8e44..59a82a4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,11 +41,14 @@ dependencies: expandable: ^5.0.1 - url_launcher: ^5.7.10 - - amap_map_fluttify: ^0.29.0 - - permission_handler: ^5.0.1+1 + url_launcher: ^6.0.3 + amap_flutter_map: + git: + url: http://159.75.73.143:8080/third_packages/amap_flutter_map + ref: nullsafety + amap_flutter_location: ^1.0.1 + amap_flutter_base: ^1.0.2 + permission_handler: ^6.1.1 velocity_x: ^2.6.0 dotted_border: ^2.0.0-nullsafety.0