list_bloc 3.1.3 copy "list_bloc: ^3.1.3" to clipboard
list_bloc: ^3.1.3 copied to clipboard

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

list_bloc #

Overview #

This Flutter package is a comprehensive BLoC library designed for loading, managing, and displaying data with support for filtering and pagination. It simplifies handling various data states like loading, empty, error, and loaded, using the freezed package.

Key Components #

  • DataCubit<T, F>: Manages the state of data with generic types for data (T) and filters (F).
  • ListCubit<T, F>: Specialized for handling lists of data, extending DataCubit.
  • PaginatedCubit<T, F>: Tailored for paginated data handling, extending DataCubit.
  • ContinousListBloc<T, F>: Extends ListCubit for continuous list implementation, requiring OffsetLimitFilter in the filter class.

Installation #

Add this package to your Flutter project by including it in your pubspec.yaml file:

dependencies:
  list_bloc: ^latest_version

Usage #

Basic Usage of DataCubit #

final dataCubit = DataCubit<YourDataType, YourFilterType>(yourDataLoaderFunction);

// Load data
dataCubit.load();

// Clear data
dataCubit.clear();

Using ListCubit for List Management #

final listCubit = ListCubit<YourListItemType, YourFilterType>(yourListLoaderFunction);

// Reload the entire list
listCubit.reload();

// Append more items to the existing list
listCubit.append();

// Add or remove items locally
listCubit.addLocally(yourItem);
listCubit.removeLocally(yourItem);

Working with PaginatedCubit #

final paginatedCubit = PaginatedCubit<YourPaginatedItemType, YourFilterType>(yourPaginatedLoaderFunction);

// Usage is similar to DataCubit, but tailored for paginated data.

Advanced Usage Example #

import 'package:list_bloc.dart';

class ItemFilter {
  enum Type { fruits, vegetables }
}

class Item {
  int type;
  int value;
}

typedef FruitBloc = ListBloc<Item, ItemFilter>;
typedef FruitState = Data<List<Item>, ItemFilter>;

Future<List<Item>> loader([ItemFilter? filter]) async => api.....

void main() {
  final bloc = FruitBloc(loader);

  bloc.load(ItemFilter.Type.fruits);

  BlocBuilder<FruitBloc, FruitState>(
    bloc: bloc,
    builder: (context, state) {
      for (var item in state.data) {
        // Handle your data
      }
    },
  );
}

Features and Bugs #

We welcome your feedback and contributions to this package. Please file feature requests and bugs at the issue tracker.

2
likes
110
pub points
62%
popularity

Publisher

verified publisherapexive.com

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

bloc, freezed_annotation

More

Packages that depend on list_bloc