bloc_event_gen 0.1.2 copy "bloc_event_gen: ^0.1.2" to clipboard
bloc_event_gen: ^0.1.2 copied to clipboard

discontinued
outdated

A source code generator for BLoC events.

Getting Started #

Add the packages to your pubspec.yaml file:

dependencies:
  bloc_event_gen: ^[latest version]

dev_dependencies:
  build_runner: ^1.5.2 # Also depend on build_runner if you aren't already.
  bloc_event_generator: ^[latest version]

Annotate your BLoC class with BlocEvents:

@BlocEvents({
  'NavigateToAwesomePage': {},
  'ShowSnackBar': {
    'message': String,
    'duration': Duration,
  },
})
class HomeBloc // ...

Specify the part file for the generator code:

part 'your_bloc_file_name.g.dart';

Run the build:

$ flutter pub run build_runner build

...or have it watch for changes:

$ flutter pub run build_runner watch

The output will be the following code in the your_bloc_file_name.g.dart file:

class NavigateToAwesomePage extends BlocEvent {
  NavigateToAwesomePage();
}

class ShowSnackBar extends BlocEvent {
  final String message;
  final Duration duration;
  ShowSnackBar(this.message, this.duration);
}

See the example project for a working example.