美文网首页
创建flutter插件package

创建flutter插件package

作者: 贝勒老爷 | 来源:发表于2022-03-21 17:52 被阅读0次

一、创建package

要创建纯 Dart 库的 package,使用带有 --template=package 标志的 flutter create 命令
要创建原生插件 package,使用带有 --template=plugin 标志的 flutter create 命令
使用 --org 选项,以反向域名表示法来指定你的组织。该值用于生成的 Android 及 iOS 代码
使用 -a 选项指定 Android 的语言,或使用 -i 选项指定 iOS 的语言
默认情况下插件项目中 iOS 代码使用 Swift 编写, Android 代码使用 Kotlin 编写
例如创建一个名为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库是不会自动创建example项目的,但可以在库文件夹里自己创建一个example项目 然后在pubspec.yaml通过路径引用

二、package引用等完善

1、完成插件以及example逻辑

2、在插件的pubspec.yaml里编辑完成插件名字、介绍、版本、源代码地址等

如下图

11476712-ceaddd063aa10a87.png

3、完善readme、changelog等文档以及编写license(在github等找个MIT或者Apache的就行)

4、在终端进入插件文件夹,执行

插件检查

flutter packages pub publish --dry-run

发布

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

之后提示是否确定发布

Do you want to publish flutter_plugin_calendar 0.0.1 (y/N)? 

确定输入y 回车 发布完成
完整流程如下

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.

相关文章

网友评论

      本文标题:创建flutter插件package

      本文链接:https://www.haomeiwen.com/subject/ebytjrtx.html