bloc_event 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

bloc_event #

Make the Bloc Events easier to structure

Getting Started #

To use this plugin, add bloc_event as a dependency in your pubspec.yaml file.

Basic Usage #

Create your events base class like followed:

abstract class MyEvent extends Event<MyBloc, MyState> {}

Your actual Event should look like:

class DoSomethingEvent extends MyEvent {
  final String myData;
  
  DoSomethingEvent(this.myData);
  
  @Override
  Stream<MyState> onTriggered(MyBloc bloc, MyState state) async* {
    // Do your event stuff here
    yield state.copyWith(data: myData);
  }
}

By extending EventBloc in your Bloc you don't have to implement mapEventToState:

class MyBloc extends EventBloc<MyEvent, MyState> {
  
  @Override
  MyState get initialState => MyState();
  
}

That's it!!

Testing #

You are now able to test your events separated easily without even using the bloc.

test('sample test', () {
    var myEventToTest = MyEvent(myData);
    var result = myEventToTest.onTriggered(myMockedBloc, myCurrentState);
    expectLater(result, emits(myNewState));
});

1.0.5 - 12.1.2019 #

  • bloc library updated to 2.0.0

1.0.4 - 22.10.2019 #

  • bloc library updated to 1.0.0
  • test documentation

1.0.3 - 16.10.2019 #

  • Removed generic event parameter from onTriggered function, its not needed

1.0.2 - 15.10.2019 #

  • Updated dependencies
  • Provide example

1.0.1 - 13.10.2019 #

  • Changes for pub.dev

1.0.0 - 13.10.2019 #

  • Added initial functionality

example/main.dart

import 'package:bloc_event/bloc_event.dart';

abstract class CounterEvent<E> extends Event<CounterBloc, int> {}

class CounterBloc extends EventBloc<CounterEvent, int> {

  @override
  int get initialState => 0;

}

class CounterIncrement extends CounterEvent {
  final int value;

  CounterIncrement(this.value);

  @override
  Stream<int> onTriggered(bloc, state) async* {
    yield state+value;
  }
}

void main() {
  final counterBloc = CounterBloc();
  counterBloc.add(CounterIncrement(2));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bloc_event: ^1.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bloc_event/bloc_event.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

We analyzed this package on Dec 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Health suggestions

Fix lib/Event.dart. (-0.50 points)

Analysis of lib/Event.dart reported 1 hint:

line 2 col 3: Prefer using /// for doc comments.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (bloc).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bloc ^2.0.0 2.0.0 3.0.0-dev.1
Transitive dependencies
meta 1.1.8
rxdart 0.22.6 0.23.0-dev.3