A simple state management solution that combine the power of inherited widget and rxdart

Overview

pub package

A simple state management solution that combine the power of inherited widget and rxdart

Features

Create state management logic for your app using multitude of blocs, which internal is just stream and rxdart, you can access them anywhere in your widget tree when provided using providers.

Getting started

Started by providing blocs and service for your widget's subtree like this:

First import it:

import 'package:inherited_rxdart/inherited_rxdart.dart';

Create your bloc and state:

@immutable
class MyState {
  final int number;
  final String text;

  const MyState({required this.number, required this.text});

  MyState copyWith({int? number, String? text}) {
    return MyState(number: number ?? this.number, text: text ?? this.text);
  }
}

// Define bloc with two type:
// MyState: State of the bloc
// String: Type of notification
class CounterBloc extends RxBloc<MyState, String> {
  CounterBloc(MyState initialState) : super(initialState);

  void showDialog() {
    // will notify all notification listeners
    notify("showDialog");
  }

  void changeText(String newText) {
    // will cause dependent to rebuild
    state = state.copyWith(text: newText);
  }

  void increase() {
    // will cause dependent to rebuild
    state = state.copyWith(number: state.number + 1);
  }

  void decrease() {
    // will cause dependent to rebuild
    state = state.copyWith(number: state.number - 1);
  }
}

And start using it in your app:

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: RxProvider<CounterBloc>(
          create: () => CounterBloc(const MyState(text: "hi", number: 0)),
          child: MyHomePage(),
        )
    );
  }
}

Access them anywhere in your subtree with:

final bloc = RxProvider.of<CounterBloc>(context);

Usage

View documents of each API for more details. The library support bloc pattern and view model pattern for your app.

Bloc's Widgets

For blocs, there will be specific widget for each purpose include: rebuilding, listening,...

  • RxBuilder: For building widgets based on states.
  • RxListener: For listening to state changes and notifications.
  • RxStateListener: For listening to state changes only.
  • RxConsumer: Combination of RxListener and RxBuilder.
  • RxStateConsumer: Combination of RxStateListener and RxBuilder.
  • RxSelector: For selectively rebuilding widgets based on specific property of state.

RxCubit:

A simple bloc, which will emit states throughout its life-cycle and rebuild widgets when necessary. Work with:

  • RxBuilder
  • RxSelector
  • RxStateConsumer
  • RxStateListener

RxBloc:

Bloc with notification beside states, which can be listened and react accordingly. Work with:

  • RxBuilder
  • RxListener
  • RxStateListener
  • RxConsumer
  • RxStateConsumer
  • RxSelector

RxViewModel

For simple view model based state-management, shipped with related widget:

  • RxViewModelBuilder: for handle rebuilding widget when a new state is emitted.
  • RxViewModelSelector: for selectively rebuilding when state changed.
  • RxViewModelListener: for a listener callback when state changed.
  • RxViewModelConsumer: combination of builder and listener.

RxValue

A value for reactive state management, will cause its dependent to rebuild when its value is set.

  • RxValueBuilder: build to work with RxValue.

ServiceProvider

There's also simple service provider for repo or simply to inject an instance through a widget subtree.

  • ServiceProvider

Rx

Though not really inherited, this library do provide the use of register an instance through GetIt, and use them in builders, listeners .value constructor. This feature can be access with Rx static method

Additional information

To provide multiple blocs/view model/service instances, the use of these widget is encouraged:

  • RxMultiProvider
  • MultiServiceProvider

To quickly access blocs/services, rather than use these function:

RxProvider.of<MyBloc>(context);
ServiceProvider.of<MyService>(context);

One can use:

context.watch<MyBloc>(); // for getting an instance of a bloc / view model and subscribe to it's changes.
context.read<MyBloc>(); // for getting an instance of a bloc/view model
context.get<MyService>(); //for getting an instance of a service. 

And

final text = RxValue<String>("hello");

Is equivalent to:

final text = "hello".rx;
You might also like...

A flutter state management solution.

A Flutter State Management solution with dependency injection Usage Create your business logic class and place all variables, methods inside it. impor

