| name | mobile-flutter-project-setup |
|---|---|
| description | Create a new Flutter project with recommended structure, linting, and packages. Covers flutter create, directory conventions, analysis_options.yaml, pubspec.yaml management, and flavors. Use when the user wants to start a new Flutter app. |
| standards-version | 1.6.3 |
Use this skill when the user:
- Wants to create a new Flutter app from scratch
- Asks how to set up a Flutter project with good structure
- Needs help with
flutter createoptions - Wants recommended project structure or directory conventions
- Mentions "flutter create", "new Flutter project", "Flutter scaffold", or "Dart project"
- App name: lowercase_with_underscores (Dart package naming convention)
- Platforms (optional): ios, android, web, macos, linux, windows (defaults to ios + android)
- Organization (optional): reverse domain for bundle ID (e.g.
com.example)
-
Verify Flutter SDK. Confirm Flutter is installed and on the PATH:
flutter --version flutter doctor
If not installed, direct the user to flutter.dev/get-started. Minimum Flutter 3.22+ recommended for latest features.
-
Create the project.
flutter create --org com.example --platforms ios,android my_app cd my_appFor an empty starting point (no counter demo):
flutter create --empty --org com.example my_app
-
Set up recommended directory structure. Reorganize
lib/:lib/ ├── main.dart # Entry point, app config ├── app.dart # MaterialApp / GoRouter setup ├── core/ │ ├── constants.dart # App-wide constants │ ├── theme.dart # ThemeData definitions │ ├── router.dart # GoRouter configuration │ └── extensions/ # Dart extension methods ├── features/ │ ├── auth/ │ │ ├── data/ # Repositories, data sources │ │ ├── domain/ # Models, entities │ │ └── presentation/ # Screens, widgets │ ├── home/ │ │ ├── data/ │ │ ├── domain/ │ │ └── presentation/ │ └── settings/ │ └── presentation/ └── shared/ ├── widgets/ # Reusable UI components ├── utils/ # Helper functions └── services/ # API clients, storage, etc.This is the feature-first architecture. Each feature is self-contained with its own data, domain, and presentation layers.
-
Configure linting. Replace the default
analysis_options.yaml:include: package:flutter_lints/flutter.yaml analyzer: errors: missing_required_param: error missing_return: error exclude: - "**/*.g.dart" - "**/*.freezed.dart" linter: rules: prefer_const_constructors: true prefer_const_declarations: true prefer_final_locals: true avoid_print: true require_trailing_commas: true sort_constructors_first: true unawaited_futures: true prefer_single_quotes: true
Install the lints package:
flutter pub add --dev flutter_lints
-
Add recommended base packages.
# Navigation flutter pub add go_router # State management (pick one) flutter pub add flutter_riverpod riverpod_annotation flutter pub add --dev riverpod_generator build_runner # Code generation (immutable models) flutter pub add freezed_annotation json_annotation flutter pub add --dev freezed json_serializable build_runner # Environment config flutter pub add flutter_dotenv
Run code generation after adding freezed/riverpod_generator:
dart run build_runner build --delete-conflicting-outputs
-
Set up flavors (optional). For dev/staging/prod environments:
Create
lib/core/env.dart:enum Env { dev, staging, prod } class EnvConfig { final String apiBaseUrl; final Env env; const EnvConfig({required this.apiBaseUrl, required this.env}); static const dev = EnvConfig( apiBaseUrl: 'https://api-dev.example.com', env: Env.dev, ); static const staging = EnvConfig( apiBaseUrl: 'https://api-staging.example.com', env: Env.staging, ); static const prod = EnvConfig( apiBaseUrl: 'https://api.example.com', env: Env.prod, ); }
Create separate entry points:
lib/main_dev.dart # runApp with EnvConfig.dev lib/main_staging.dart # runApp with EnvConfig.staging lib/main.dart # runApp with EnvConfig.prodRun with a specific flavor:
flutter run -t lib/main_dev.dart
-
Configure VS Code / Cursor. Add
.vscode/settings.json:{ "editor.formatOnSave": true, "dart.lineLength": 80, "[dart]": { "editor.defaultFormatter": "Dart-Code.dart-code", "editor.rulers": [80], "editor.selectionHighlight": false, "editor.suggestSelection": "first", "editor.tabCompletion": "onlySnippets", "editor.wordBasedSuggestions": "off" } }
- Flutter: Get started
- Flutter project structure
- Dart package naming conventions
- flutter_lints
- GoRouter
- Riverpod
- Freezed
User: "I want to create a new Flutter app for a fitness tracker."
Agent:
- Verifies Flutter SDK with
flutter doctor - Runs
flutter create --org com.example --platforms ios,android fitness_tracker - Restructures
lib/into feature-first layout withfeatures/workouts/,features/profile/,features/stats/ - Adds
analysis_options.yamlwith strict linting - Installs go_router, flutter_riverpod, freezed
- Creates
core/theme.dartwith Material 3 fitness-themed colors - Sets up
.vscode/settings.jsonfor Dart formatting
| Step | MCP Tool | Description |
|---|---|---|
| Check environment | mobile_checkDevEnvironment |
Verify Flutter SDK, Dart, Android SDK, Xcode are installed |
| Check build | mobile_checkBuildHealth |
Verify the project builds after setup |
- Not using
--emptyflag - The default counter app template adds boilerplate that most developers delete immediately. Use--emptyfor a clean start. - Flat
lib/structure - Putting all files directly inlib/becomes unmanageable past 10 files. Use feature-first structure from day one. - Ignoring
analysis_options.yaml- Default rules are too lenient. Enableprefer_const_constructors,require_trailing_commas, andavoid_printearly. - Forgetting
--delete-conflicting-outputs-build_runnerwill fail on subsequent runs without this flag. Always use it. - Wrong package name format - Dart packages must be
lowercase_with_underscores. No hyphens, no camelCase. - Missing
.gitignoreentries - Ensure*.g.dart,*.freezed.dart, and.dart_tool/are NOT in.gitignore(generated files should be committed for CI). Butbuild/and.dart_tool/should be ignored.
- Flutter Navigation - GoRouter setup after project creation
- Flutter State Management - Riverpod/Bloc patterns
- Flutter Run on Device - deploying to physical hardware