b_generator 0.0.1+1

Generators for b_annotations.

b(loc)_generator #

Generators for b_annotations

Disclaimer #

This package is intended for personal use, so use at own risk. It is based on flutter_bloc: ^1.0.0 and might not work for later versions.

Requirement #

  • bloc
  • b_annotations
  • b_generator
  • build_runner

Usage #

  1. Import bloc
  2. Add the following to the beginning of your bloc file part '<filename>.bloc.dart' part '<filename>.events.dart'
  3. Annotate the class with @bloc
  4. Extend GeneratedBloc
  5. implement initialState
  6. Add methods for handling events and annotate them with @event

Example #

When you create my_bloc.dart

import 'package:b_annotations/b_annotations.dart';
import 'package:b_generator_example/feed_state.dart';
import 'package:bloc/bloc.dart';

part 'my_bloc.bloc.dart';

part 'my_bloc.events.dart';

@bloc
class MyBloc extends GeneratedBloc {
  @override
  // Implement this
  MyBlocState get initialState => throw UnimplementedError();

  @event
  Stream<MyBlocState> exampleEvent(final String test) async* {}
}

It will generate the following two files:

my_bloc.bloc.dart

abstract class GeneratedBloc extends Bloc<MyBlocEvent, MyBlocState> {
  MyBlocState get initialState;

  @override
  Stream<MyBlocState> mapEventToState(final MyBlocEvent event) async* {
    if (event is ExampleEvent) yield* exampleEvent();
  }

  Stream<MyBlocState> exampleEvent();
}

my_bloc.events.dart

class MyBlocEvent {}

class ExampleEvent extends MyBlocEvent {
  final String test;

  ExampleEvent(this.test);

  @override
  String toString() {
    return '$runtimeType { test: $test }';
  }
}
1
likes
20
pub points
1%
popularity

Generators for b_annotations.

Uploader

robert.moeller@booza.app

License

MIT (LICENSE)

More

Packages that depend on b_generator