116 lines
2.6 KiB
Markdown
116 lines
2.6 KiB
Markdown
# Feature Brick
|
|
|
|
[](https://github.com/felangel/mason)
|
|
|
|
|
|
|
|
|
|
A brick to create a feature using best practices and your state management of choice! Supports Bloc & Cubit.
|
|
|
|
## How to use 🚀
|
|
|
|
```
|
|
mason make feature_brick --feature_name audit --state_management cubit --use_equatable true
|
|
```
|
|
|
|
## Variables ✨
|
|
|
|
| Variable | Description | Default | Type |
|
|
| ------------------ | ------------------------------- | ------- | --------- |
|
|
| `feature_name` | The name of the feature | login | `string` |
|
|
| `state_management` | The state management of the app | cubit | `enum` |
|
|
| `use_equatable` | Use the equatable package | true | `boolean` |
|
|
|
|
## Outputs 📦
|
|
|
|
### Using Bloc
|
|
|
|
```shell
|
|
--feature_name login --state_management bloc
|
|
```
|
|
|
|
```
|
|
├── feature
|
|
│ ├── blocs
|
|
| | └── feature_bloc
|
|
│ │ ├── feature_bloc.dart
|
|
│ │ ├── feature_event.dart
|
|
│ │ └── feature_state.dart
|
|
│ ├── state_management
|
|
| | └── ...
|
|
│ └── feature.dart
|
|
└── ...
|
|
```
|
|
|
|
- {{featureName}}_bloc.dart
|
|
|
|
```dart
|
|
class FeatureBloc extends Bloc<FeatureEvent, FeatureState> {
|
|
// TODO: Add repo if needed
|
|
FeatureBloc() : super(const FeatureInitial()) {
|
|
on<CustomFeatureEvent>(_onCustomFeatureEvent);
|
|
}
|
|
|
|
FutureOr<void> _onCustomFeatureEvent(
|
|
CustomFeatureEvent event,
|
|
Emitter<FeatureState> emit,
|
|
) {
|
|
// TODO: Add your logic
|
|
}
|
|
}
|
|
```
|
|
|
|
- {{featureName}}.dart
|
|
|
|
only one event is generated. It is up to you to rename it and add other events.
|
|
|
|
```dart
|
|
class CustomFeatureEvent extends FeatureEvent {}
|
|
```
|
|
|
|
- {{featureName}}_state.dart
|
|
|
|
only one state is generated. It is up to you to rename it and add other states.
|
|
|
|
```dart
|
|
class FeatureInitial extends FeatureState {
|
|
const FeatureInitial() : super();
|
|
}
|
|
```
|
|
|
|
|
|
### Using Cubit
|
|
|
|
```shell
|
|
--feature_name login --state_management cubit
|
|
```
|
|
|
|
```
|
|
├── feature
|
|
│ ├── cubits
|
|
| | └── feature_cubit
|
|
│ │ ├── feature_cubit.dart
|
|
│ │ └── feature_state.dart
|
|
│ ├── state_management
|
|
| | └── ...
|
|
│ └── feature.dart
|
|
└── ...
|
|
```
|
|
|
|
- {{featureName}}_cubit.dart
|
|
|
|
```dart
|
|
class FeatureCubit extends Cubit<FeatureState> {
|
|
// Add repo if needed
|
|
FeatureCubit() : super(const FeatureInitial());
|
|
|
|
FutureOr<void> yourCustomFunction() {
|
|
// TODO: Add your logic
|
|
}
|
|
}
|
|
```
|
|
|
|
{{featureName}}_state.dart is the same file as before
|
|
|
|
### None
|
|
TODO |