refactor-flutter_skill

This skill refactors Flutter/Dart code to improve maintainability, readability, and performance using Dart 3 features, modern state management, and clean

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill refactor-flutter

  • SKILL.md24.6 KB

Overview

This skill refactors Flutter and Dart code to improve maintainability, readability, and runtime performance. It applies Dart 3 features (records, pattern matching, sealed classes), introduces immutable models with Freezed, and migrates state management to Riverpod or BLoC. The result is smaller widgets, fewer unnecessary rebuilds, and clearer separation between UI and logic.

How this skill works

I analyze widget trees, build methods, and state flow to find monolithic widgets, improper BuildContext usage, missing const constructors, and deep nesting. I replace legacy Dart patterns with Dart 3 constructs, extract reusable components, introduce Freezed data models, and wire Riverpod or BLoC providers/notifiers for predictable state updates. I also optimize performance: use const where possible, lazy list builders, correct key usage, and guard async context access.

When to use it

  • Widgets exceed ~150 lines or build methods are very long
  • App suffers from excessive or unnecessary widget rebuilds
  • Legacy Dart 2 patterns block maintainability or you want Dart 3 benefits
  • State is mixed into UI instead of being separated (no provider/bloc)
  • Deeply nested conditionals or asynchronous context misuse cause bugs

Best practices

  • Extract repeated widget trees into focused, composable widgets under 100–150 lines
  • Prefer const constructors and lightweight widgets (SizedBox vs Container) to reduce rebuild cost
  • Use Freezed for immutable models and union types for explicit states
  • Adopt Riverpod for concise providers or BLoC for event/state separation where appropriate
  • Apply Dart 3 patterns: records for multi-returns, switch expressions and if-case for null checks
  • Guard BuildContext across async gaps (capture Navigator/Messenger or check mounted/context.mounted)

Example use cases

  • Refactor a monolithic ProfilePage into small stateless widgets with Riverpod-backed user loading
  • Migrate legacy stateful logic into a Riverpod AsyncNotifier or a typed BLoC with Freezed states
  • Replace repeated item widget trees with a reusable component and correct ListView.builder usage
  • Convert verbose if-else UI logic into exhaustive switch expressions over sealed result types
  • Upgrade model classes to Freezed with JSON serialization and safe deep copyWith updates

FAQ

Refactors aim to preserve behavior while improving structure and performance. Where behavior changes are needed (e.g., fixing async/context bugs), I document and test them.

Which state management should I choose: Riverpod or BLoC?

Choose Riverpod for concise, testable providers and modern DI style; choose BLoC when you prefer explicit event/state flows and long-lived streams. I can migrate code to either based on your architecture and team preference.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational