flutter_refactor_plugin 1.0.2 copy "flutter_refactor_plugin: ^1.0.2" to clipboard
flutter_refactor_plugin: ^1.0.2 copied to clipboard

A custom lint plugin that encourages declarative widget composition by suggesting extraction of complex widget trees.

Flutter Refactor Plugin #

A custom lint plugin that encourages declarative widget composition by suggesting the extraction of complex widget trees into separate helper methods or widgets.

This plugin includes the prefer_declarative_over_widget_nesting rule, which flags widget trees that are too deep or complex inside a build method and provides a Quick Fix to extract them with intelligent naming.

Features #

  • Lint Rule: prefer_declarative_over_widget_nesting detects when structural widgets (like Column, Row, Stack) contain complex children that should be extracted.
  • Smart Naming: The Quick Fix automatically suggests meaningful names for extracted methods based on the widget's content (e.g., Text('Login') -> _buildLoginText).
  • Context Awareness: Handles l10n variables, context access, and custom widgets gracefully.
  • Batch Fix Support: Safely handles "Fix All" operations by coordinating names to avoid collisions (e.g., _buildBorderLine, _buildBorderLine2).

Installation #

Add the package to your pubspec.yaml as a dev dependency, along with custom_lint:

dev_dependencies:
  custom_lint: ^0.8.0
  flutter_refactor_plugin: ^1.0.0

Usage #

Enable the plugin in your analysis_options.yaml:

analyzer:
  plugins:
    - custom_lint

custom_lint:
  rules:
    - prefer_declarative_over_widget_nesting

Example #

Before:

Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: [
        Text('Hello'), // Flagged: "Extract this widget..."
        Icon(Icons.star),
      ],
    ),
  );
}

After (Quick Fix):

Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: [
        _buildHelloText(),
        _buildStarIcon(),
      ],
    ),
  );
}

Widget _buildHelloText() {
  return Text('Hello');
}

Widget _buildStarIcon() {
  return Icon(Icons.star);
}
1
likes
0
points
287
downloads

Publisher

verified publisherahmedmamdouh.dev

Weekly Downloads

A custom lint plugin that encourages declarative widget composition by suggesting extraction of complex widget trees.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, cupertino_icons, custom_lint_builder, flutter, meta

More

Packages that depend on flutter_refactor_plugin