import 'dart:io'; import 'package:android_intent_plus/android_intent.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/view_widget/request_permission.dart'; import 'package:permission_handler/permission_handler.dart'; class Location { static Location _instance; Location._internal() { aMapFlutterLocation = LocationFlutterPlugin(); } static Location getInstance() { if (_instance == null) { _instance = Location._internal(); } return _instance; } LocationFlutterPlugin aMapFlutterLocation; prepareLoc() { aMapFlutterLocation.prepareLoc({ "coorType": "bd09ll", "isNeedAddres": false, "isNeedAltitude": false, "isNeedLocationPoiList": false, "isNeedLocationDescribe": false, "isNeedNewVersionRgc": false, "scanspan": 0, "openGps": true, "locationMode": 2, }, { "locationMode": "kCLLocationAccuracyBest", "locationTimeout": 10, "reGeocodeTimeout": 10, "activityType": "CLActivityTypeAutomotiveNavigation", "BMKLocationCoordinateType": "BMKLocationCoordinateTypeBMK09LL", "isNeedNewVersionRgc": false, }); } Future startLocation(context) async { if (!(await Permission.locationWhenInUse.serviceStatus.isEnabled)) { enableLocation(context); print("object1111"); return; } if (await Permission.location.isPermanentlyDenied) { requestDialog(context); print("object2222"); } else if (await Permission.location.isGranted) { aMapFlutterLocation.startLocation(); print("object3333"); } else if (await Permission.location.isUndetermined) { await Permission.location.request(); print("object44444"); } else { print("object5555"); if (Platform.isIOS) { //去设置中心 requestDialog(context); } else { await Permission.location.request(); } } } void sotpLocation() { aMapFlutterLocation.stopLocation(); } enableLocation(context) { showCupertinoDialog( context: context, builder: (context) { return RequestPermission( "assets/image/icon_permission_location_bg.png", S.of(context).nindingweigongnengweikaiqi, S.of(context).weilexiangnintuijianfujindemendianxinxi, S.of(context).dakaidingwei, (result) async { if (result) { final AndroidIntent intent = AndroidIntent( action: 'action_location_source_settings', package: "com.zsw.huixiang"); await intent.launch(); // startLocation(); } }, heightRatioWithWidth: 0.82, ); }, ); } requestDialog(context) { showCupertinoDialog( context: context, builder: (context) { return RequestPermission( "assets/image/icon_permission_location_bg.png", S.of(context).nindingweiquanxianweiyunxu, S.of(context).weilexiangnintuijianfujindemendianxinxi, S.of(context).kaiqiquanxian, (result) async { if (result) { await openAppSettings(); if (await Permission.location.isGranted) { startLocation(context); } } }, heightRatioWithWidth: 0.82, ); }); } }