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
特定的 commit
、branch
或者 tag
。上述例子中使用的是tag
可以对比项目中下载下来的commit id(http-798aad1....)
和github
上tag
的commit id(798aad1....)
相同。