Dart——库

1.分类

  • 自定义的库
    • import ""
  • 系统内置库
    • io,math,convert...
  • Pub包管理系统里面的库
    • 需要在自己的项目根目录新建一个pubspec.yaml
    • 在pubspec.yaml文件中配置名称、描述、依赖等信息
      •  注意:冒号后面需要有空格

    • 然后运行pub get (当前目录)获取包下载到本地
    • 项目中引入库: import "package:http/http.dart" as http
       

2.库的重命名(as关键字)

示例:

import './Person.dart' as P;

main(List<String> args) {
  P.Person p1 = new P.Person("xxx", 12);
}

3.部分导入(show关键字、hide关键字)

  • Person库:
    • fn1() {
        print("111");
      }
      
      fn2() {
        print("222");
      }
      
      fn3() {
        print("333");
      }
  • 引入Person库的文件
    • 1.show
    • import './Person.dart' show fn1;
      
      main(List<String> args) {
        fn1();
      }
      • 此时只会引入fn1()方法
    • 2.hide
    • import './Person.dart' hide fn1;

      此时会引入排除fn1以外的所有库

原文地址:https://www.cnblogs.com/codexlx/p/13849664.html