使用了挺久的Flutter,今天学习下发布package到pub.dev~

首先得准备的内容有:1、翻墙工具 2、如果是第一次上传的话需要一个谷歌账号。

1、首先我们先确定下合适的名字,去到pub官网上搜索下,如果没有该库,那就可以使用。

没有该包

2、 flutter create --template=package qwerbbb,新建一个package,叫qwerbbb,名字随意。

create_package.png

pub目录

如果没有example文件夹,可以执行flutter create example

create_example

3、在lib里面就可以写你的组件内容了。

途中如果出现无故报红现象可以执行下flutter packages get
flutter_package_get

4、插件内容写完之后,可以回到example中,写一下例子。
pub引入

pub中main

5、回到最外层的pubspec.yaml中,书写该包的namedescriptionversionhomepage,在README.md中写一些包的描述,如:


pub 描述
pub 描述1 6、接下来到最外面的这个 LICENSE 文件中,写下许可证, 我这里直接复制一个,修改顶部的title和年份、作者,当然你可以选择想用的许可证文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 qwerbbb


Copyright <2022> <zhoushaoting>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.I

7、先在开始上传,接下来需要你终端翻墙了。翻墙后,执行 flutter packages pub publish --dry-run,如果是首次发布的话,终端会告诉你需要访问一个网址,浏览器访问,使用一个谷歌账号登录即可。
8、然后,终端如果输出Package has 0 warnings那就成功.
第一头部

第一尾部

9、执行flutter packages pub publish --server=https://pub.dartlang.org,如果有警告,根据信息改后再次执行命令即可
头部

中部

尾部

最后,看到Successfully uploaded …….即表示成功。我们复制上面的https://pub.dev/packages/qwebbb即可看到该库,同时稍等片刻后即可以搜索到该库。
pub包
pub上传ok

打完,吐槽一下,为何这个库无法彻底删除,会一直挂在你的账号下,所幸可以设置为DISCONTINUED区分下。