FlutterGenius
Description
FlutterGenius is a productivity extension for Flutter developers using Clean Architecture and BLoC. It automates repetitive boilerplate tasks such as generating data models from entities, creating BLoC structures with Freezed, extracting hardcoded strings for localization, and refactoring UI code for cleaner responsiveness.
Features
- Entity to Model Mapper: Instantly generate a
Freezed data model from a Clean Architecture Entity class.
- Bloc Generator: Create a full BLoC feature (Bloc, Event, State) using
Freezed and Equatable via the context menu.
- Smart Localization (AppText): Automatically extract strings wrapped in
AppText(...) to your JSON translation file.
- Aggressive Localization: Select a folder to scan and extract all hardcoded strings, converting them to
easy_localization keys.
- Size Extension & Refactor: Auto-injects a responsive sizing extension and refactors your
SizedBox, Padding, and BorderRadius code to use cleaner, fluent syntax.
Usage
1. Entity to Model Mapper (Freezed)
Convert your Domain Entities into Data Models with zero typing.
- Open a Dart file containing your entity (e.g.,
user_entity.dart).
- Place your cursor anywhere inside the class definition.
- Open the Command Palette (
Ctrl+Shift+P / Cmd+Shift+P).
- Run: Dart: Generate Entity to Model.
What Happens:
- Detects the class name (e.g.,
UserEntity).
- Creates a new file in
data/models/user_model.dart.
- Generates
UserEntity -> UserModel mapping logic (toEntity, fromEntity).
- Generates standard
Freezed boilerplate (fromJson, toJson).
2. Create BLoC (Freezed)
Generate a complete BLoC structure with standard imports and boilerplate.
- Right-click on any folder in your file explorer.
- Select Create BLoC (Freezed).
- Enter the name of your BLoC (e.g.,
Login).
What Happens:
- Creates a folder named
login_bloc.
- Generates 3 files:
login_bloc.dart, login_event.dart, and login_state.dart.
- Sets up
Equatable for events and Freezed for state management.
Ideal for maintaining existing projects using a custom AppText widget.
- Open the Command Palette.
- Run: Dart: Extract AppText to Localization.
What Happens:
- Scans
lib/ for usage of AppText("String").
- Adds the key/value to
assets/translations/en-GB.json.
- Replaces code with
AppText(LocaleKeys.generated_key).
- automatically runs
easy_localization:generate to update your generated keys file.
4. Aggressive Localization (Targeted)
Best for localizing a new feature or cleaning up technical debt.
- Open the Command Palette.
- Run: Dart: Extract Localization (Aggressive - Select Folder).
- Select the folder you want to clean (e.g.,
lib/features/profile).
What Happens:
- Scans all string literals (e.g.,
'Profile', "Settings").
- Intelligent filtering: Skips assets, imports, Map keys, and technical strings.
- Adds keys to
assets/translations/en-GB.json.
- Replaces code with
LocaleKeys.generated_key.tr().
5. Smart Size Extensions & Refactor
Refactor your entire codebase to use cleaner, fluent UI syntax.
- Open the Command Palette.
- Run: Flutter: Add Size Extension & Refactor UI.
⚠️ What will happen?
- Dependency Check: The extension checks
pubspec.yaml for flutter_screenutil. If missing, it asks you to add it.
- File Creation: It creates a new file at:
lib/core/common/presentation/extensions/size/app_size_extension.dart
This file contains the logic for .horizontalGap, .allPadding, etc.
- Global Scan: It scans every
.dart file in your lib/ folder.
- Refactoring: It replaces verbose Flutter widgets with the new extension syntax.
🔄 What exactly will change?
| Widget Type |
Before (Old Code) |
After (Refactored Code) |
| Gaps (SizedBox) |
SizedBox(width: 10) SizedBox(width: 10.w) |
10.horizontalGap |
|
SizedBox(height: 20) SizedBox(height: 20.h) |
20.verticalGap |
| Padding |
EdgeInsets.all(16) |
16.allPadding |
|
EdgeInsets.symmetric(horizontal: 12) |
12.horizontalPadding |
|
EdgeInsets.symmetric(vertical: 8) |
8.verticalPadding |
|
EdgeInsets.only(bottom: 10) |
10.bottomOnly |
|
EdgeInsets.only(top: 10) |
10.topOnly |
|
EdgeInsets.only(left: 10) |
10.leftOnly |
|
EdgeInsets.only(right: 10) |
10.rightOnly |
| Border Radius |
BorderRadius.circular(15) |
15.rounded |
|
Radius.circular(15) |
15.circular |
| Shape |
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)) |
12.roundShape |
Note: The extension automatically adds the necessary import to app_size_extension.dart in every file it modifies.
Requirements
To use the generated code effectively, your pubspec.yaml should include the following dependencies:
dependencies:
flutter_bloc: ^8.1.0
freezed_annotation: ^2.4.0
json_annotation: ^4.8.0
equatable: ^2.0.5
easy_localization: ^3.0.0
flutter_screenutil: ^5.9.0
dev_dependencies:
build_runner: ^2.4.0
freezed: ^2.4.0
json_serializable: ^6.7.0