“显示”和“显示”之间有什么区别?和“为”在进口声明中? [英] What is the difference between "show" and "as" in an import statement?

查看:130
本文介绍了“显示”和“显示”之间有什么区别?和“为”在进口声明中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入语句中的 show as 有什么区别?

What is the difference between show and as in an import statement?

例如,

import 'dart:convert' show JSON;

import 'package:google_maps/google_maps.dart' as GoogleMap;

何时使用 show 以及何时使用我使用作为吗?

When do I use show and when should I use as?

如果我切换到显示GoogleMap GoogleMap (例如 GoogleMap.LatLng )对象的所有引用均报告为未定义。

If I switch to show GoogleMap all references to GoogleMap (e.g. GoogleMap.LatLng) objects are reported as undefined.

推荐答案

as show 是两个不同的地方

通过 as ,您可以为导入的库命名。如果库具有许多全局函数,通常可以这样做以防止库污染您的命名空间。如果您将用作,则可以通过按示例中的方式访问它们来访问所述库的所有函数和类: GoogleMap.LatLng

With as you are giving the imported library a name. It's usually done to prevent a library from polluting your namespace if it has a lot of global functions. If you use as you can access all functions and classes of said library by accessing them the way you did in your example: GoogleMap.LatLng.

具有显示(和隐藏),您可以选择想要在应用程序中显示的特定类。例如,

With show (and hide) you can pick specific classes you want to be visible in your application. For your example it would be:

import 'package:google_maps/google_maps.dart' show LatLng;

使用此功能,您可以访问 LatLng 但该库中没有其他内容。相反的是:

With this you would be able to access LatLng but nothing else from that library. The opposite of this is:

import 'package:google_maps/google_maps.dart' hide LatLng;

使用此方法,您可以访问该库中的所有内容,但 LatLng

With this you would be able to access everything from that library except for LatLng.

如果要使用相同名称的多个类,则需要使用作为。您还可以结合使用这两种方法:

If you want to use multiple classes with the same name you'd need to use as. You also can combine both approaches:

import 'package:google_maps/google_maps.dart' as GoogleMap show LatLng;

这篇关于“显示”和“显示”之间有什么区别?和“为”在进口声明中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