flutter-错误:无法将类型“ PermissionStatus”的值分配给类型“ bool”的变量

时间:2020-03-21 07:57:05

标签: android flutter hybrid-mobile-app

最近更新频繁后出现错误消息(我三个月都没有更新代码,但是上次构建成功)。

lib / src / blocs / home / home_bloc.dart:141:23:错误:不能将类型为“ PermissionStatus”的值分配给类型为“ bool”的变量。 < / p>

  • “ PermissionStatus”来自“ package:location / location.dart”(“ ../ programs / flutter / .pub-cache / hosted / pub.dartlang.org / location-2.5.4 / lib / location.dart')。

    _permission =等待_locationService.requestPermission();

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

https://pub.dev/packages/location_permissions

import 'package:location_permissions/location_permissions.dart';
PermissionStatus permissionStatus = await LocationPermissions().requestPermissions();

PermissionStatus permission = await LocationPermissions().checkPermissionStatus();

答案 1 :(得分:0)

尝试

PermissionStatus permission  =  await location.hasPermission();


    if(permission==PermissionStatus.GRANTED){
      return location.getLocation();
    }else{
      location.requestPermission();
    }

答案 2 :(得分:0)

  if (result == PermissionStatus.GRANTED) {
    location.onLocationChanged().listen((locationData) {
      if (locationData != null) {
        _locationController.add(UserLocation(
          latitude: locationData.latitude,
          longitude: locationData.longitude,
        ));
      }
    });
  }