简体   繁体   English

Flutter:导入和库的区别

[英]Flutter: Difference between import and library

I don't know it is a good question or not but I want to know what is differense between importing this library我不知道这是不是一个好问题,但我想知道导入这个库有什么区别

import 'package:hw_mp/hw_mp.dart';

with

library peg_parser.source_scanner; . .

Seems both are library but what is differences?似乎两者都是图书馆,但有什么区别?

The difference is that the library peft_parser.source_scanner does not import anything.不同之处在于library peft_parser.source_scanner导入任何内容。 It declares the name of the current library.它声明了当前库的名称。

Library names are not very important in Dart.库名称在 Dart 中不是很重要。 The only place you can refer to a library by name is in its own part files, and you can also just refer to it by URL there.唯一可以通过名称引用库的地方是它自己的零件文件,您也可以在那里通过 URL 来引用它。 The only things a Dart library names is good for is avoiding accidentally importing the same library twice, using different URLs. Dart 库名称的唯一好处是避免使用不同的 URL 意外导入同一个库两次。 If that happens, the compiler will treat it as two different libraries, declaring different types with the same name, which is bad.如果发生这种情况,编译器会将其视为两个不同的库,以相同的名称声明不同的类型,这很糟糕。 However, it will warn you if you have two different libraries with the same name.但是,如果您有两个同名的不同库,它会警告您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM