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

问题描述 投票:0回答:1

我有一个Dart(Flutter)应用程序正在使用locationmap_view包。我的问题是这两个都定义了一个“位置”类。

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

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

location.Location = new Location();

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

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

dart geolocation location flutter flutter-dependencies
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.