使用终端创建flutter项目

配置环境后,在vscode中创建flutter项目 

flutter create 项目名称

这会默认创建可以构建6端(android、ios、windows、macos、web、linux)的项目,但有时候我们并不需要这么多平台,所以可以:

flutter create 项目名称 --template=app --platforms=android --platforms=ios

这样子就可以创建适配android和ios的项目了。

有更多的需求的话,可以研读一下

flutter create -h
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.
    --enable-analytics      Enable telemetry reporting each time a flutter or dart command runs.
    --disable-analytics     Disable telemetry reporting each time a flutter or dart command runs, until it is re-enabled.
    --suppress-analytics    Suppress analytics reporting for the current CLI invocation.

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 (https://api.flutter.dev/). An example can be found at:
                             https://api.flutter.dev/flutter/widgets/SingleChildScrollView-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". 

Run "flutter help" to see global options.

使用VSCode创建一个新的Flutter项目非常简单。首先需要确保您已经安装了Flutter和VSCode,以及Flutter插件。然后按照以下步骤操作: 1. 打开VSCode并点击左侧的“扩展”选项卡。 2. 在搜索框中输入“Flutter”并找到Flutter插件。点击“安装”。 3. 安装完成后,重新启动VSCode。现在您应该能够看到菜单栏中有一个“Flutter: New Project”选项。 4. 单击此选项,输入项目名称,并选择要创建的目录。 5. 接下来,VSCode将提示您选择Flutter模板。选择“Flutter: New Application”以创建一个全新的Flutter应用程序。 6. 完成模板选择后,VSCode会生成新项目的骨架代码。这需要一点时间,视您的计算机速度而定。 7. 一旦骨架代码生成完成,您将会看到一个“main.dart”文件。这是您新创建的应用程序的入口点。 8. 您现在可以开始构建您的应用程序了。在VSCode终端中键入“flutter run”命令,它将编译和运行您的应用程序。 9. 您可以在应用程序的“lib/main.dart”文件中进行更改来构建您的应用程序。保存文件后,VSCode会自动重新编译您的应用程序,并将更改推送到运行中的应用程序中。 总之,使用VSCode创建一个新的Flutter项目是非常简单的,只需几个简单的步骤就能完成。在您的计算机上安装了Flutter和VSCode及其插件之后,您可以轻松地开始构建您的应用程序并让它运行起来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值