Flutter 中Application、Plugin、Pack

2023-02-27  本文已影响0人  张_何

Flutter Application

Flutter Application 表示一个Flutter项目,主体是Flutter,当然它也可以接入Android Module 或者 iOS Framework,其内部包含 Android 和 iOS 项目(默认情况下,以后正式支持Web、Windows、Mac等系统后可能更多),其目录结构如下:


目录结构

其中各个目录说明如下:

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

Flutter Plugin

Flutter Plugin表示 Flutter 插件,包含 Android 和 iOS 项目,如果你要开发一个 Plugin 且此 Plugin 涉及到原生支持,比如蓝牙功能、网络功能等,这些功能纯 Flutter 是无法实现的。
其目录比 Flutter Application 多了一个 example,example用于当前 Plugin 的demo, Flutter Plugin 开发完成后可以发布到 pub 上。
其目录结构如下:


目录结构
name: plugin_demo
description: A new Flutter project.
version: 0.0.1
homepage:

此外还多了此插件关于平台的配置:

  # This section identifies this Flutter project as a plugin project.
  # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.)
  # which should be registered in the plugin registry. This is required for
  # using method channels.
  # The Android 'package' specifies package in which the registered class is.
  # This is required for using method channels on Android.
  # The 'ffiPlugin' specifies that native code should be built and bundled.
  # This is required for using `dart:ffi`.
  # All these are used by the tooling to maintain consistency when
  # adding or updating assets for this project.
  plugin:
    platforms:
      android:
        package: com.example.plugin_demo
        pluginClass: PluginDemoPlugin
      ios:
        pluginClass: PluginDemoPlugin

Flutter Package

Flutter Package 和 Flutter Plugin 基本一样,唯一的区别是Flutter Package表示纯 Flutter 模块,不需要原生开发,没有Android 和 iOS 项目,比如开发一个纯 UI 的插件。
其目录结构如下:


目录结构

Flutter Module

Flutter Module 用于原生项目中插入 Flutter 模块,原生为主体,与 Flutter 进行混合开发。
其目录结构如下:


目录结构

创建一个带有example的package

上一篇下一篇

猜你喜欢

热点阅读