All Projects → klisiewicz → flutter-bloc-patterns

klisiewicz / flutter-bloc-patterns

Licence: MIT License
A set of most common BLoC use cases built on top of flutter_bloc library

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to flutter-bloc-patterns

Bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 8,214 (+14062.07%)
Mutual labels:  state-management, bloc, flutter-package
bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 12 (-79.31%)
Mutual labels:  state-management, bloc, flutter-package
bloc samples
A collection of apps built with the Bloc library.
Stars: ✭ 39 (-32.76%)
Mutual labels:  state-management, bloc, flutter-bloc
whatsApp clone
Flutter WhatsClone (with Firebase + Clean Architecture) this app follow clean architecture proposed by our friendly Uncle Bob.
Stars: ✭ 181 (+212.07%)
Mutual labels:  bloc, flutter-bloc, flutter-bloc-pattern
rx shared preferences
🌀 Shared preferences with RxDart Stream observation ⚡️ Reactive shared preferences for Flutter 🌸Reactive stream wrapper around SharedPreferences 🍄 Lightweight and easy-to-use 🌱 A reactive key-value store for Flutter projects. Like shared_preferences, but with Streams 📕 Rx Shared Preferences for Flutter 🌿 rx_shared_preferences 🌰 rx_shared_prefere…
Stars: ✭ 36 (-37.93%)
Mutual labels:  flutter-package, flutter-bloc, flutter-bloc-pattern
load more flutter BLoC pattern RxDart and RxRedux
🔥 [FUNCTIONAL & REACTIVE PROGRAMMING (FRP)] ❄️[Pure RxDart] Paging ListView flutter 🌸 Load more flutter listview 🌱 Endless scrolling flutter 👏 Flutter infinite list - BLoC pattern - rxdart - reactive stream flutter - RxDart.
Stars: ✭ 91 (+56.9%)
Mutual labels:  flutter-bloc, flutter-bloc-pattern
generic bloc provider
Generic BloC provider implementation
Stars: ✭ 26 (-55.17%)
Mutual labels:  state-management, bloc
flutter-checkio
How time flies.一款开源习惯打卡APP,流畅的动画体验,Bloc实现状态管理,主题(颜色)切换,字体切换,数据库管理等。
Stars: ✭ 507 (+774.14%)
Mutual labels:  bloc, flutter-bloc
crypto-currency
A Flutter application showing crypto currency rates.
Stars: ✭ 16 (-72.41%)
Mutual labels:  state-management, flutter-bloc-pattern
devon4flutter-non-bloc-arch
A guide aiming to bridge the gap between the absolute Flutter basics and clean, structured Flutter Development
Stars: ✭ 283 (+387.93%)
Mutual labels:  state-management, bloc
Chi Food
Food Delivery App made by Flutter and Bloc
Stars: ✭ 103 (+77.59%)
Mutual labels:  bloc, flutter-bloc
IQPlayer
Simple video player with subtitle for flutter.
Stars: ✭ 16 (-72.41%)
Mutual labels:  flutter-package, flutter-bloc
Flutter Roadmap
This is a flutter roadmap and documentation repository. If anyone is interested you can join the party to help the community and make flutter great again.
Stars: ✭ 47 (-18.97%)
Mutual labels:  state-management, bloc
getx snippets extension
An extension to accelerate the process of developing applications with flutter, aimed at everyone using the GetX package.
Stars: ✭ 142 (+144.83%)
Mutual labels:  state-management, flutter-package
reactive state
An easy to understand reactive state management solution for Flutter.
Stars: ✭ 19 (-67.24%)
Mutual labels:  state-management, flutter-package
flutter preload videos
Preloading videos in Flutter 💙
Stars: ✭ 42 (-27.59%)
Mutual labels:  bloc
xstate-viz
Visualizer for XState machines
Stars: ✭ 274 (+372.41%)
Mutual labels:  state-management
time chart
A scrollable time chart in Flutter.
Stars: ✭ 21 (-63.79%)
Mutual labels:  flutter-package
eva icons flutter
Flutter package for Eva Icons. Eva Icons is a pack of more than 480 beautifully crafted Open Source icons for common actions and items. https://pub.dartlang.org/packages/eva_icons_flutter
Stars: ✭ 80 (+37.93%)
Mutual labels:  flutter-package
getwidget-web-kit
Get Widget Web app Demo
Stars: ✭ 40 (-31.03%)
Mutual labels:  flutter-package

Flutter BLoC patterns

Codemagic build status Star on GitHub License: MIT


A set of most common BLoC use cases build on top flutter_bloc library.

Key contepts

BLoC

BLoC, aka Business Logic Component, is a state management system for Flutter. It's main goal is to separate business logic from the presentation layer. The BLoC handles user actions or any other events and generates new state for the view to render.

Repository

