跳转至正文

创建新的 Flutter 应用

了解如何从命令行、不同编辑器甚至云端引导创建新的 Flutter 应用。

本页提供在你首选开发环境中引导创建新 Flutter 应用的分步说明。

要创建新 Flutter 应用,请先 set up Flutter(设置 Flutter),然后选择首选环境并遵循相应说明。

VS Code

#

To create a Flutter app with VS Code and other Code OSS-based editors, you first need to install Flutter and set up VS Code for Flutter development. Then follow these steps:

  1. Launch VS Code

    Open VS Code or your preferred Code OSS-based editor.

  2. Open the command palette

    Go to View > Command Palette or press Cmd/Ctrl + Shift + P.

  3. Find the Flutter commands

    在命令面板中输入 flutter:,VS Code 应显示 Flutter 插件命令。

  4. Run the new project command

    选择 Flutter: New Project 命令;系统或 VS Code 可能请求文档访问权限,同意以继续。

  5. Choose a template

    VS Code 会提示 Which Flutter template?;根据项目类型选择模板,新建应用选 Application

  6. Select a project location

    将出现文件对话框;选择或创建父目录(勿自行创建项目文件夹)。点击 Select a folder to create the project in 确认。

  7. Enter a project name

    VS Code 会提示输入项目名称;按 lowercase_with_underscoresEffective Dart 输入名称,按 Enter 确认。

  8. Wait for project initialization

    VS Code 根据输入用 flutter create 引导应用;进度常在右下角通知或 Output 面板显示。

  9. Run your app

    新应用应已在 VS Code 中打开;试运行请按 run and debug 步骤操作。

你已在 VS Code 中成功创建新的 Flutter 应用!更多帮助请参阅 VS Code for Flutter reference

Android Studio

#

要使用 Android Studio 创建 Flutter 应用,请先 install Flutterset up Android Studio(配置 Android Studio),然后按以下步骤操作:

  1. Launch Android Studio

    Open Android Studio with the Dart and Flutter plugins installed.

打开已安装 Dart 与 Flutter 插件的 Android Studio。

  1. Begin project creation

    If you're on the IDE welcome dialog that says Welcome to Android Studio, find and click the New Flutter Project button in the center.

若在显示 Welcome to Android Studio 的欢迎对话框,点击中央的 New Flutter Project 按钮。

若已有打开的项目,可关闭或前往 File > New > New Flutter Project...

  1. Choose a project type

    In the New Project dialog, under Generators in the left panel, select Flutter.

New Project 对话框左侧 Generators 下选择 Flutter

  1. Verify Flutter SDK setup

    At the top of the right panel, ensure the Flutter SDK path value matches the location of the Flutter SDK you'd like to develop with. If not, update it by choosing or specifying the correct one.

在右侧面板顶部确保 Flutter SDK path 与欲使用的 Flutter SDK 位置一致,否则请选择或指定正确路径。

  1. Configure your project

    Click Next to continue to project configuration. Multiple configuration options should appear.

点击 Next 继续项目配置,将出现多个配置选项。

Project name 字段输入符合 lowercase_with_underscores 规范的应用名称,遵循 Effective Dart 指南。

若并非创建 application,从 Project type 下拉框选择其他模板。

若未来可能发布应用,将 Organization 字段 设为公司域名

其他字段可保持默认或按项目需要配置。

  1. Finish project creation

    Once you've completed the configuration of your project, click Create to begin project initialization.

完成项目配置后,点击 Create 开始初始化。

  1. Wait for workspace initialization

    Android Studio will now initialize your workspace, bootstrap your project file structure, and retrieve your app's dependencies. This might take a while and can be tracked at the bottom of the window.

Android Studio 将初始化工作区、引导项目结构并获取依赖,可能耗时,可在窗口底部查看进度。

  1. Run your app

    Your new app should now be created and open in Android Studio. To try your new app, follow the steps to run and debug in Android Studio.

新应用应已创建并在 Android Studio 中打开;试运行请按 run and debug 步骤操作。

你已在 Android Studio 中成功创建新的 Flutter 应用!更多帮助请参阅 Android Studio for Flutter reference

IntelliJ

#

要使用 IntelliJ 或其他 JetBrains IDE 创建 Flutter 应用,请先 install Flutterset up IntelliJ,然后按以下步骤操作:

  1. Launch IntelliJ

    Open IntelliJ IDEA or your preferred IntelliJ-based IDE by JetBrains that has the Dart and Flutter plugins installed.

  2. Begin project creation

    If you're on the IDE welcome dialog that says Welcome to IntelliJ IDEA, find and click the New Project button in the upper right corner.

若在 Welcome to IntelliJ IDEA 欢迎对话框,点击右上角 New Project 按钮。

