搜索插件、代码仓与 APP 分类

GitHub 代码仓Flutterando/rx_notifier

rx_notifier

通过透明应用函数式响应式编程(TFRP)扩展 ValueNotifier

rx_notifier 项目封面
星标
43
复刻
13
最近推送(UTC)
2025年6月13日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

rx_notifier

The ValueNotifier is a simple, native form of Flutter reactivity. This extension aims to transparently apply functional reactive programming (TFRP).

Implementing the Atomic State.

It is possible to implement Recoil Atoms pattern using RxNotifier. This pattern consists of the state being an object with its own reactivity.

atom

Motivation

Developers still have trouble understanding state management in Flutter. We had this conclusion after several research in the community fluttering and also in partner companies. Atomic State is a noob-friendly state management approuch at the same time that maintains a reliable structure thinking of scalability and maintenance.

More details, read this Medium article on the subject.

Rules

We must take into account some architectural limits to execute this Approach:

  1. All states must be an atom(RxNotifier instance).
  2. All actions must be an atom(RxNotifier instance).
  3. Business rules must be created in the Reducer and not in the Atom.

Layers

We will have 3 main layers, they are: Atoms, Reducers and Views;

atom

Note that the View (which is the presentation layer) does not know about the Reducer (which is the business rule execution layer). These two layers share atoms that in turn represent the state and the dispatch of state actions.

In Flutter these layers translate to Atom(RxNotifier), Reducer(RxReducer) and View(Widget):

atom

Atoms (RxNotifier)

Atom represent the reactive state of an application. Each atom has its own reactivity.

// atoms
final productsState = <Product>[].asRx();
final productTextFilterState = RxNotifier<String>('');

// computed
List<Product> get filteredProductsState {
     if(productTextFilterState.value.isEmpty()){
         return productsState.value;
     }

     return productsState.where(
         (p) => p.title.contains(productTextFilterState.value),
     );
}

// actions
final selectedProductState = RxNotifier<Product?>(null);
final fetchProductsState = RxNotifier(null);

Reducer (RxReducer)

In this architecture you are forced to split state management of business rules, which may seem strange at first when seen that we are always managing and reducing state in the same layer as BLoC and ChangeNotifier for example.
However, dividing state management and business rule execution will help us distribute multiple states to the same widget, and these multiple states will not need to be concatenated beforehand through a facade or proxy.

The layer responsible for making business decisions will be called Reducer:

class ProductReducer extends RxReducer {

    ProductReducer(){
        on(() => [fetchProductsState.action], _fetchProducts);
        on(() => [selectedProductState.value], _selectProduct);
    }

    void _fetchProducts(){
        ...
    }

    void _selectProduct(){
        ...
    }
}

Reducers can register methods/functions that listen to the reactivity of an Atom(RxNotifier).

View (Widget)

Any widget can listen to changes of one or many atoms, provided they have the RxRoot widget as their ancestor. For more details about RxRoot, Read the documentation.

The context.select() method is added via Extension to BuildContext and can be called on any type of Widget, StatefulWidget and StatelessWidget.


...
Widget build(BuildContext context){
     final products = context.select(
                 () => filteredProductsState.value
              );
     ...
}

Examples

Flutter projects using RxNotifier

Trivial Counter.

Shop Cart.

Flutterando GitHub avatar
GitHub 作者

Flutterando ↗

The biggest and most active Flutter community in Latin America. Responsible for packages like flutter_modular and flutter_triple.

语言DartC++CMakeHTMLSwiftCKotlinObjective-C

此仓库发布的插件

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