Flutter 项目结构的区别

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1. 如果需要调用原生代码,请创建一个plugin类型的项目开发。 2. 如果需要调用C语言,请参考文档:Flutter项目中调用C语言 3. plugin 其实是 package 的一种,全称是 plugin package,我们简称为 plugin,中文叫插件。 |

1. Application

Flutter Application 表示一个Flutter项目,主体是Flutter,当然它也可以接入Android Module 或者 iOS Framework,其内部包含 Android 和 iOS 项目。

其目录结构如下:

目录 描述 备注
android Android原生代码目录。 其实就是一个内嵌的Android工程
ios iOS原生代码目录。 其实就是一个内嵌的iOS工程 可以通过xcode 打开 Runner.xcworkspace 进行项目配置
lib 这个是Flutter项目的核心目录,我们写的代码放在这个目录,我们也可以在这个目录创建子目录。
test 测试代码目录。
pubspec.yaml 这个是Flutter项目的依赖配置文件,类似于Android build.gradle文件,这里面包含了Flutter SDK 版本、依赖等。

2. Plugin

Flutter Plugin表示 Flutter 插件,包含 Android 和 iOS 项目,如果你要开发一个 Plugin 且此 Plugin 涉及到原生支持,比如蓝牙功能、网络功能等,这些功能纯 Flutter 是无法实现的。

其目录比 Flutter Application 多了一个 example,example用于当前 Plugin 的demo, Flutter Plugin 开发完成后可以发布到 pub 上。

其目录结构如下:

其pubspec.ymal中多了关于该插件的名称,描述,版本等信息

|----------------------------------------------------------------------------------------|
| 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 |

3. Package

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

其目录结构如下:

4. Module

Flutter Module 用于原生项目中插入 Flutter 模块,原生为主体,与 Flutter 进行混合开发。

其目录结构如下:

5. 参考指令

flutter create 指令用法说明

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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 (https://api.flutter.dev/). An example can be found at: https://api.flutter.dev/flutter/widgets/SingleChild ScrollView-class.html -e, --[no-]empty Specifies creating using an application template with a main.dart that is minimal, including no comments, as a starting point for a new application. Implies "--template=app". --list-samples=<path> Specifies a JSON output file for a listing of Flutter code samples that can be created with "--sample". |

例如创建一个插件

|-------------------------------------------------|
| flutter create --template=package hello |

相关推荐
见山是山-见水是水2 小时前
鸿蒙版 Flutter Video 视频播放组件:播放控制、全屏切换与倍速播放
flutter·音视频·harmonyos
六年码农5 小时前
2026最新开源 屏译ScreenTranslator 0.4.4 开源 全屏实时翻译教程
运维·人工智能·flutter·开源
恋猫de小郭9 小时前
超好用 R8 Configuration Analyzer, 优化你的 App 大小和内存
android·前端·flutter
键盘飞行员1 天前
Flutter App 全套实战学习计划:从零搭建到 APK 部署
学习·flutter
GitLqr1 天前
Flutter 实战:图片上传前的压缩优化,解决带宽与存储的“大户”问题
flutter·全栈·dart
进哥AI研习社1 天前
AtomCode 跨端开发实战:Flutter 项目从原型到多端运行的 AI 驱动体验
人工智能·flutter
恋猫de小郭1 天前
Flutter A2UI 的正确用法,怎么把 AI 和动态 UI 结合有效生产
android·前端·flutter
年小个大2 天前
受 go-zero 启发,我给 Flutter 整了套 MVI-BLoC 脚手架
android·flutter·架构
Zender Han2 天前
Flutter 自适应(Adaptive)与响应式(Responsive)设计实践:官方推荐方案详解
android·flutter·ios
恋猫de小郭2 天前
社区版 Dart macros?一个可以解决 JSON 序列化的Fluter “宏编程”第三方包
android·前端·flutter