颤振位置权限上的PlatformException ERROR_ALREADY_REQUESTING_PERMISSIONS

时间:2020-06-01 08:28:34

标签: flutter exception dart geolocation location

颤振位置权限发生异常。

PlatformException (PlatformException(ERROR_ALREADY_REQUESTING_PERMISSIONS, A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)., null))

尝试使用geolocator软件包获取当前位置,获得对

的期望
Position position = await Geolocator().getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);

完整代码:

class LocationService{
  Position currentLocation;
  var timer = Duration(seconds: 10);

  StreamController<Position> _locationController = StreamController<Position>();

  LocationService() {
    findLocation();
    Timer.periodic(timer, (t) {
      findLocation();
    });
  }

  Stream<Position> get getLocation => _locationController.stream;

  Future<Position> getCurrentLocation() async {
    print("fetch position");
    Position position = await Geolocator().getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);
    return position;
  }

  findLocation() async {
    currentLocation = await getCurrentLocation();
    _locationController.add(currentLocation);
  }
} 

如何解决此异常? 为什么会发生此异常?

0 个答案:

没有答案