list_bloc 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • new46

A BLoC library for loading data from an api end-point with filtering and pagination.

The idea for this library is to convert the data loaded from an API into a BLoC to avoid boiler plate, but at the same time keeping things very simple and generic.

The base classes are DataBloc<T,F> with DataEvent<T,F> and DataState<T,F> where T is the type of the data element and F is a class for thr API filtering.

Then, ListBloc<T,F> extends DataBloc<List<T>,F to provide a shorthand for loading list of items.

Further, PaginatedBloc<T,F> extends DataBloc<ListPage<T,F> to provide pagination.

If you have an API instance that does not use filtering, you can replace the filter class with Object.

The three blocs are expecting to be initialized with a DataRepository, ListRepository or PaginatedRepository respectively, all of which should implement a Future load({F filter}) which is slightly different for List or Paginated bloc.

The filters can extend Object or any other class however built_value is quite useful for this as this allows re-building filters based on existing ones quite easily.

In order to generate the OffetLimitFilter run pub run build_runner build

Usage #

A simple usage example:

import 'packages:list_bloc.dart';

// Can be as complex as the API supports
class ItemFilter {
    enum fruits, vegetables;
class Item {
    int type;
    int value;
class ItemRepository implements ListRepository<Item, ItemFilter> {
    Future List<Item>load({ItemFilter filter}) async => await apiList(type: filter);

main() {
    final bloc = ListBloc<Item, ItemFilter>(ItemRepository());

    BlocBuilder<ListBloc<Item, ItemFilter>, DataState<Item, ItemFilter>(
        bloc: bloc,
        builder: (context, state) {
            for(var item in {

TODO: [ ] PaginatedBloc example [ ] ListPage class explanation

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.0.5 #

  • reuse state filter if no filter is supplied with DataLoad event

0.0.4 #

  • Use built_value for the filters

0.0.3 #

  • Initial README

0.0.1 #

  • Initial version


//import 'package:list_bloc/list_bloc.dart';
//import 'package:list_bloc/src/repositories/list_repository.dart';

void main() {}

Use this package as a library

1. Depend on it

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

  list_bloc: ^0.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:list_bloc/list_bloc.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 Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Health suggestions

Format lib/src/blocs/data_bloc.dart.

Run dartfmt to format lib/src/blocs/data_bloc.dart.

Format lib/src/blocs/data_event.dart.

Run dartfmt to format lib/src/blocs/data_event.dart.

Format lib/src/blocs/data_state.dart.

Run dartfmt to format lib/src/blocs/data_state.dart.

Fix additional 7 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/blocs/list_bloc.dart (Run dartfmt to format lib/src/blocs/list_bloc.dart.)
  • lib/src/blocs/paginated_bloc.dart (Run dartfmt to format lib/src/blocs/paginated_bloc.dart.)
  • lib/src/filter.dart (Run dartfmt to format lib/src/filter.dart.)
  • lib/src/page.dart (Run dartfmt to format lib/src/page.dart.)
  • lib/src/repositories/data_repository.dart (Run dartfmt to format lib/src/repositories/data_repository.dart.)
  • lib/src/repositories/list_repository.dart (Run dartfmt to format lib/src/repositories/list_repository.dart.)
  • lib/src/repositories/paginated_repository.dart (Run dartfmt to format lib/src/repositories/paginated_repository.dart.)

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field was unreachable.

Support latest dependencies. (-10 points)

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

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.1 <3.0.0
bloc ^4.0.0 4.0.0 5.0.1
equatable ^1.2.0 1.2.2
Transitive dependencies
collection 1.14.13 1.15.0-nullsafety
meta 1.2.2 1.3.0-nullsafety
Dev dependencies
pedantic ^1.9.0
test ^1.14.4