Skip to content
Flutter Architecture Best Practices

Flutter Architecture Best Practices Skill

The Flutter team's official skill for structuring an app in the recommended UI / Logic / Data layers, with MVVM view-models and the repository pattern.

GitHub Docs

Install

Install with the skills CLI

One command for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf and dozens of other agents. Needs Node.js; the skill is fetched straight from flutter/agent-plugins.

$ npx skills add flutter/agent-plugins --skill flutter-apply-architecture-best-practices

Run it in a terminal. The CLI finds the agents installed on your machine, asks which ones to add the skill to, and whether to install it into the folder you ran it from or for all your projects.

Other ways to install

Copy the whole skill folder — SKILL.md and any scripts or references beside it — into ~/.claude/skills/flutter-apply-architecture-best-practices/, where Claude Code picks it up in every project. Only git is needed.

tmp=$(mktemp -d) && \
  git clone --depth 1 --branch main https://github.com/flutter/agent-plugins.git "$tmp" && \
  mkdir -p ~/.claude/skills && \
  cp -R "$tmp"/skills/flutter-apply-architecture-best-practices ~/.claude/skills/flutter-apply-architecture-best-practices

No scripts or references next to it? Saving the SKILL.md alone as ~/.claude/skills/flutter-apply-architecture-best-practices/SKILL.md works too.

Using another agent? Its personal skills folder
Codex
~/.agents/skills/
Cursor
~/.cursor/skills/
GitHub Copilot
~/.copilot/skills/
Gemini CLI
~/.gemini/skills/
Windsurf
~/.codeium/windsurf/skills/
OpenCode
~/.config/opencode/skills/

About

  • Enforces UI / Logic / Data layer separation
  • MVVM view-models on ChangeNotifier with immutable state snapshots
  • Repository pattern with stateless services and clean domain models
  • Constructor injection of repositories into view-models
  • Project structure plus an end-to-end new-feature workflow
  • Applies to greenfield scaffolding and refactoring alike

Agents left to their own devices tend to write Flutter code that fetches data inside a widget's build method. It works, and then it does not scale. This skill, maintained by the Flutter team, gives the agent the architecture the framework's own guidance recommends and holds it to a strict separation of concerns.

The layers

UI layer. MVVM. Views stay lean and reusable, with logic limited to genuinely UI-level concerns — animation, layout constraints, simple routing — and all data passed in from the view-model. View-models extend ChangeNotifier (or another Listenable), expose immutable state snapshots, handle user interactions, and receive repositories through constructor injection.

Data layer. The repository pattern, so data access is isolated and there is a single source of truth. Services are stateless wrappers over HTTP clients, local databases and platform plugins, returning raw API models or Result wrappers. Repositories consume services, transform raw models into clean domain models, and own caching, offline synchronisation and retry logic.

Logic layer. Optional use cases for behaviour that spans repositories or would otherwise bloat a view-model.

Alongside the layer definitions it carries the project structure to lay out, a workflow for implementing a new feature end to end through the layers, and worked examples — useful either when scaffolding a new project or when refactoring an existing one that has outgrown its structure.

Part of the Flutter team's agent-plugins repository, which also covers integration tests, widget tests, widget previews, responsive layouts, layout debugging, JSON serialisation, declarative routing, localisation and the http package. BSD-3-Clause licensed; the Dart team maintains a companion collection for Dart-level tasks.

SKILL.md

The instructions your agent loads, as published by Flutter.

SKILL.md
name
flutter-apply-architecture-best-practices
description
Architects a Flutter application using the recommended layered approach (UI, Logic, Data). Use when structuring a new project or refactoring for scalability.
metadata
model: models/gemini-3.1-pro-preview last_modified: Tue, 21 Apr 2026 20:11:20 GMT

Architecting Flutter Applications