Dec 15, 2022

A simple application connected with API (The Movie Database), related to movies. Application created using BLoC pattern and RxDart

MovieApp I will not hide that this is the most difficult application I have done so far (and I am still working on new features). It looks like this (

Oct 28, 2022

State Persistence - Persist state across app launches. By default this library store state as a local JSON file called `data.json` in the applications data directory. Maintainer: @slightfoot

State Persistence Persist state across app launches. By default this library store state as a local JSON file called data.json in the applications dat

Sep 28, 2022

Shopify Tag and Product Management App using Flutter and Riverpod State Management

Shopify Tag and Product Management App using Flutter and Riverpod State Management

Myshopify App A Simple Flutter Application project to get List of Tags, Products and Product Details from shopify https://shopicruit.myshopify.com/adm

Nov 12, 2022

An extension to the bloc state management library which lets you create State Machine using a declarative API

An extension to the bloc state management library which lets you create State Machine using a declarative API

Nov 28, 2022

A powerful state machine for MobX management, that can be used in almost any application state.

A powerful state machine for MobX management, which can be used in almost any application state. It has 3 states - loading, success, error - and is pe

Oct 31, 2022

Practice building basic animations in apps along with managing app state by BLoC State Management, Flutter Slider.

Practice building basic animations in apps along with managing app state by BLoC State Management including: Cubit & Animation Widget, Flutter Slider.

Jun 8, 2022

Practice code of simple flutter app to explain how provider works as across the widget state management.

vdo A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this is y

Nov 7, 2022

A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and Dio to architect a flutter project. This starter kit build an App Store app as a example

A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and Dio to architect a flutter project. This starter kit build an App Store app as a example

Flutter Starter Kit - App Store Example A starter kit for beginner learns with Bloc pattern, RxDart, sqflite, Fluro and Dio to architect a flutter pro

Jan 8, 2023
Releases(v2.0.0)
Owner
Nguyễn Ngọc Phước
Contacts: [email protected] 0818828659
Nguyễn Ngọc Phước
Behruz Hurramov 0 Dec 29, 2021
Various extensions on BuildContext to access inherited widget's state

context_extentions Getting inherited widget's state var themeData = context.theme; var scaffold = context.scaffold; var navigator = context.navi

Ali Ghanbari 4 Sep 23, 2021
Dart package for Async Data Loading and Caching. Combine local (DB, cache) and network data simply and safely.

Stock is a dart package for loading data from both remote and local sources. It is inspired by the Store Kotlin library.

xmartlabs 59 Dec 24, 2022
Combine a set of dart files into one

dart-merger Combine a set of dart files into one. This is useful when you want to organize a group of files automatically generated by generator. Inst

Kenta Murai 2 Mar 17, 2022
Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to tidily bound separated logic into complex solution.

Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to

Roman Hornak 23 Feb 23, 2022
⚡FQuery is a powerful async state management solution for flutter. It caches, updates and fully manages asynchronous data in your flutter apps.

⚡ FQuery is a powerful async state management solution for flutter. It caches, updates and fully manages asynchronous data in your flutter apps. It ca

Piyush 21 Dec 22, 2022
🚀 User management app built in flutter using clean architecture, MVVM, get it, dio, RxDart, bloc, cubit, getX and provider

?? Go Rest app In this project, we are going to build a user management app using Flutter. We have used the Go REST API to make HTTP request methods.

Sina 99 Aug 14, 2023
Cubit is a lightweight state management solution

Cubit is a lightweight state management solution. It is a subset of the bloc package that does not rely on events and instead uses methods to emit new states.

Felix Angelov 582 Nov 23, 2022
GetX - one of the most popular state management solution in flutter

GteX Tutorial - Udemy GetX is one of the most popular state management solution in flutter. In addition to state management, GetX provides easy way to

Md. Siam 3 May 18, 2022
This repo is an example of clean architecture using the GetX state-management solution.

GetX Clean Architecture A Flutter Clean Architecture Using GetX. This repo is forked from: https://github.com/phamdinhduc795397/flutter-getx-clean-arc

Md. Siam 78 Jan 3, 2023