Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/sahandevs/bloc_generator
- Owner: sahandevs
- License: mit
- Created: 2019-03-30T07:45:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-11T09:55:24.000Z (over 5 years ago)
- Last Synced: 2024-10-20T07:49:43.969Z (19 days ago)
- Topics: bloc, design-patterns, flutter
- Language: Dart
- Homepage:
- Size: 78.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.0dev_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 HANDpart 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)