Contents
  • [Architectural Layers](#architectural-layers)
  • [Project Structure](#project-structure)
  • [Workflow: Implementing a New Feature](#workflow-implementing-a-new-feature)
  • [Examples](#examples)
Architectural Layers

Enforce strict Separation of Concerns by dividing the application into distinct layers. Never mix UI rendering with business logic or data fetching.

UI Layer (Presentation)

Implement the MVVM (Model-View-ViewModel) pattern to manage UI state and logic.

  • Views: Write reusable, lean widgets. Restrict logic in Views to UI-specific operations (e.g., animations, layout constraints, simple routing). Pass all required data from the ViewModel.
  • ViewModels: Manage UI state and handle user interactions. Extend ChangeNotifier (or use Listenable) to expose state. Expose immutable state snapshots to the View. Inject Repositories into ViewModels via the constructor.
Data Layer

Implement the Repository pattern to isolate data access logic and create a single source of truth.

  • Services: Create stateless classes to wrap external APIs (HTTP clients, local databases, platform plugins). Return raw API models or Result wrappers.
  • Repositories: Consume one or more Services. Transform raw API models into clean Domain Models. Handle caching, offline synchronization, and retry logic. Expose Domain Models to ViewModels.
Logic Layer (Domain - Optional)
  • Use Cases: Implement this layer only if the application contains complex business logic that clutters the ViewModel, or if logic must be reused across multiple ViewModels. Extract this logic into dedicated Use Case (interactor) classes that sit between ViewModels and Repositories.
Project Structure

Organize the codebase using a hybrid approach: group UI components by feature, and group Data/Domain components by type.

lib/
├── data/
│   ├── models/         # API models
│   ├── repositories/   # Repository implementations
│   └── services/       # API clients, local storage wrappers
├── domain/
│   ├── models/         # Clean domain models
│   └── use_cases/      # Optional business logic classes
└── ui/
    ├── core/           # Shared widgets, themes, typography
    └── features/
        └── [feature_name]/
            ├── view_models/
            └── views/
Workflow: Implementing a New Feature

Follow this sequential workflow when adding a new feature to the application. Copy the checklist to track progress.

Task Progress
  • [ ] Step 1: Define Domain Models. Create immutable data classes for the feature using freezed or built_value.
  • [ ] Step 2: Implement Services. Create or update Service classes to handle external API communication.
  • [ ] Step 3: Implement Repositories. Create the Repository to consume Services and return Domain Models.
  • [ ] Step 4: Apply Conditional Logic (Domain Layer).
  • If the feature requires complex data transformation or cross-repository logic: Create a Use Case class.
  • If the feature is a simple CRUD operation: Skip to Step 5.
  • [ ] Step 5: Implement the ViewModel. Create the ViewModel extending ChangeNotifier. Inject required Repositories/Use Cases. Expose immutable state and command methods.
  • [ ] Step 6: Implement the View. Create the UI widget. Use ListenableBuilder or AnimatedBuilder to listen to ViewModel changes.
  • [ ] Step 7: Inject Dependencies. Register the new Service, Repository, and ViewModel in the dependency injection container (e.g., provider or get_it).
  • [ ] Step 8: Run Validator. Execute unit tests for the ViewModel and Repository.
  • Feedback Loop: Run tests -> Review failures -> Fix logic -> Re-run until passing.
Examples
Data Layer: Service and Repository
// 1. Service (Raw API interaction)
class ApiClient {
  Future<UserApiModel> fetchUser(String id) async {
    // HTTP GET implementation...
  }
}

// 2. Repository (Single source of truth, returns Domain Model)
class UserRepository {
  UserRepository({required ApiClient apiClient}) : _apiClient = apiClient;
  
  final ApiClient _apiClient;
  User? _cachedUser;

  Future<User> getUser(String id) async {
    if (_cachedUser != null) return _cachedUser!;
    
    final apiModel = await _apiClient.fetchUser(id);
    _cachedUser = User(id: apiModel.id, name: apiModel.fullName); // Transform to Domain Model
    return _cachedUser!;
  }
}
UI Layer: ViewModel and View
// 3. ViewModel (State management and presentation logic)
class ProfileViewModel extends ChangeNotifier {
  ProfileViewModel({required UserRepository userRepository}) 
      : _userRepository = userRepository;

  final UserRepository _userRepository;

  User? _user;
  User? get user => _user;

  bool _isLoading = false;
  bool get isLoading => _isLoading;

  Future<void> loadProfile(String id) async {
    _isLoading = true;
    notifyListeners();

    try {
      _user = await _userRepository.getUser(id);
    } finally {
      _isLoading = false;
      notifyListeners();
    }
  }
}

// 4. View (Dumb UI component)
class ProfileView extends StatelessWidget {
  const ProfileView({super.key, required this.viewModel});

  final ProfileViewModel viewModel;

  @override
  Widget build(BuildContext context) {
    return ListenableBuilder(
      listenable: viewModel,
      builder: (context, _) {
        if (viewModel.isLoading) {
          return const Center(child: CircularProgressIndicator());
        }
        
        final user = viewModel.user;
        if (user == null) {
          return const Center(child: Text('User not found'));
        }

        return Column(
          children: [
            Text(user.name),
            ElevatedButton(
              onPressed: () => viewModel.loadProfile(user.id),
              child: const Text('Refresh'),
            ),
          ],
        );
      },
    );
  }
}
Install

Skill: Google Maps Platform

by Google Maps Platform

Featured

Google's official agent skill for writing production Maps Platform code — grounded in freshly fetched docs, with a demo key path that needs no billing account.

Browse all skills →