A Repository to handles data operations. It knows where to get the data from and what API calls to make when data is updated. A Repository can utilize a single data source as well as it can be a mediator between different data sources, such as database, web services and caches.

ViewStateBuilder

ViewStateBuilder is responsible for building the UI based on the view state. It's a wrapper over the BlocBuilder widget so it accepts a bloc object and a set of handy callbacks, which corresponds to each possible state:

  • onReady - informs the presentation layer that view is in it's initial state, and no action has taken place yet,
  • onLoading - informs the presentation layer that the data is being loaded, so it can display a loading indicator,
  • onRefreshing - informs the presentation layer that the data is being refreshed, so it can display a refresh indicator or/and the current state of list elements,
  • onSuccess - informs the presentation layer that the loading is completed and a nonnull and not empty data was retrieved,
  • onEmpty - informs the presentation layer that the loading is completed, but null or empty data was retrieved,
  • onError - informs the presentation layer that the loading or refreshing has ended with an error. It also provides an error that has occurred.
ViewStateListener

ViewStateListener is responsible for performing an action based on the view state. It should be used for functionality that needs to occur only in response to a state change such as navigation, showing a SnackBar etc. ViewStateListener is a wrapper over the BlocListener widget so it accepts a bloc object as well as a child widget and a set of handy callbacks corresponding to a given state:

  • onLoading - informs the presentation layer that the data is being loaded,
  • onRefreshing - informs the presentation layer that the data is being refreshed,
  • onSuccess - informs the presentation layer that the loading is completed and a nonnull and not empty data was retrieved,
  • onEmpty - informs the presentation layer that the loading is completed, but null or empty data was retrieved,
  • onError - informs the presentation layer that the loading or refreshing has ended with an error. It also provides an error that has occurred.

Features

ListBloc

The most basic use case. Allows to fetch, refresh and display a list of elements without filtering and pagination. Thus, ListBloc should be used only with a reasonable amount of data. ListBloc provides the methods for loading and refreshing data: loadElements() and refreshElements(). The former is most suitable for initial data fetch or for retry action when the first fetch fails. The latter is designed for being called after the initial fetch succeeds. It can be performed when the list has already been loaded. To display the current view state ListBloc cooperates with BlocBuilder as well as ViewStateBuilder.

ListRepository

A ListRepository implementation should provide only one method:

Future<List<T>> getAll(); - this method is responsible for providing all the data to the ListBloc.

Where:

  • T is the element type returned by this repository.
Usage

List BLoC Sample App

FilterListBloc

An extension to the ListBloc that allows filtering.

FilterRepository

FilterListRepository provides two methods:

Future<List<T>> getAll(); - this method is called when a null filter is provided and should return all elements, Future<List<T>> getBy(F filter); - this method is called with nonnull filter and should return only elements that match it.

Where:

  • T is the element type returned by this repository,
  • F is the filter type, which can be primitive as well as complex object.

Usage

Filter List BLoC Sample App

PagedListBloc

A list BLoC with pagination but without filtering. It works best with Infinite Widgets but a custom presentation layer can provided as well.

Page

Contains information about the current page, this is number and size.

PagedList

List of elements with information if there are more elements or not.

PagedListRepository

PagedListRepository comes with only one method:

Future<List<T>> getAll(Page page); - this method retrieves elements meeting the pagination restriction provided by the page object. When elements are exceeded it should return an empty list or throw PageNotFoundException. PagedListBloc will handle both cases in the same way.

Where:

  • T is the element type returned by this repository.

Usage

Paged List BLoC Sample App

PagedListFilterBloc

A list BLoC with pagination and filtering. It works best with Infinite Widgets but a custom presentation layer can provided as well.

Page

Contains information about the current page, this is number and size.

PagedList

List of elements with information if there are more elements or not.

PagedListFilterRepository

PagedListFilterRepository provides only two methods:

Future<List<T>> getAll(Page page); - retrieves elements meeting the pagination restriction provided by the page object. Future<List<T>> getBy(Page page, F filter); - retrieves elements meeting pagination as well as the filter restrictions provided by the page and filter objects.

When elements are exceeded it should return an empty list or throw PageNotFoundException. PagedListFilterBloc will handle both cases in the same way.

Where:

  • T is the element type returned by this repository,
  • F is the filter type, which can be primitive as well as complex object.

Usage

Paged List BLoC Sample App

DetailsBloc

A BLoC that allows to fetch a single element with given identifier.

DetailsRepository

DetailsRepository comes with only one method:

Future<T> getById(I id); - this method retrieves an element with given id. When there's no element matching the id the null should be returned or ElementNotFoundException should be thrown. In both cases the DetailsBloc will emit Empty state.

Where:

  • T is the element type returned by this repository,
  • I is the id type, it can be primitive as well as a complex object.

Usage:

List/Details BLoC Sample App

Dart version

  • Dart 2: >= 2.12.0

Author

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].