diff --git a/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart b/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart index 44483d67..ce2f6f09 100755 --- a/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart +++ b/lib/mine/addLock/lockAddress/gaode/lockAddressGaoDe_page.dart @@ -1,4 +1,3 @@ - import 'dart:async'; import 'dart:io'; @@ -31,11 +30,13 @@ class LockAddressGaoDePage extends StatefulWidget { class _LockAddressGaoDePageState extends State with RouteAware { final LockAddressGaoDeLogic logic = Get.put(LockAddressGaoDeLogic()); - final LockAddressGaoDeState state = Get.find().state; + final LockAddressGaoDeState state = Get + .find() + .state; // 高德地图 static AMapApiKey amapApiKeys = - AMapApiKey(iosKey: F.aMapKey.iosKey, androidKey: F.aMapKey.androidKey); + AMapApiKey(iosKey: F.aMapKey.iosKey, androidKey: F.aMapKey.androidKey); AMapController? mapController; AMapFlutterLocation location = AMapFlutterLocation(); @@ -52,51 +53,16 @@ class _LockAddressGaoDePageState extends State requestPermission(); } - // Future requestPermission() async { - // final status = await Permission.location.request(); - // AppLog.log("Permission.location.request()=status:$status"); - // permissionStatus = status; - // if(Platform.isIOS){ - // _setLocationOption(); - // requestIOSLocation(); - // } - // switch (status) { - // case PermissionStatus.denied: - // // AppLog.log("拒绝"); - // break; - // case PermissionStatus.granted: - // if(Platform.isIOS){ - // // _setLocationOption(); - // // requestIOSLocation(); - // }else{ - // requestAndroidLocation(); - // location.startLocation(); - // } - // break; - // case PermissionStatus.limited: - // // AppLog.log("限制"); - // break; - // case PermissionStatus.permanentlyDenied: - // // AppLog.log("永久的否认"); - // break; - // case PermissionStatus.provisional: - // // AppLog.log("临时"); - // break; - // default: - // // AppLog.log("其他状态"); - // // requestLocation(); - // break; - // } - // } Future requestPermission() async { final bool status = await PermissionDialog.request(Permission.location); - if(Platform.isIOS){ + if (Platform.isIOS) { _setLocationOption(); requestIOSLocation(); } if (!Platform.isIOS || status) { + _setLocationOption(); requestAndroidLocation(); location.startLocation(); } @@ -114,19 +80,18 @@ class _LockAddressGaoDePageState extends State } Future requestIOSLocation() async { - location = AMapFlutterLocation() - ..setLocationOption(AMapLocationOption()) - ..onLocationChanged().listen((Map event) { - // AppLog.log("listenLocationChanged$event"); - // EasyLoading.dismiss(); - if (event.isNotEmpty) { - setState(() { - addressInfo = event; - }); - // location.stopLocation(); - } - }) - ..startLocation(); + location.setLocationOption(AMapLocationOption()); + location.onLocationChanged().listen((Map event) { + // AppLog.log("listenLocationChanged$event"); + // EasyLoading.dismiss(); + if (event.isNotEmpty) { + setState(() { + addressInfo = event; + }); + // location.stopLocation(); + } + }); + location.startLocation(); } @override @@ -152,85 +117,88 @@ class _LockAddressGaoDePageState extends State SizedBox( child: (addressInfo != null && addressInfo!.containsKey('latitude')) ? Column( + children: [ + SizedBox( + height: 1.sw / 5 * 4, + width: 1.sw, + child: AMapWidget( + apiKey: amapApiKeys, + // 初始化地图中心 + initialCameraPosition: CameraPosition( + target: LatLng( + double.parse( + addressInfo!['latitude'].toString()), + double.parse( + addressInfo!['longitude'].toString())), + zoom: 10.0, + ), + //定位小蓝点 + myLocationStyleOptions: MyLocationStyleOptions( + true, + ), + // 普通地图normal,卫星地图satellite,夜间视图night,导航视图 navi,公交视图bus, + mapType: MapType.normal, + // 缩放级别范围 + minMaxZoomPreference: + const MinMaxZoomPreference(3, 20), + // 隐私政策包含高德 必须填写 + privacyStatement: const AMapPrivacyStatement( + hasAgree: true, hasContains: true, hasShow: true), + // 地图创建成功时返回AMapController + onMapCreated: (AMapController controller) { + mapController = controller; + }, + onLocationChanged: (AMapLocation location) { + print("onLocationChanged ${location}"); + }, + ), + ), + Container( + // color: Colors.red, + margin: + EdgeInsets.only(left: 25.w, top: 20.h, right: 25.w), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, children: [ - SizedBox( - height: 1.sw / 5 * 4, - width: 1.sw, - child: AMapWidget( - apiKey: amapApiKeys, - // 初始化地图中心 - initialCameraPosition: CameraPosition( - target: LatLng( - double.parse( - addressInfo!['latitude'].toString()), - double.parse( - addressInfo!['longitude'].toString())), - zoom: 10.0, - ), - //定位小蓝点 - myLocationStyleOptions: MyLocationStyleOptions( - true, - ), - // 普通地图normal,卫星地图satellite,夜间视图night,导航视图 navi,公交视图bus, - mapType: MapType.normal, - // 缩放级别范围 - minMaxZoomPreference: - const MinMaxZoomPreference(3, 20), - // 隐私政策包含高德 必须填写 - privacyStatement: const AMapPrivacyStatement( - hasAgree: true, hasContains: true, hasShow: true), - // 地图创建成功时返回AMapController - onMapCreated: (AMapController controller) { - mapController = controller; - }, - ), - ), - Container( - // color: Colors.red, - margin: - EdgeInsets.only(left: 25.w, top: 20.h, right: 25.w), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, + Flexible( + child: Text('检查以确保以下地址是正确的'.tr, + style: TextStyle(fontSize: 24.sp))), + ], + ), + ), + // SizedBox(height: 20.h), + Container( + // color: Colors.red, + // height: 45.h, + margin: EdgeInsets.only( + left: 25.w, top: 20.h, right: 25.w), + child: Column( + children: [ + Row( children: [ - Flexible( - child: Text('检查以确保以下地址是正确的'.tr, - style: TextStyle(fontSize: 24.sp))), + Expanded( + child: Text( + addressInfo!['address'].toString() ?? + '', + style: const TextStyle( + color: Colors.grey, + fontSize: 16, + fontWeight: FontWeight.w500, + overflow: TextOverflow.clip))), ], ), - ), - // SizedBox(height: 20.h), - Container( - // color: Colors.red, - // height: 45.h, - margin: EdgeInsets.only( - left: 25.w, top: 20.h, right: 25.w), - child: Column( - children: [ - Row( - children: [ - Expanded( - child: Text( - addressInfo!['address'].toString() ?? - '', - style: const TextStyle( - color: Colors.grey, - fontSize: 16, - fontWeight: FontWeight.w500, - overflow: TextOverflow.clip))), - ], - ), - SizedBox(height: 5.h), - Container( - height: 1.h, - color: AppColors.mainColor, - ), - ], - )), - ], - ) + SizedBox(height: 5.h), + Container( + height: 1.h, + color: AppColors.mainColor, + ), + ], + )), + ], + ) : SizedBox( - height: 1.sw / 5 * 4 + 65.h * 2, - child: Center(child: Text('地图加载中,请稍候。。。'.tr))), + height: 1.sw / 5 * 4 + 65.h * 2, + child: Center(child: Text('地图加载中,请稍候。。。'.tr))), ), SizedBox(height: 200.h), Row( @@ -242,14 +210,15 @@ class _LockAddressGaoDePageState extends State style: TextStyle(color: Colors.black, fontSize: 24.sp), ), onPressed: () { - Get.toNamed(Routers.addLockSelectCountryPage, arguments: { - 'addressInfo': {}, - 'pwdTimestamp': state.pwdTimestamp.value, - 'lockInfo': state.lockInfo, - 'featureValue': state.featureValue, - 'featureSettingValue': state.featureSettingValue, - 'featureSettingParams': state.featureSettingParams, - }); + Get.toNamed(Routers.addLockSelectCountryPage, + arguments: { + 'addressInfo': {}, + 'pwdTimestamp': state.pwdTimestamp.value, + 'lockInfo': state.lockInfo, + 'featureValue': state.featureValue, + 'featureSettingValue': state.featureSettingValue, + 'featureSettingParams': state.featureSettingParams, + }); }, ), TextButton( @@ -262,15 +231,16 @@ class _LockAddressGaoDePageState extends State logic.showToast('还未获取到位置信息哦,请耐心等待一下!'.tr); return; } - Get.toNamed(Routers.saveLockPage, arguments: { - 'addressInfo': addressInfo, - 'pwdTimestamp': state.pwdTimestamp.value, - 'lockInfo': state.lockInfo, - 'featureValue': state.featureValue, - 'featureSettingValue': state.featureSettingValue, - 'featureSettingParams': state.featureSettingParams, - 'isFromMap': 1, - }); + Get.toNamed(Routers.saveLockPage, + arguments: { + 'addressInfo': addressInfo, + 'pwdTimestamp': state.pwdTimestamp.value, + 'lockInfo': state.lockInfo, + 'featureValue': state.featureValue, + 'featureSettingValue': state.featureSettingValue, + 'featureSettingParams': state.featureSettingParams, + 'isFromMap': 1, + }); // Navigator.pushNamed(context, Routers.saveLockPage); }, ), diff --git a/pubspec.yaml b/pubspec.yaml index fd96384f..487bf75f 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -193,11 +193,11 @@ dependencies: easy_refresh: ^3.3.4 #高德地图定位 - amap_flutter_location: ^3.0.0 + amap_flutter_location: 3.0.0 #权限使用 permission_handler: ^11.3.1 #高德地图地图 - amap_flutter_map: ^3.0.0 + amap_flutter_map: 3.0.0 # 谷歌地图 google_maps_flutter: ^2.2.5