1. 关联上传远程仓库
- github上创建同名仓库 rf_section_listview
- 关联package 文件
- 将所有文件push到远程仓库
2. 发布package命令
- 2.1 测试发布
flutter packages pub publish --dry-run
➜ rf_section_listview git:(master) flutter packages pub publish --dry-run
Publishing rf_section_listview 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
| |-- rf_section_listview.dart
| '-- src
| '-- impl.dart
|-- pubspec.yaml
'-- test
'-- rf_section_listview_test.dart
Package has 0 warnings.
先试一下,看又没有问题,没有报错就可以进行发布。有报错就根据报错看下
- 2.2 正式发布
flutter packages pub publish或者flutter packages pub publish --server=https://pub.dartlang.org
我使用的是 flutter packages pub publish --server=pub.dartlang.org 注意首次发布需要google authorization
➜ rf_section_listview git:(master) ✗ flutter packages pub publish --server=https://pub.dartlang.org
Publishing rf_section_listview 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
| |-- rf_section_listview.dart
| '-- src
| '-- impl.dart
|-- pubspec.yaml
'-- test
'-- rf_section_listview_test.dart
Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy
Do you want to publish rf_section_listview 0.0.1 (y/N)? y
Pub needs your authorization to upload packages on your behalf.
In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A64250&code_challenge=e0Jo1pcVdxnpDIude-PFlrQHsPT0iD6GSrfvUJnFAo4&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
Then click "Allow access".
Waiting for your authorization...
Authorization received, processing...
复制上面输出的地址,粘贴到浏览器(chrome)上加载,进行授权(要翻墙)
https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A64250&code_challenge=e0Jo1pcVdxnpDIude-PFlrQHsPT0iD6GSrfvUJnFAo4&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
授权成功后会继续进行上传动作
Waiting for your authorization...
Authorization received, processing...
Successfully authorized.
Uploading... (4.9s)
Successfully uploaded package.
提示Successfully uploaded package.就说明上传成功了。
注意:步骤2需要开启终端翻墙
3. 测试
- 3.1. 先去pub上看看
去pub dev上搜索下刚发布的package
rf_section_listview - 3.2. 本地测试
在测试工程
pubspec.yaml文件中添加, 然后pub get
rf_section_listview: ^0.0.1
回到main.dart文件中测试
import 'package:rf_section_listview/rf_section_listview.dart';
void main() {
Test.kkkk();//rf_section_listview中测试的方法
runApp(MyApp());
}
打印: dddd
测试通过,发布成功