1. 創(chuàng)建packages
flutter create --template=package flutter_easy_use_tools
2. 實現(xiàn)功能
lib
下創(chuàng)建src
文件夾,src
文件下的文件是不對外開放的,開放則通過flutter_easy_use_tools.dart
來對外開放树埠。
library flutter_easy_use_tools;
export 'src/extension/string_extension.dart';
export 'src/utils/num_util.dart';
export 'src/utils/string_util.dart';
export 'src/widgets/custom_inner_shadow.dart';
3. 檢查pubspec.yaml
name: flutter_easy_use_tools
description: A new Flutter project.
version: 0.0.1
homepage: https://github.com/yuanzhiying/flutter_easy_use_tools
4. 驗證packages
$ flutter packages pub publish --dry-run
$ flutter packages pub publish --dry-run
Publishing flutter_easy_use_tools 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
| |-- extension
| | '-- string_extension.dart
| |-- flutter_easy_use_tools.dart
| '-- widgets
| '-- custom_inner_shadow.dart
|-- pubspec.yaml
'-- test
'-- flutter_easy_use_tools_test.dart
Package has 0 warnings.
5. 發(fā)布packages
執(zhí)行flutter packages pub publish
橄唬,點擊其中鏈接瀏覽器打開授權,需要登錄谷歌賬號盐杂。
先用命令測試能否訪問谷歌:$ curl www.google.com
$ flutter packages pub publish
Publishing flutter_easy_use_tools 0.0.1 to https://pub.flutter-io.cn:
|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
| |-- extension
| | '-- string_extension.dart
| |-- flutter_easy_use_tools.dart
| '-- widgets
| '-- custom_inner_shadow.dart
|-- pubspec.yaml
'-- test
'-- flutter_easy_use_tools_test.dart
Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy
Do you want to publish flutter_easy_use_tools 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%3A58974&code_challenge=Nc8EH9vceyITk7SeK9H9iEXvcPTlLxzBLhFWE9zwnm0&code_challenge_method=S256&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
Then click "Allow access".
Waiting for your authorization...
發(fā)布成功的情況:
$ flutter packages pub publish
Publishing flutter_easy_use_tools 0.0.1 to https://pub.dartlang.org:
|-- .gitignore
|-- .metadata
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- lib
| |-- extension
| | '-- string_extension.dart
| |-- flutter_easy_use_tools.dart
| '-- widgets
| '-- custom_inner_shadow.dart
|-- pubspec.yaml
'-- test
'-- flutter_easy_use_tools_test.dart
Downloading vector_math 2.1.0...
Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy
Do you want to publish flutter_easy_use_tools 0.0.1 (y/N)? y
Uploading...
Successfully uploaded package.
如果使用了代理,則需要在客戶端上執(zhí)行終端代理命令:
我的代理命令如下:
export HTTP_PROXY=http://127.0.0.1:1081; export HTTPS_PROXY=http://127.0.0.1:1081; export ALL_PROXY=socks5://127.0.0.1:1080
執(zhí)行完之后,再執(zhí)行發(fā)布命令廊佩。
6. 查看自己發(fā)布的packages
使用谷歌賬號,登錄網(wǎng)站:https://pub.dev/
查看自己發(fā)布的插件:
搜索自己發(fā)布的插件:
7. 更新插件
編寫完新的插件代碼后:
① 修改pubspec.yaml
文件中的version: 0.0.1
為version: 0.0.2
靖榕。
② CHANGELOG.md
增加更新日志标锄,最新版本在最上面。
③ 修改README.md
文件茁计。
④ 提交git
代碼料皇,添加tag
。
$ flutter packages pub publish
重新發(fā)布。
8. 為插件添加example
在packages
目錄下践剂,創(chuàng)建example
項目鬼譬。
添加插件到example
,
dependencies:
flutter:
sdk: flutter
flutter_easy_use_tools:
path: ../
example
中使用:
import 'package:flutter_easy_use_tools/flutter_easy_use_tools.dart';
在packages
頁面查看:
9. 插件問題完善
在我的插件后臺可以看到插件不完善和不規(guī)范的地方舷手,可以完善以提高評分拧簸。
代碼格式化執(zhí)行命令:
flutter format .
$ flutter format .
Formatting directory .:
Unchanged example/lib/main.dart
Unchanged example/test/widget_test.dart
Unchanged lib/flutter_easy_use_tools.dart
Formatted lib/src/extension/string_extension.dart
Formatted lib/src/utils/num_util.dart
Formatted lib/src/utils/string_util.dart
Formatted lib/src/widgets/custom_inner_shadow.dart
Unchanged test/flutter_easy_use_tools_test.dart
10. 避免通過package:flutter_easy_use_tools/src/...
方式來使用插件。
應該通過插件提供的對外文件來使用:
import 'package:flutter_easy_use_tools/flutter_easy_use_tools.dart';
11. 為packages
創(chuàng)建文檔
使用 dart doc 可以為 Library 生成 API 文檔男窟。
dartdoc 解析源文件去查找使用 ///
語法標注的文檔注釋盆赤。
進入packages
根目錄,執(zhí)行dart doc .
命令歉眷。
$ dart doc .
Documenting flutter_easy_use_tools...
dartdoc failed: Top level package requires Flutter but FLUTTER_ROOT environment variable not set.
執(zhí)行失敗牺六。
查看FLUTTER_ROOT
,
$ echo $FLUTTER_ROOT
添加FLUTTER_ROOT
添加FLUTTER_ROOT
汗捡,執(zhí)行淑际,查看。
$ source ~/..bash_profile
$ echo $FLUTTER_ROOT
/Users/yuanzhiying/fvm/versions/stable
$ dartdoc
Documenting flutter_easy_use_tools...
Initialized dartdoc with 393 libraries in 48.6 seconds
Generating docs for library flutter_easy_use_tools from package:flutter_easy_use_tools/flutter_easy_use_tools.dart...
warning: flutter_easy_use_tools has no library level documentation comments, from flutter_easy_use_tools: (file:///Users/yuanzhiying/github/flutter_easy_use_tools/lib/flutter_easy_use_tools.dart:1:9)
Validating docs...
Found 1 warning and 0 errors.
Documented 1 public library in 2.6 seconds
Success! Docs generated into /Users/yuanzhiying/github/flutter_easy_use_tools/doc/api