flutter-feature
v0.1.0
Published
A command line tool to generate flutter feature module boilerplate directory structure
Downloads
185
Maintainers
Readme
flutter-feature
A CLI tool to generate the repetitive boilerplate of a Flutter feature.
Build the structure once. Generate it whenever you need it.
Installation
npm install -g flutter-featureOr with pnpm:
pnpm add -g flutter-featureAfter installation, use either flutter-feature or the shorter ff.
Usage
Run the command from the root of a Flutter project:
ff generate profileor:
ff g profileThis creates the feature under:
lib/features/profile/What gets generated?
The current generator creates:
lib/
└── features/
└── profile/
├── data/
│ ├── datasources/
│ │ └── profile_remote_datasource.dart
│ ├── models/
│ │ └── profile_model.dart
│ └── repositories/
│ └── profile_repository.dart
├── domain/
│ ├── entities/
│ │ └── profile.dart
│ └── repositories/
│ └── profile_repository.dart
└── presentation/
└── bloc/
├── profile_bloc.dart
├── profile_event.dart
└── profile_state.dartThe directory structure and generated files are intentionally separate. Some directories can exist even when they do not currently have a generated template.
Project-aware templates
Templates can use information from the Flutter project's pubspec.yaml.
For example:
name: blog_app
description: "A new Flutter project with supabase."provides:
appName = blog_appA model template can then generate:
import 'package:blog_app/features/profile/domain/entities/profile.dart';
class ProfileModel extends Profile {
const ProfileModel();
}Template system
Templates live under:
src/templates/feature/They use variables such as:
{{appName}}
{{snakeName}}
{{PascalName}}For example:
import 'package:{{appName}}/features/{{snakeName}}/domain/entities/{{snakeName}}.dart';
class {{PascalName}}Model extends {{PascalName}} {
const {{PascalName}}Model();
}Template mapping
template-path.ts defines what the feature generator creates by mapping:
layer
folder
template
outputFor example:
t({
layer: "domain",
folder: "entities",
template: "entity.dart.template",
output: "{{snakeName}}.dart",
})maps:
domain/entities/entity.dart.template
↓
domain/entities/profile.dartTo add another permanent piece of boilerplate:
- Create the
.dart.templatefile. - Add its mapping to
template-path.ts. - Build the package.
The generation engine handles the rest.
Development
Install dependencies:
pnpm installBuild:
pnpm buildRun during development:
pnpm dev -- g profileBuild flow:
TypeScript source
↓
tsc
↓
tsc-alias
↓
dist/*.js
↓
copy templates
↓
dist/templates/tsc-alias resolves the @/ imports after TypeScript compilation, while the template-copy step places the runtime templates into dist/templates/.
Requirements
- Node.js
- A Flutter project
pubspec.yamlat the Flutter project root
License
MIT
