Poorgramer-Zack/dart-expert-skills / skills/flutter-expert
building-flutter-production-apps
VerifiedExpert-level guidance for Flutter production applications: architecture decisions (Clean/Layered/Hexagonal/Feature-First), advanced state management (BLoC/Riverpod/GetX), performance optimization (eliminating jank, memory profiling, reducing rebuild overhead), code review with design pattern enforcement, scalability assessments, native platform integration (MethodChannel/EventChannel/FFI), complex UI challenges (custom render objects, slivers), testing strategies (unit/widget/integration/golden), CI/CD pipeline architecture, build optimization, and accessibility compliance. Triggers: 'architecture decision', 'design pattern', 'performance issue', 'code review', 'production problem', 'scaling concerns', 'best practices', 'technical debt', 'refactoring strategy'. Essential for complex enterprise apps, critical production debugging, architectural refactors, or when choosing between competing technical approaches.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.3 KB |
| references/accessibility.md | markdown | 6.7 KB |
| references/animation.md | markdown | 9.9 KB |
| references/app-size.md | markdown | 5.1 KB |
| references/architecture-decision-matrix.md | markdown | 16.2 KB |
| references/architecture.md | markdown | 7.0 KB |
| references/caching.md | markdown | 8.4 KB |
| references/concurrency.md | markdown | 7.7 KB |
| references/error-handling.md | markdown | 3.9 KB |
| references/home-screen-widget.md | markdown | 8.8 KB |
| references/http-and-json.md | markdown | 8.0 KB |
| references/layout.md | markdown | 5.2 KB |
| references/localization.md | markdown | 6.1 KB |
| references/native-interop.md | markdown | 9.3 KB |
| references/performance.md | markdown | 7.3 KB |
| references/platform-views.md | markdown | 13.3 KB |
| references/plugins.md | markdown | 6.5 KB |
| references/system-ui.md | markdown | 3.3 KB |
| references/theming.md | markdown | 6.2 KB |
references/theming.md
View on GitHub---
name: "flutter-theming"
description: "How to customize your app's theme using Flutter's theming system"
metadata:
last_modified: "2026-03-12 11:18:17 (GMT+8)"
---
## Goal
Updates and manages Flutter application styling by migrating legacy Material 2 implementations to Material 3, normalizing component themes, updating deprecated button classes, and adapting UI idioms for cross-platform consistency. Assumes a Flutter environment using Dart.
## Instructions
1. **Analyze Current Theme State**
Review the existing Flutter codebase to identify legacy Material 2 components, deprecated button classes (`FlatButton`, `RaisedButton`, `OutlineButton`), and outdated theme properties (e.g., `accentColor`, `color` in `AppBarTheme`).
**STOP AND ASK THE USER:** "What is the primary seed color for the new Material 3 ColorScheme, and which target platforms (iOS, Android, Windows, macOS, Linux, Web) should be prioritized for platform idioms?"
2. **Decision Logic: Component Migration**
When encountering legacy widgets, use the following decision tree to determine the replacement:
* IF `BottomNavigationBar` -> REPLACE WITH `NavigationBar` (uses `NavigationDestination`).
* IF `Drawer` -> REPLACE WITH `NavigationDrawer` (uses `NavigationDrawerDestination`).
* IF `ToggleButtons` -> REPLACE WITH `SegmentedButton` (uses `ButtonSegment` and `Set` for selection).
* IF `FlatButton` -> REPLACE WITH `TextButton`.
* IF `RaisedButton` -> REPLACE WITH `ElevatedButton` (or `FilledButton` for no elevation).
* IF `OutlineButton` -> REPLACE WITH `OutlinedButton`.
3. **Implement App-Wide Material 3 Theme**
Define the global `ThemeData` using `ColorScheme.fromSeed`. Ensure `useMaterial3` is implicitly or explicitly true. Remove all references to deprecated accent properties (`accentColor`, `accentColorBrightness`, `accentTextTheme`, `accentIconTheme`).
```dart
MaterialApp(
title: 'App Name',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.light,
),
// Use colorScheme.secondary instead of accentColor
),
darkTheme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
),
),
home: const MyHomePage(),
);
```
4. **Normalize Component Themes**
Update all component theme definitions in `ThemeData` to use their `*ThemeData` equivalents. Do not use the base theme classes for configuration.
* `cardTheme` -> `CardThemeData`
* `dialogTheme` -> `DialogThemeData`
* `tabBarTheme` -> `TabBarThemeData`
* `appBarTheme` -> `AppBarThemeData` (Replace `color` with `backgroundColor`)
* `bottomAppBarTheme` -> `BottomAppBarThemeData`
* `inputDecorationTheme` -> `InputDecorationThemeData`
```dart
ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
appBarTheme: const AppBarThemeData(
backgroundColor: Colors.blue, // Do not use 'color'
elevation: 4.0,
),
cardTheme: const CardThemeData(
elevation: 2.0,
),
);
```
5. **Migrate Buttons and Button Styles**
Replace legacy buttons. Use the `styleFrom()` static method for simple overrides, or `ButtonStyle` with `WidgetStateProperty` for state-dependent styling.
```dart
// Simple override using styleFrom
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
disabledForegroundColor: Colors.red,
),
onPressed: () {},
child: const Text('TextButton'),
)
// State-dependent override using WidgetStateProperty
OutlinedButton(
style: ButtonStyle(
side: WidgetStateProperty.resolveWith<BorderSide>(
(Set<WidgetState> states) {
if (states.contains(WidgetState.pressed)) {
return const BorderSide(color: Colors.blue, width: 2);
}
return const BorderSide(color: Colors.grey, width: 1);
}
),
),
onPressed: () {},
child: const Text('OutlinedButton'),
)
```
6. **Decision Logic: Platform Idioms**
Apply platform-specific adaptations based on the host OS to reduce cognitive load and build user trust.
* **Scrollbars:** IF desktop platform -> Set `thumbVisibility: true` (or `alwaysShown`). IF mobile -> Use default auto-hiding behavior.
* **Text Selection:** IF text is informational and non-interactive -> Wrap in `SelectableText` to allow mouse selection on Web/Desktop.
* **Button Ordering:** IF Windows -> Place confirmation button on the LEFT. IF macOS/Linux/Android/iOS -> Place confirmation button on the RIGHT.
```dart
// Platform-aware button ordering
TextDirection btnDirection = Platform.isWindows
? TextDirection.rtl
: TextDirection.ltr;
Row(
children: [
const Spacer(),
Row(
textDirection: btnDirection,
children: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('OK'),
),
],
),
],
)
```
7. **Validate-and-Fix**
Scan the generated code to verify that no `FlatButton`, `RaisedButton`, `OutlineButton`, or `ButtonTheme` classes remain. Verify that `AppBarTheme` does not use the `color` property. Fix any instances found.
## Constraints
* **Single Source of Truth:** All colors must be derived from the `ColorScheme` (e.g., `Theme.of(context).colorScheme.primary`). Do not hardcode hex colors unless explicitly requested.
* **No Legacy Buttons:** Never output `FlatButton`, `RaisedButton`, or `OutlineButton`.
* **No Accent Properties:** Never use `accentColor`, `accentColorBrightness`, `accentTextTheme`, or `accentIconTheme`. Use `colorScheme.secondary` and `colorScheme.onSecondary` instead.
* **Component Theme Suffixes:** Always append `Data` to component themes when configuring `ThemeData` (e.g., `CardThemeData`, not `CardTheme`).
* **AppBar Background:** Never use the `color` property in `AppBarTheme` or `AppBarThemeData`; strictly use `backgroundColor`.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |