如何解决颤动错误中的“作为前缀”

问题描述 投票:0回答:3
The name 'LocationAccuracy' is defined in the libraries 'package:geolocation/geolocation.dart', 'package:geolocator/geolocator.dart' and 'package:location_platform_interface/location_platform_interface.dart (via package:location/location.dart)'.
Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.dartambiguous_import

enter image description here

flutter dart
3个回答
11
投票

此消息是因为在多个库中定义了

LocationAccuracy
。因此,您需要定义从哪个库获取此 LocationAccuracy。所以你需要在导入后指定一个前缀,如下所示:

import 'package:geolocation/geolocation.dart' as geo; // or whatever name you want
import 'package:geolocator/geolocator.dart' as geolocator; // or whatever name you want

然后具体要使用的

LocationAccuracy
可以这样参考:

geo.LocationAccuracy
geolocator.LocationAccuracy


1
投票

您还可以使用隐藏 LocationAccuracy 的第二个建议,方法是在导入“package:geolocator/geolocator.dart”后添加此内容,如下所示:

import 'package:geolocator/geolocator.dart' hide LocationAccuracy;

0
投票

将“package:flutter_archive/flutter_archive.dart”导入为zip; 你在哪里使用这个包 等待 zip.ZipFile.createFromDirectory( 源目录:临时目录, zip文件: zip文件, recurseSubDirs:真, );

© www.soinside.com 2019 - 2024. All rights reserved.