Flutter发布Package到Pub.dev

本文介绍如何创建并发布一个Flutter插件到pub.dev平台,以支付宝授权SDK为例,详细说明了从创建项目到最终发布的整个流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目场景:

因为项目开发中用到支付宝授权功能,需要集成支付宝SDK,由于产品经理考虑支付SDK会影响store上架(你懂的嘿嘿),所以我们使用的是只有授权的SDK并做成插件上传到了pub.dev

废话不多说直入主题。

1、创建package工程

new Flutter Project >Project type选择Plugin

在这里插入图片描述

2、完成你的插件

写好插件功能
在example工程下编写示例代码
修改 CHANGELOG.md

3. 添加License(我这里用的是Dart推荐的BSD-3-Clause)

Copyright 2022, the Dart project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * 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.
    * Neither the name of Google Inc. nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS 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
OWNER 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.

4. 修改pubspec.yaml文件

name: alipay_auth
description: 项目描述.
version: 0.0.1
author: cwdsgi@gmail.com
homepage: https://github.com/yiqimanbu/flutter_alipay_auth

5、开启梯子,并设置终端代理

export https_proxy=http://127.0.0.1:1087
export http_proxy=http://127.0.0.1:1087

注意!windows电脑使用下面的命令

set https_proxy=https://127.0.0.1:1087
set http_proxy=http://127.0.0.1:1087

6、检查下包有没有问题,一般是没有许可证书,readme中存在todo字眼等问题

flutter packages pub publish --dry-run

7、开始发布

flutter packages pub publish --server=https://pub.dartlang.org

7.1、输入后会提示是否继续:

在这里插入图片描述

7.2、 提示 Google 验证:

复制到浏览器并登录验证

在这里插入图片描述

8、成功

Waiting for your authorization...
Authorization received, processing...
Successfully authorized.
Uploading...
Successfully uploaded package.

这里附上我上传的插件alipay_auth一个为支付宝授权SDK做的Flutter插件,同时支持Android、IOS

需要的可以直接拿来使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值