flutter_rebloc 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new58

Flutter Re:BLoC #

A Flutter package inspired by flutter_bloc and reimagined to fit my own use case.

The core concept is the same and many of the implementation ideas are borrowed from that package. The main different between this package and flutter_bloc lies in how output state and events are handled.

  • There are two different events, (1) input events which I'll call actions and (2) internal BLoC triggered output events.
  • Output events are separated from the State value itself. These events represent the internal happenings of the BLoC and state represents the application state. In relation to the BLoC, events are internal and state is external.
  • Since events are separated, each BLoC should only stream one exact final State type. If you find yourself needing to use different State types, then creating a different BLoC to handle that State might be better.
  • State can be shared with multiple BLoCs using StateProvider so one BLoC can access the state value generated by another BLoC.

Usage #

class CounterState extends ReBlocState {
  final int count;
  const CounterState(this.count);

enum CounterAction {

class CounterBloc extends ReBloc<CounterState> {
  CounterState initState() => CounterState(0);
  Stream<StateEvent<CounterState>> runEvent(Object action, CounterState state) async* {
    yield(StateEvent(event: 'Working...'));

    switch (action) {
      case CounterAction.increment:
        yield(StateEvent(event: 'Incremented', state: CounterState(state.count+1)));
      case CounterAction.decrement:
        yield(StateEvent(event: 'Decremented', state: CounterState(state.count-1)));
        yield(StateEvent(event: ErrorEvent(message: 'Not implemented')));

class CounterWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Counter App'),
      body: ReBlocProvider<CounterBloc, CounterState>(
        create: (context) => CounterBloc(),
        initialAction: CounterAction.increment,
        successListener: (context, event) => Scaffold.of(context).showSnackBar(
            content: Text(event.message),
        errorListener: (context, event) => Scaffold.of(context).showSnackBar(
            content: Text(event.message),
            backgroundColor: Colors.red,
        builder: (context, bloc, state) {
          return Center(
            child: Column(
              children: [
                  onPressed: () => bloc.add(CounterAction.increment),
                  child: const Text('Plus 1'),
                  onPressed: () => bloc.add(CounterAction.decrement),
                  child: const Text('Minus 1'),

1.0.0 #

  • Initial release


flutter_rebloc_example #

A simple counter app to demonstrate the flutter_rebloc package.

Use this package as a library

1. Depend on it

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

  flutter_rebloc: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support 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:flutter_rebloc/flutter_rebloc.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/bloc/bloc.dart. (-1 points)

Analysis of lib/src/bloc/bloc.dart reported 2 hints:

line 169 col 13: Close instances of dart.core.Sink.

line 228 col 13: Close instances of dart.core.Sink.

Fix lib/src/state/state_builder.dart. (-0.50 points)

Analysis of lib/src/state/state_builder.dart reported 1 hint:

line 30 col 11: Close instances of dart.core.Sink.

Maintenance suggestions

The package description is too short. (-13 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
effective_dart ^1.1.2