GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Searching for packages
  • Package scoring and pub points
  • Using packages
  • Developing packages and plugins
  • Publishing a package
  • Using packages

This view

  • Original page
  • New address

GeezerVison is showing pub.dev — bloc_code_generator | Dart package

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

Published 6 years ago Dart 3 incompatible
discontinued
11
→

Metadata

Bloc Code Generator is a code generator for https://github.com/felangel/bloc package.

More...

  • Readme
  • Changelog
  • Example
  • Installing
  • Versions
  • Scores

Bloc Code Generator #

A Dart package that generates code for the bloc library.

GenerateBloc Annotation #

GenerateBloc is a dart annotation that requires a State as parameter, the state can be a primitive or an object. It handles the bloc's generation.

How it works #

By adding the annotation to your Bloc class like this:

part 'my_bloc.g.dart';

@GenerateBloc(MyState)
class MyBloc extends _$Bloc {
 @override
  MyState get initialState => MyState();

  Stream<MyState> _mapDoSomethingToState(int someValue, SomeModel someModel) async* {
    yield MyState.doSomething(someValue, someModel);
  }
}

And running

flutter packages pub run build_runner build --delete-conflicting-outputs

The generator will create the my_bloc.g.dart file for you:

part of 'main_bloc.dart';

enum _$EventType { doSomething }

class _$Event {
  final _$EventType type;
  final List<dynamic> payload;

  _$Event({this.type, this.payload});
}

abstract class _$Bloc extends Bloc<_$Event, MyState> {
  Stream<MyState> mapEventToState(_$Event event) async* {
    switch (event.type) {
      case _$EventType.doSomething:
        yield* _mapDoSomethingToState(event.payload[0], event.payload[1]);
        break;
    }
  }

  void dispatchDoSomethingEvent(int someValue, SomeModel someModel) {
    dispatch(_$Event(
      type: _$EventType.increment,
      payload: [someValue, someModel],
    ));
  }

  Stream<MyState> _mapDoSomethingToState(int someValue, SomeModel someModel);
}

It gets all _map<NAME>ToState methods, creates the dispatchers and maps the right events to them.

By using the generator you don't need to handle the events, only the mapToState methods.

Examples #

  • Counter - an example of how to create a counter bloc

Maintainers #

  • Adson Leal
11
likes
40
points
65
downloads

Publisher

unverified uploader

Weekly Downloads

Metadata

Bloc Code Generator is a code generator for https://github.com/felangel/bloc package.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

analyzer, build, source_gen

More

Packages that depend on bloc_code_generator

← Metadata

11
likes
40
points
65
downloads

Publisher

unverified uploader

Weekly Downloads

Metadata

Bloc Code Generator is a code generator for https://github.com/felangel/bloc package.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

analyzer, build, source_gen

More

Packages that depend on bloc_code_generator

Back

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.