Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sahandevs/bloc_generator

experimental implementation of code generator for BLoC pattern
https://github.com/sahandevs/bloc_generator

bloc design-patterns flutter

Last synced: 8 days ago
JSON representation

experimental implementation of code generator for BLoC pattern

Awesome Lists containing this project

README

        

# BLoC Generator

experimental implementation of code generator for BLoC pattern

## Installation

```yaml
dependencies:
bloc_generator_annotation: ^1.0.0
bloc_generator_flutter_helper: ^1.0.0

dev_dependencies:
build_runner: ^1.0.0
bloc_gen: ^1.0.1

```
then run

```sh
flutter packages get
```

## Run Builder

```sh
flutter packages pub run build_runner build # [watch, serve]
```

## Usage

Note: Supports `BehaviorSubject` (rxDart) and `Stream`

create a dart file `.dart`

```dart
import 'package:bloc_generator_flutter_helper/bloc_generator_flutter_helper.dart';
import 'package:bloc_generator_annotation/bloc_generator_annotation.dart';

part '.bloc.dart';

@BLoC()
class TestBloc {

// your logic here

void test() { }

}
```

run `flutter packages pub run build_runner build`

and this will generate a file named `.bloc.dart`
```dart
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'test_bloc.dart';

// **************************************************************************
// BLoCGenerator
// **************************************************************************

abstract class TestBlocMixin {
TestBloc bloc = TestBloc();

void event_test() => bloc.test();
}

```

now use this mixin like this:
```dart
// for stateful widget
class _WidgetState extends State with TestBlocMixin { }
// for stateless widget
class Widget extends StatelessWidget with TestBlocMixin {}
```

> DO NOT FORGET TO CLOSE THE STREAMS

[FULL EXAMPLE](./example/README.md)

## TODO:

- FULL DOCUMENTATION

[Hacky way to use with Android Studio's Run Configurations](./docs/android_studio_run_configuration.md)