# Feature Brick

[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](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
```

## Variables ✨

| Variable           | Description                     | Default | Type      |
| ------------------ | ------------------------------- | ------- | --------- |
| `feature_name`     | The name of the feature         | login   | `string`  |


## Outputs 📦

```shell
--feature_name feature
```

```
├── feature
│   ├── blocs
│   │   ├── feature_bloc
│   │   │   ├── feature_bloc.dart
│   │   │   ├── feature_event.dart
│   │   │   └── feature_state.dart
│   │   └── feature_cubit
│   │       ├── feature_cubit.dart
│   │       └── feature_state.dart
│   ├── screens
│   │   ├── widgets
│   │   │   └── feature_consumer_widget.dart
│   │   ├── feature_parent.dart
│   │   ├── feature_provider.dart
│   │   └── feature_screen.dart
│   ├── stateless
│   │   └── feature_widget.dart
│   └── feature.dart
└── ...
```

## Using BLoC

- {{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


## TODO
add this varibales : 

| `state_management` | The state management of the app | cubit   | `enum`    |
| `use_equatable`    | Use the equatable package       | true    | `boolean` |

# State Management Helper Brick

[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason)


## How to use 🚀

```
mason make state_management_helper_brick --name audit --state_management cubit --use_wrapper true
```

## Variables ✨

| Variable           | Description                     | Default | Type      | When                   |
| ------------------ | ------------------------------- | ------- | --------- |------------------------|
| `name`             | The name of the part            | login   | `string`  |  N/A                   |



```
├── feature_state_management
│    ├── feature_state_management.dart
|    ├── feature_wraper_widget.dart
|    └── widgets
|        └── feature_widget.dart
└── ...
```

- {{Name}}_state_management.dart

```dart
class FeatureCubitStateManagement
    extends CubitScreen<CounterCubit, CounterState> {
  const CounterCubitPage({super.key});

  @override
  CounterCubit create(BuildContext context) => FeatureCubit();

  @override
  Widget onWrap(BuildContext context, Widget child) => FeatureWrapperWidget(child: child);

  @override
  Widget onBuild(BuildContext context, CounterState state) => ChildWidget();

}
```

- {{Name}}_wrapper_widget.dart

```dart
class FeatureWrapperWidget extends WrapperStatelessWidget {
    const FeatureWrapperWidget(super.child);

  @override
  Widget build(BuildContext context, Widget child) => child;

}
```

- {{Name}}_widget.dart classic stateless widget.

Please note that `{Name}}_state_management.dart` and the functions you can override may change depending on the type you have chosen (Consummer, Screen or Provider).


Note 2 : This is intentionally not part of the feature :
- Assets
- AppRessources
- Data (Repositories, Data Provider, Models, ..)

## TODO 
add this variables 

| `state_management` | The state management of the app | cubit   | `enum`    |  N/A                   |
| `type`             | Screen, Provider or Consumer    | screen  | `enum`    |  N/A                   |
| `use_wrapper`      | Use the equatable package       | true    | `boolean` | Using screen/consumer/ |