Flutter

From j4flmao/agent-skills · View interactive version

Flutter is an AI agent skill from the GitHub repository j4flmao/agent-skills. Use when the user asks about a Flutter app, Riverpod, BLoC, Provider, go_router, widget rebuilds, jank, platform channels, golden tests, flavors or Flutter release builds. Produces Flutter project structure, state management choices, performance fixes and tests. Not for engine and rendering internal

How to use this skill

Skill file

Flutter

Purpose

Flutter renders its own UI from a declarative widget tree, so app quality depends on keeping rebuilds narrow, state ownership clear, and heavy work off the UI isolate. This skill provides the default architecture, state-management decision rules, current Riverpod/BLoC APIs, performance techniques and the testing pyramid for production Flutter apps.

Agent Protocol

Trigger

"Flutter", "widget rebuild", "Riverpod", "BLoC", "Provider", "go_router", "Flutter performance", "jank", "const widget", "platform channel", "golden test", "flavors".

Input Context

Output Artifact

Dart code, folder structure, pubspec.yaml changes, test code or a performance plan. No file unless requested.

Response Format

Flutter/Dart: {versions}
Layer: {UI | state | data | platform}
Change: {what and why}
Code: {snippet}
Verify: {flutter test / DevTools trace / golden diff}

1. Project Structure (feature-first)

lib/
  main.dart                 // ProviderScope / BlocProvider roots, app config per flavor
  app/router.dart           // go_router configuration
  features/orders/
    data/                   // DTOs, API clients, repositories (implementations)
    domain/                 // entities, repository interfaces, use cases (pure Dart)
    presentation/           // widgets, controllers/notifiers/blocs
  core/                     // theming, networking, error types, utils

Keep domain free of Flutter imports so it unit-tests without a device. See references/architecture.md.

2. Choosing State Management

| Option | Fits | Notes |

|--------|------|-------|

| setState / ValueNotifier | local, ephemeral widget state | do not lift everything into global state |

| Riverpod 3 | app-wide state, DI, async data, testability | compile-safe providers; Notifier/AsyncNotifier APIs |

| BLoC / Cubit (flutter_bloc) | teams wanting explicit events → states, strong tracing | more boilerplate; great for complex flows |

| Provider + ChangeNotifier | existing apps, simple DI | Riverpod is its successor by the same author |

Riverpod 3 (current API)

StateProvider, StateNotifierProvider and ChangeNotifierProvider are legacy in Riverpod 3 (importable from package:flutter_riverpod/legacy.dart). New code uses Notifier/AsyncNotifier:

import 'package:flutter_riverpod/flutter_riverpod.dart';

final counterProvider = NotifierProvider<Counter, int>(Counter.new);

class Counter extends Notifier<int> {
  @override
  int build() => 0;
  void increment() => state++;
}

final ordersProvider = AsyncNotifierProvider<OrdersController, List<Order>>(OrdersController.new);

class OrdersController extends AsyncNotifier<List<Order>> {
  @override
  Future<List<Order>> build() => ref.watch(orderRepositoryProvider).fetchOrders();

  Future<void> refresh() async {
    state = const AsyncLoading();
    state = await AsyncValue.guard(() => ref.read(orderRepositoryProvider).fetchOrders());
  }
}

class CounterText extends ConsumerWidget {
  const CounterText({super.key});
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final count = ref.watch(counterProvider);           // rebuilds only when the int changes
    return Text('Count: $count');
  }
}

BLoC

Use BlocBuilder with buildWhen, BlocSelector for slices, BlocListener for one-off effects; model states as a sealed class hierarchy and switch exhaustively.

3. Navigation

go_router for declarative, URL-based routing (deep links, web, redirects for auth guards); StatefulShellRoute for bottom-nav tabs with preserved stacks. Avoid mixing imperative Navigator.push and router-driven navigation for the same flows.

4. Performance

5. Platform Integration

6. Testing

| Level | Tool | Purpose |

|-------|------|---------|

| Unit | package:test, mocktail | domain/use cases, notifiers (ProviderContainer with overrides) |

| Widget | flutter_test (testWidgets, pumpWidget, finders) | UI behaviour without a device |

| Golden | matchesGoldenFile (or alchemist) | visual regressions; pin fonts/platform for stable images |

| Integration | integration_test (+ Patrol for native dialogs) | end-to-end on device/emulator |

See references/testing.md.

7. Builds and Releases

8. Anti-Patterns

| Anti-pattern | Problem | Fix |

|--------------|---------|-----|

| One giant build() with business logic | wide rebuilds, untestable | small widgets + notifiers/blocs |

| ref.read inside build | UI never updates | ref.watch |

| Using legacy StateProvider in new Riverpod 3 code | deprecated path | Notifier/AsyncNotifier |

| Heavy work in build or on the UI isolate | jank | precompute, Isolate.run |

| ! on nullable state in widgets | red-screen crashes | handle loading/error/empty states |

| setState after dispose | exceptions | check mounted, cancel subscriptions |

9. Checklist

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.