flutter-plugin之创建与弥补
  7nR2g7mlPvjr 2023年11月02日 35 0

创建

命令创建

  • 默认命令
 Flutter create  -t plugin --platforms <platforms> -i swift -a java plugin_name
  • 命令分解
No option specified for the output directory.
Create a new Flutter project.

If run on a project that already exists, this will repair the project, recreating any files that are missing.

Global options:
-h, --help Print this usage information.
-v, --verbose Noisy logging, including all shell commands executed.
If used with "--help", shows hidden options. If used with "flutter doctor", shows additional diagnostic information. (Use "-vv" to force verbose logging in those cases.)
-d, --device-id Target device id or name (prefixes allowed).
--version Reports the version of this tool.
--suppress-analytics Suppress analytics reporting when this command runs.

Usage: flutter create <output directory>
-h, --help Print this usage information.
--[no-]pub Whether to run "flutter pub get" after the project has been created.
(defaults to on)
--[no-]offline When "flutter pub get" is run by the create command, this indicates whether to run it in offline mode or not. In offline mode, it will need to have all dependencies already
available in the pub cache to succeed.
--[no-]overwrite When performing operations, overwrite existing files.
--description The description to use for your new Flutter project. This string ends up in the pubspec.yaml file.
(defaults to "A new Flutter project.")
--org The organization responsible for your new Flutter project, in reverse domain name notation. This string is used in Java package names and as prefix in the iOS bundle identifier.
(defaults to "com.example")
--project-name The project name for this new Flutter project. This must be a valid dart package name.
-i, --ios-language The language to use for iOS-specific code, either Objective-C (legacy) or Swift (recommended).
[objc, swift (default)]
-a, --android-language The language to use for Android-specific code, either Java (legacy) or Kotlin (recommended).
[java, kotlin (default)]
--platforms The platforms supported by this project. Platform folders (e.g. android/) will be generated in the target project. This argument only works when "--template" is set to app or
plugin. When adding platforms to a plugin project, the pubspec.yaml will be updated with the requested platform. Adding desktop platforms requires the corresponding desktop
config setting to be enabled.
[ios (default), android (default), windows (default), linux (default), macos (default), web (default)]
-t, --template=<type> Specify the type of project to create.

[app] (default) Generate a Flutter application.
[module] Generate a project to add a Flutter module to an existing Android or iOS application.
[package] Generate a shareable Flutter project containing modular Dart code.
[plugin] Generate a shareable Flutter project containing an API in Dart code with a platform-specific implementation through method channels for Android, iOS, Linux, macOS, Windows, web,
or any combination of these.
[plugin_ffi] Generate a shareable Flutter project containing an API in Dart code with a platform-specific implementation through dart:ffi for Android, iOS, Linux, macOS, Windows, or any
combination of these.
[skeleton] Generate a List View / Detail View Flutter application that follows community best practices.

-s, --sample=<id> Specifies the Flutter code sample to use as the "main.dart" for an application. Implies "--template=app". The value should be the sample ID of the desired sample from the API
documentation website (http://docs.flutter.dev/). An example can be found at: https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html
--list-samples=<path> Specifies a JSON output file for a listing of Flutter code samples that can be created with "--sample".

Run "flutter help" to see global options.
  • -t, --template (模版)
  • [app] 默认类型,创建一个flutter app
  • [module] flutter 模块开发
  • [package] 纯Dart库
  • [plugin]针对Android、iOS、Web、MacOS、Windows或Linux,或者把它们组合到一起的库
  • -i, --ios-language
  • 从字面意上,我们可以知道这是来指定iOS平台开发语言,swift(默认)或objc,
  • eg: -i swift
  • -a, --android-language
  • 和👆一样.java或kotlin(默认)
  • eg: -a java
  • --platforms
  • 指定平台组合
  • eg:--platforms=android,ios,web,MacOS,Windows,Linux,
  • --org
  • 指定包名
  • eg: --org com.example.hello

     

  • 默认命令
flutter create --org com.example.hello -t plugin --platforms=ios,android -i swift -a java hello


vscode创建

  • 创建plugin
  • 打开命令面板

flutter-plugin之创建与弥补_flutter

  • 选择Plugin

flutter-plugin之创建与弥补_iOS_02

  • 创建plugin

flutter-plugin之创建与弥补_flutter_03

  • 创建完成,但默认是没有指定平台

flutter-plugin之创建与弥补_iOS_04

 通过上面的创建,我们只是简单的创建Plugin.细心的小伙伴会发现,当我们使用vscode创建完成后,项目目录中和其他的是不一样的.我们缺少了对应的平台文件夹.下面我们一起来看一下怎么弥补.

弥补

命令弥补

  • iOS弥补
 flutter create -t plugin --platforms=ios -i swift .
  • 安卓弥补
 flutter create -t plugin --platforms=android -a java .
  • web弥补
 flutter create --template=plugin --platforms=web .

vscode弥补

  • 通过pubspec.yaml来添加指定平台
flutter:
plugin:
platforms:
android:
package: com.example.hello
pluginClass: HelloPlugin
ios:
pluginClass: HelloPlugin
  • 通过flutter create .即可创建添加的平台

flutter-plugin之创建与弥补_iOS_05

  通过上面的配置,我们已经完成了对应平台的添加,如果想修改平台的开发语言.可以使用下面的命令

flutter create -a jave -i objc .

参考资料

​flutter Packages的插件​


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  iD7FikcuyaVi   2023年11月30日   26   0   0 MacWindowsandroid
  b1UHV4WKBb2S   2023年11月13日   34   0   0 裁剪ideflutter
  b1UHV4WKBb2S   2023年11月13日   27   0   0 flutterDart
7nR2g7mlPvjr
作者其他文章 更多