Dart如何明确说明要使用哪个包类?

时间:2018-09-17 09:32:27

标签: dart geolocation location flutter flutter-dependencies

我有一个Dart(Flutter)应用程序,它同时使用locationmap_view软件包。我的问题是,这两个都定义了“ Location”类。

如何在任何特定调用中明确声明我正在使用两个类中的哪个?

例如我尝试使用包名称为类名称添加前缀:

location.Location = new Location();

map_view.Location = new Location(45.5231233, -122.6733130);

但是Dart似乎不喜欢这种语法。

1 个答案:

答案 0 :(得分:2)

找到了答案。您必须为库指定一个前缀:https://www.dartlang.org/guides/language/language-tour#libraries-and-visibility

之后,您可以在类名称中使用前缀使其起作用:

import 'package:location/location.dart' as locLib;
import 'package:map_view/map_view.dart' as mapViewLib;

locLib.Location = new Location();
mapViewLib.Location = new Location(45.5231233, -122.6733130);