All Projects → robertohuertasm → generic_bloc_provider

robertohuertasm / generic_bloc_provider

Licence: MIT license
Generic BloC provider implementation

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to generic bloc provider

bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 12 (-53.85%)
Mutual labels:  state-management, bloc
bloc samples
A collection of apps built with the Bloc library.
Stars: ✭ 39 (+50%)
Mutual labels:  state-management, bloc
devon4flutter-non-bloc-arch
A guide aiming to bridge the gap between the absolute Flutter basics and clean, structured Flutter Development
Stars: ✭ 283 (+988.46%)
Mutual labels:  state-management, bloc
flutter-bloc-patterns
A set of most common BLoC use cases built on top of flutter_bloc library
Stars: ✭ 58 (+123.08%)
Mutual labels:  state-management, 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 (+80.77%)
Mutual labels:  state-management, bloc
Bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 8,214 (+31492.31%)
Mutual labels:  state-management, bloc
Controllerim
A state management library for React
Stars: ✭ 213 (+719.23%)
Mutual labels:  state-management
React Agent
Client and server-side state management library
Stars: ✭ 235 (+803.85%)
Mutual labels:  state-management
Tinystate
A tiny, yet powerful state management library for Angular
Stars: ✭ 207 (+696.15%)
Mutual labels:  state-management
Eiffel
Redux-inspired Android architecture library leveraging Architecture Components and Kotlin Coroutines
Stars: ✭ 203 (+680.77%)
Mutual labels:  state-management
Xstate
State machines and statecharts for the modern web.
Stars: ✭ 18,300 (+70284.62%)
Mutual labels:  state-management
Pulse
✨ Pulse is a global state and logic framework for reactive Typescript & Javascript applications. Supporting frameworks like VueJS, React and React Native.
Stars: ✭ 243 (+834.62%)
Mutual labels:  state-management
Getx pattern
Design pattern designed to standardize your projects with GetX on Flutter.
Stars: ✭ 225 (+765.38%)
Mutual labels:  state-management
Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+730.77%)
Mutual labels:  state-management
Redux Tiles
Composable way to create less verbose Redux code
Stars: ✭ 239 (+819.23%)
Mutual labels:  state-management
React Easy State
Simple React state management. Made with ❤️ and ES6 Proxies.
Stars: ✭ 2,459 (+9357.69%)
Mutual labels:  state-management
Final Form
🏁 Framework agnostic, high performance, subscription-based form state management
Stars: ✭ 2,787 (+10619.23%)
Mutual labels:  state-management
Reusable
Reusable is a library for state management using React hooks
Stars: ✭ 207 (+696.15%)
Mutual labels:  state-management
Use Machine
React Hook for using Statecharts powered by XState. use-machine.
Stars: ✭ 226 (+769.23%)
Mutual labels:  state-management
Vue Class Store
Universal Vue stores you write once and use anywhere
Stars: ✭ 243 (+834.62%)
Mutual labels:  state-management

generic_bloc_provider

Build Status License: MIT Pub

A generic BloC Provider for your Flutter apps.

Getting Started

All your BloCs must extend the Bloc abstract class. This means that all of them should have a dispose method that will be executed whenever the life of the BloC comes to an end.

In this method, you should take care of closing all the sinks and resources.

Example of how to use it:

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      bloc: AppBloc(),
      child: MaterialApp(
        title: 'Yo Sleep',
        home: MainPage(),
        initialRoute: 'main',
        routes: {
          'main': (context) => MainPage(),
        },
      ),
    );
  }
}

class MainPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final appBloc = BlocProvider.of<AppBloc>(context);
    return Scaffold(
      body: SafeArea(
        child: Column(
          children: <Widget>[
            Header(),
            RecordList(appBloc),
          ],
        ),
      ),
    );
  }
}

Attaching your context to the InheritedWidget

The BlocProvider class depends on InheritedWidget. Whenever you want to get your BloC, you can decide wether to attach the context of your widget to the InheritedWidget or not.

In order to control this behavior, the static method of has an optional boolean argument (which is true by default) which determines wether your context will be attached or not.

Basically, if you don't provide it or you just set it to true, dependOnInheritedWidgetOfExactType will be used. If you set it to false then getElementForInheritedWidgetOfExactType will be used instead.

Customizing the update policy

If you want to change the way updateShouldNotify behaves you have the option to provide a custom anonymous function to the BlocProvider constructor.

You will notice that there's an argument called updateShouldNotifyOverride which accepts a function receiving a BloC and the internal InheritedWidget:

bool Function(T bloc, _BlocProvider oldWidget);

This is the default implementation of the updateShouldNotify method:

@override
  bool updateShouldNotify(_BlocProvider oldWidget) =>
      updateShouldNotifyOverride != null
          ? updateShouldNotifyOverride!(bloc, oldWidget)
          : oldWidget.bloc != bloc;
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].