dart 如何解决flutter错误中“as前缀”

ars1skjm  于 2023-02-27  发布在  Flutter
关注(0)|答案(2)|浏览(354)
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

o4hqfura

o4hqfura1#

此消息是因为在多个库中定义了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.LocationAccuracygeolocator.LocationAccuracy

jgovgodb

jgovgodb2#

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

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

相关问题