Home > OS >  Import ambiguity for PermissionStatus in Flutter
Import ambiguity for PermissionStatus in Flutter

Time:01-20

I have to dynamically check for location permission in my Flutter appliaction, For that I am using below plugins:

permission_handler: ^10.2.0
location: ^4.4.0

Now, Its needed to check for the permission status i.e. granted, denied, restricted and allowed. So, for that I am declaring PermissionStatus as below:

PermissionStatus locationPermissionStatus = PermissionStatus.denied;

But due to below two imports one is for location and one is for permission,

import 'package:location/location.dart';
import 'package:permission_handler/permission_handler.dart';

It saying me on PermissionStatus declaration:

The name 'PermissionStatus' is defined in the libraries 'package:location_platform_interface/location_platform_interface.dart (via package:location/location.dart)' and 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart (via package:permission_handler/permission_handler.dart)'. (Documentation) Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.

How can I resolve this ambiguity of imported data from two different plugins?

CodePudding user response:

use for import both packages.

import 'package:location/location.dart' as location;
import 'package:permission_handler/permission_handler.dart';

for use location Permission.

location.PermissionStatus locationPermissionStatus = location.PermissionStatus.denied;

I Hope this will solve your issue.

  • Related