【Flutter】Flutter添加依赖

Flutter添加依赖

依赖pub.dev

flutter添加依赖是在flutter模块下的pubspec.yaml文件里的dependencies下添加。

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

  event_bus: 1.0.3

添加三方包的格式很简单:包名 + ^ + 版本号。其中,^表示会获取版本号第一个数为标准的最高版本,比如,event_bus: ^1.0.3,最后依赖的是event_bus:1.1.1版本,因为这个是event_bus:1.y.z的最高版本。

上述添加的依赖都是被存放在pub.dev平台上

依赖本地库

dependencies:
    // 包名
    pkg1:
        // 本地包路径
        path: ../../code/pkg1

依赖本地库暂时没实践过。

依赖github

dependencies:
	http:
    git:
      url: https://github.com/dart-lang/http.git
      ref: 0.13.3

在这里插入图片描述

上述url使用https方式,使用ssh方式需要配置git账号。ref 参数将依赖固定到 git 特定的 commitbranch 或者 tag。上述例子中使用的是tag
在这里插入图片描述

可以对比项目中下载下来的commit id(http-798aad1....)githubtagcommit id(798aad1....)相同。

猜你喜欢

转载自blog.csdn.net/u013293125/article/details/125537065