|
| 1 | +--- |
| 2 | +name: "flutter-creating-projects" |
| 3 | +description: "Creates a new Flutter project using the CLI or an IDE. Use when initializing a new application, package, or plugin and understanding the generated project structure." |
| 4 | +metadata: |
| 5 | + model: "models/gemini-3.1-pro-preview" |
| 6 | + last_modified: "Sun, 22 Mar 2026 07:50:00 GMT" |
| 7 | + |
| 8 | +--- |
| 9 | +# Creating a New Project in Flutter |
| 10 | + |
| 11 | +## Contents |
| 12 | +- [Core Concepts](#core-concepts) |
| 13 | +- [Architecture and Data Flow](#architecture-and-data-flow) |
| 14 | +- [Workflow: Creating a Project with the CLI](#workflow-creating-a-project-with-the-cli) |
| 15 | +- [Workflow: Creating a Project with an IDE](#workflow-creating-a-project-with-an-ide) |
| 16 | +- [Examples](#examples) |
| 17 | + |
| 18 | +## Core Concepts |
| 19 | + |
| 20 | +Flutter development begins with creating a project structure that contains all necessary code, assets, and platform-specific configurations. |
| 21 | + |
| 22 | +* **Project Types:** Flutter supports multiple project types depending on your goal: |
| 23 | + * **Application (`app`):** A standard Flutter app for mobile, web, or desktop. |
| 24 | + * **Package (`package`):** A reusable Dart library (e.g., a state management utility). |
| 25 | + * **Plugin (`plugin`):** A package that includes native code for platform-specific integration (e.g., accessing camera APIs). |
| 26 | + * **Module (`module`):** A Flutter component designed to be embedded into an existing native app (Add-to-App). |
| 27 | +* **Creation Tools:** Projects can be initialized via the **Flutter CLI** (platform-agnostic) or **IDE Wizards** (VS Code, Android Studio, IntelliJ). |
| 28 | + |
| 29 | +## Architecture and Data Flow |
| 30 | + |
| 31 | +When a project is created, Flutter generates a standard directory structure. Understanding this structure is essential for organizing code and resources. |
| 32 | + |
| 33 | +* **`lib/`**: The heart of the project. Contains Dart source code. `main.dart` is the default entry point. |
| 34 | +* **`pubspec.yaml`**: The project's manifest. Manages dependencies, assets (images, fonts), and versioning. |
| 35 | +* **`test/`**: Contains automated unit, widget, and integration tests. |
| 36 | +* **`android/`, `ios/`, `web/`, `linux/`, `macos/`, `windows/`**: Platform-specific "runners" that host the Flutter engine and handle native integration. |
| 37 | +* **`analysis_options.yaml`**: Configures linting rules for the project. |
| 38 | + |
| 39 | +## Workflow: Creating a Project with the CLI |
| 40 | + |
| 41 | +Use the Flutter CLI for precise control over project initialization and platform support. |
| 42 | + |
| 43 | +1. **Open the Terminal** and navigate to your workspace. |
| 44 | +2. **Run `flutter create`**: |
| 45 | + * Basic command: `flutter create my_app_name` |
| 46 | + * Specify platforms: `flutter create --platforms=ios,android,web my_app_name` |
| 47 | + * Specify project type: `flutter create --template=plugin my_plugin_name` |
| 48 | + * Specify organization (package name): `flutter create --org com.example my_app` |
| 49 | +3. **Navigate to the directory**: `cd my_app_name` |
| 50 | +4. **Verify the setup**: Run `flutter doctor` to ensure your environment is ready for the selected platforms. |
| 51 | + |
| 52 | +## Workflow: Creating a Project with an IDE |
| 53 | + |
| 54 | +IDEs provide a visual, guided experience for project creation. |
| 55 | + |
| 56 | +### Visual Studio Code |
| 57 | +1. Open the **Command Palette** (`Ctrl+Shift+P` or `Cmd+Shift+P`). |
| 58 | +2. Type `Flutter: New Project` and press Enter. |
| 59 | +3. Select the **Application** template (or another type). |
| 60 | +4. Choose a parent folder for the project. |
| 61 | +5. Enter the project name and press Enter. |
| 62 | + |
| 63 | +### Android Studio / IntelliJ |
| 64 | +1. Select **New Flutter Project** from the Welcome screen or `File > New > New Project`. |
| 65 | +2. Select **Flutter** in the left sidebar. |
| 66 | +3. Ensure the **Flutter SDK path** is correct and click Next. |
| 67 | +4. Enter the Project name, location, and select supported platforms. |
| 68 | +5. Click **Finish**. |
| 69 | + |
| 70 | +## Examples |
| 71 | + |
| 72 | +### Basic Application Creation (CLI) |
| 73 | +Initialize a project for mobile and web with a custom organization name. |
| 74 | + |
| 75 | +```bash |
| 76 | +flutter create --org com.mycompany --platforms=android,ios,web my_awesome_app |
| 77 | +``` |
| 78 | + |
| 79 | +### Creating a Dart Package (CLI) |
| 80 | +Initialize a reusable library without platform-specific code. |
| 81 | + |
| 82 | +```bash |
| 83 | +flutter create --template=package my_utility_library |
| 84 | +``` |
| 85 | + |
| 86 | +### Project Structure Checklist |
| 87 | +After creation, verify the presence of these key files: |
| 88 | +- [ ] `lib/main.dart` (entry point) |
| 89 | +- [ ] `pubspec.yaml` (dependency management) |
| 90 | +- [ ] `analysis_options.yaml` (linting) |
| 91 | +- [ ] Platform folders for your targets (e.g., `android/`, `ios/`) |
0 commit comments