bloc_helpers 0.3.2

Dart native js
Flutter Android iOS web

Set of helpers class and function to implements Bloc pattern

Dart Bloc Pattern helper #

What is Bloc pattern ? #

bloc_helpers #

This package contain helper class and common Bloc Pattern

  • Bloc (base to implement Bloc pattern)
  • AsyncTaskBloc
  • AsyncCachedTaskBloc
  • RequestBloc
  • CachedRequestBloc
  • SelectorBloc

Bloc class #

The bloc class is a simple class that provide dispose function and a disposed boolean

abstract class Bloc {
  bool _disposed = false;

  bool get disposed => _disposed;

  @mustCallSuper
  void dispose() {
    _disposed = true;
  }
}

Request bloc #

RequestBloc help to implement async call, it provides following stream ans sink.

Sink<Request> callSink

Stream<bool> running

Stream<Request> onCall

Stream<Response> onResult

CachedRequestBloc add the ability to cache response, to avoid multiple call when request does not change, it provides following stream and sink.

Stream<Response> cachedResult

Sink<Response> invalidateCacheSink

Sink<Response> updateCachedResultSink

Usage

import 'package:bloc_helpers/bloc_helpers.dart';
import 'package:meta/meta.dart';

class MyRequestBloc extends RequestBloc<MyRequest, MyResponse> {
  @override
  @protected
  Future<MyResponse> request(MyRequest input) async {
    // TODO: implement request
    return MyResponse();
  }
}

bloc.callSink.add(MyRequest());

See example

Selector bloc #

Selector bloc help implementing a simple selection behavior

final selector = SelectorBloc<String>();

  selector.selected.listen((selected) => print(selected));

  selector.selectSink.add('foo');
  selector.unselectSink.add('foo');

  selector.selectAllSink.add(['foo', 'bar']);

Contributions #

This repository is open to Pull Request and new idea :)

0
likes
80
pub points
34%
popularity

Set of helpers class and function to implements Bloc pattern

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

hadrien.lejard@gmail.com

License

MIT (LICENSE)

Dependencies

meta, rxdart, test

More

Packages that depend on bloc_helpers