一兄裂、創(chuàng)建package
- 要創(chuàng)建純 Dart 庫的 package败明,使用帶有 --template=package 標志的 flutter create 命令
- 要創(chuàng)建原生插件 package,使用帶有 --template=plugin 標志的 flutter create 命令
- 使用 --org 選項援所,以反向域名表示法來指定你的組織揭朝。該值用于生成的 Android 及 iOS 代碼
- 使用 -a 選項指定 Android 的語言队贱,或使用 -i 選項指定 iOS 的語言
- 默認情況下插件項目中 iOS 代碼使用 Swift 編寫, Android 代碼使用 Kotlin 編寫
- 例如創(chuàng)建一個名為hello的庫
1.純Dart庫
flutter create --template=package hello
2.iOS swift潭袱、android java
flutter create --org com.example --template=plugin --platforms=android,ios -a java hello
3.iOS Object-C柱嫌、android java
flutter create --org com.example --template=plugin --platforms=android,ios -a java -i objc hello
4.iOS Object-C、android Kotlin
flutter create --org com.example --template=plugin --platforms=android,ios -i objc hello
5.iOS Swift屯换、android Kotlin
flutter create --org com.example --template=plugin --platforms=android,ios hello
注:純Dart庫是不會自動創(chuàng)建example項目的慎式,但可以在庫文件夾里自己創(chuàng)建一個example項目 然后在pubspec.yaml通過路徑引用
二、package引用等完善
1趟径、完成插件以及example邏輯
2、在插件的pubspec.yaml里編輯完成插件名字癣防、介紹蜗巧、版本、源代碼地址等
如下圖
3蕾盯、完善readme幕屹、changelog等文檔以及編寫license(在github等找個MIT或者Apache的就行)
4、在終端進入插件文件夾,執(zhí)行
插件檢查
flutter packages pub publish --dry-run
發(fā)布
flutter packages pub publish --server=https://pub.dartlang.org
之后提示是否確定發(fā)布
Do you want to publish flutter_plugin_calendar 0.0.1 (y/N)?
確定輸入y 回車 發(fā)布完成
完整流程如下
shineyokdeMacBook-Pro:calendar admin$ flutter packages pub publish --server=https://pub.dartlang.org
Publishing flutter_plugin_calendar 0.0.1 to https://pub.dartlang.org:
|-- .gitignore
|-- .metadata
|-- .vscode
| '-- launch.json
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- example
| |-- .gitignore
| |-- .metadata
| |-- README.md
| |-- android
| | |-- .gitignore
| | |-- app
| | | |-- build.gradle
| | | '-- src
| | | |-- debug
| | | | '-- AndroidManifest.xml
| | | |-- main
| | | | |-- AndroidManifest.xml
| | | | |-- kotlin
| | | | | '-- com
| | | | | '-- example
| | | | | '-- example
| | | | | '-- MainActivity.kt
| | | | '-- res
| | | | |-- drawable
| | | | | '-- launch_background.xml
| | | | |-- mipmap-hdpi
| | | | | '-- ic_launcher.png
| | | | |-- mipmap-mdpi
| | | | | '-- ic_launcher.png
| | | | |-- mipmap-xhdpi
| | | | | '-- ic_launcher.png
| | | | |-- mipmap-xxhdpi
| | | | | '-- ic_launcher.png
| | | | |-- mipmap-xxxhdpi
| | | | | '-- ic_launcher.png
| | | | '-- values
| | | | '-- styles.xml
| | | '-- profile
| | | '-- AndroidManifest.xml
| | |-- build.gradle
| | |-- gradle
| | | '-- wrapper
| | | '-- gradle-wrapper.properties
| | |-- gradle.properties
| | '-- settings.gradle
| |-- ios
| | |-- .gitignore
| | |-- Flutter
| | | |-- AppFrameworkInfo.plist
| | | |-- Debug.xcconfig
| | | '-- Release.xcconfig
| | |-- Runner
| | | |-- AppDelegate.swift
| | | |-- Assets.xcassets
| | | | |-- AppIcon.appiconset
| | | | | |-- Contents.json
| | | | | |-- Icon-App-1024x1024@1x.png
| | | | | |-- Icon-App-20x20@1x.png
| | | | | | (10 more...)
| | | | | |-- Icon-App-76x76@1x.png
| | | | | |-- Icon-App-76x76@2x.png
| | | | | '-- Icon-App-83.5x83.5@2x.png
| | | | '-- LaunchImage.imageset
| | | | |-- Contents.json
| | | | |-- LaunchImage.png
| | | | |-- LaunchImage@2x.png
| | | | |-- LaunchImage@3x.png
| | | | '-- README.md
| | | |-- Base.lproj
| | | | |-- LaunchScreen.storyboard
| | | | '-- Main.storyboard
| | | |-- Info.plist
| | | '-- Runner-Bridging-Header.h
| | |-- Runner.xcodeproj
| | | |-- project.pbxproj
| | | |-- project.xcworkspace
| | | | |-- contents.xcworkspacedata
| | | | '-- xcshareddata
| | | | |-- IDEWorkspaceChecks.plist
| | | | '-- WorkspaceSettings.xcsettings
| | | '-- xcshareddata
| | | '-- xcschemes
| | | '-- Runner.xcscheme
| | '-- Runner.xcworkspace
| | |-- contents.xcworkspacedata
| | '-- xcshareddata
| | |-- IDEWorkspaceChecks.plist
| | '-- WorkspaceSettings.xcsettings
| |-- lib
| | '-- main.dart
| |-- pubspec.yaml
| '-- test
| '-- widget_test.dart
|-- lib
| |-- flutter_plugin_calendar.dart
| |-- util
| | '-- calendar_time_util.dart
| '-- view
| |-- calendar_day_item.dart
| |-- calendar_month_item.dart
| |-- calendar_month_view.dart
| |-- calendar_view.dart
| |-- calendar_week_item.dart
| '-- calendar_week_view.dart
|-- pubspec.yaml
'-- test
'-- flutter_plugin_calendar_test.dart
Publishing is forever; packages cannot be unpublished.
Policy details are available at https://pub.dev/policy
Do you want to publish flutter_plugin_calendar 0.0.1 (y/N)? y
Uploading...
Successfully uploaded package.
iOS常用彈窗樣式flutter插件
https://pub.dev/packages/alert_tool
常用日歷樣式插件
https://pub.dev/packages/flutter_plugin_calendar
常用通訊錄/地址選擇器樣式
https://pub.dev/packages/contactor_picker