If you already have a project open, either close it or go to File > New > New Project....

  1. Choose a project type

    In the New Project dialog, under Generators in the left panel, select Flutter.

New Project 对话框左侧 Generators 下选择 Flutter

  1. Verify Flutter SDK setup

    At the top of the right panel, ensure the Flutter SDK path value matches the location of the Flutter SDK you'd like to develop with. If not, update it by choosing or specifying the correct one.

在右侧面板顶部确保 Flutter SDK path 与欲使用的 Flutter SDK 位置一致,否则请选择或指定正确路径。

  1. Configure your project

    Click Next to continue to project configuration. Multiple configuration options should appear.

点击 Next 继续项目配置,将出现多个配置选项。

Project name 字段输入符合 lowercase_with_underscores 规范的应用名称,遵循 Effective Dart 指南。

若并非创建 application,从 Project type 下拉框选择其他模板。

若未来可能发布应用,将 Organization 字段 设为公司域名

其他字段可保持默认或按项目需要配置。

  1. Finish project creation

    Once you've completed the configuration of your project, click Create to begin project initialization.

完成项目配置后,点击 Create 开始初始化。

  1. Wait for workspace initialization

    IntelliJ will now initialize your workspace, bootstrap your project file structure, and retrieve your app's dependencies. This might take a while and can be tracked at the bottom of the window.

IntelliJ 将初始化工作区、引导项目结构并获取依赖,可能耗时,可在窗口底部查看进度。

  1. Run your app

    Your new app should now be created and open in IntelliJ. To try your new app, follow the steps to run and debug in IntelliJ.

新应用应已在 IntelliJ 中创建并打开;试运行请按 run and debug 步骤操作。

你已在 IntelliJ 中成功创建新的 Flutter 应用!更多帮助请参阅 IntelliJ for Flutter reference

Antigravity

#

To create a Flutter app with Antigravity, you first need to install and set up Antigravity as described on the Antigravity tools page. Then follow these steps:

  1. Open Antigravity and create a Workspace

    Launch the Antigravity IDE and create a new, sandboxed workspace for your project using the Agent Manager.

  2. Use the Agent Manager

    Switch to the Agent Manager interface, which is where you interact with the AI agents by using chat.

  3. Write detailed prompts

    Communicate your app requirements to the agent using detailed, structured prompts, much like providing instructions to a junior developer. For example, "Create a new Flutter project named my_app. Add a home screen with a list of items and a floating action button".

  4. Review and approve the plan

    The AI agent will generate a detailed implementation plan, including folder structure, dependencies, and steps. You can review this plan and click Proceed or provide feedback to make changes.

  5. Authorize actions

    The agent will ask for permission before running terminal commands (like flutter pub add or flutter create) or accessing the browser/emulator. Review and Accept these actions to allow the agent to build the app.

  6. Iterate and refine

    Once the initial app is generated, you can provide further prompts to add features, refine the UI, implement logic, or add persistence (for example, "Add local storage using shared_preferences").

  7. Test the app

    Use the integrated emulator or connect a physical device to test the app. The agent can even run tests and provide video walkthroughs of the functionality.

  8. Verify code in the editor

    You can switch to the standard code editor view at any time to inspect the generated Dart and Flutter files, ensuring the code quality meets your standards.

终端

#

To create a Flutter app in your terminal, you first need to install and set up Flutter. Then follow these steps:

  1. Open your terminal

    Open your preferred method to access the command line, such as Terminal on macOS or PowerShell on Windows.

  2. Ensure your current working directory is the desired parent directory for your new app. Don't create the project folder, the flutter tool will do so.

  3. Configure project creation

    In your terminal, type out the flutter create command and pass in any desired flags and options to configure your project. For example, to create an app with a minimal main.dart file, you can add the --empty option:

    flutter create --empty
    

    To learn about the available creation options, run flutter create --help in another terminal window.

  4. Enter a project name

    As the only non-option argument to flutter create, specify the directory and default name for your application. The name should follow the lowercase_with_underscores naming convention, following the Effective Dart guidelines.

    例如要创建名为 my_app 的应用:

    flutter create my_app
    
  5. Execute the configured command

    To create a project with your specified configuration, run the command you built in the previous step.

  6. Wait for project initialization

    The flutter tool will now bootstrap your project's file structure and retrieve any necessary dependencies. This might take a while.

  7. Now that your project has been created, you can navigate to it in your terminal or your preferred editor. For example, with a bash shell and a project named my_app:

    cd my_app
    
  8. Run your app

    To try your new app, run the flutter run command in your terminal and respond to its prompts to select an output device.

You've successfully created a new Flutter app in your terminal! If you need help configuring your project or with the flutter CLI tool, check out the Flutter CLI reference.