使用flutter create --help指令
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/SingleChild
ScrollView-class.html
--list-samples=<path> Specifies a JSON output file for a listing of
Flutter code samples that can be created with
"--sample".
flutter create 参数详解
create
创建工程,flutter create prj_name,创建一个名为"prj_name"的工程
org
指定工程的包名和bundle Id
例子:flutter create --org xx.xx prj_name,创建一个名为"prj_name"的工程,包名、bundle Id为xx.xx
platforms
指定工程的支持的平台
例子:flutter create --platforms ios,android prj_name,创建一个名为"prj_name"的工程,指定平台为iOS和android。
Flutter3.0支持的平台有:ios/android/web/windows/macos/linux,默认创建所有平台
language
指定创建各个平台所使用的语言
-i,指定iOS的开发语言,支持objc和swift,默认是swift
-a,指定android的开发语言,支持java和kotlin,默认是kotlin
例子:flutter create -a java -i objc prj_name,创建一个名为"prj_name"的工程,指定iOS开发语言为objc,android开发语言为java
template
指定创建工程的类型
flutter 3.0支持创建6种类型,app/module/package/plugin/plugin_ffi/skeleton,默认为app
例子:flutter create -t plugin prj_name,创建一个名为"prj_name"的工程,指定类型为plugin
常用组合
创建项目:
flutter create --org xx.xx --platforms ios,android -i objc -a java prj_name
创建plugin插件:
flutter create --org xx.xx --platforms ios,android -i objc -a java -t plugin prj_name
flutter的iOS或者原生工程不能正常运行,可采用以下方法重新创建
原理是删除旧的原生项目,重新创建,在命令行下执行以下操作
1、进入工程目录,删除android目录:rm -rf android
2、创建java语言的android目录:flutter create -a java .
3、删除ios目录:rm -rf ios
4、重新创建指定swift语言的ios目录:flutter create -i swift .
5、进行一些原生项目的配置,如包名、icon、权限等