Pakete, Repositories und App-Kategorien suchen

Paketdetailsv2.3.0

rx_notifier

Erweiterung von ValueNotifier durch transparente Anwendung funktionaler reaktiver Programmierung (TFRP)

AndroidiOSWebmacOSWindowsLinux
30-Tage-Downloads
2780
Likes
82
Pub-Punkte
140

Paket installieren

flutter pub add rx_notifier

Paketübersicht

Aus öffentlichen Paketdaten erstellte Orientierung.

RxNotifier ist ein Flutter/Dart-Paket, das ValueNotifier mit transparenter funktioneller Reaktionsprogrammierung (TFRP) erweitert. Es ermöglicht reaktive Zustandsverwaltung, indem Entwickler Zustandsänderungen mithilfe funktionaler Operatoren zusammensetzen und transformieren können, wobei die Einfachheit von ValueNotifier beibehalten wird. Das Paket lässt sich nahtlos in bestehende Flutter-Anwendungen integrieren und bietet eine leichte Alternative zur Zustandsverwaltung mit reaktiven Mustern ohne Boilerplate. Es unterstützt alle Hauptplattformen und fördert sauberen, testbaren Code durch immutable Updates und streamähnliche Transformationen.

Anwendungsfälle

  • Reaktive UI-Zustandsaktualisierungen
  • Komplexe Zustandslogik zusammensetzen
  • Ersetzen mehrerer ValueNotifiers
  • Zustandsüberführung vereinfachen
  • Reaktive Formulare erstellen
  • Asynchronen Zustand verwalten

Hauptmerkmale

  • Funktionale Reaktive Programmierung
  • Transparente TFRP-Integration
  • Immutable Zustandsaktualisierungen
  • Stream-ähnliche Operatoren
  • Minimales Boilerplate
  • Plattformübergreifende Unterstützung

Geeignet für

  • Entwickler, die reaktive Zustandsverwaltung suchen
  • Apps mit zusammensetzbarer Zustandslogik
  • Teams, die funktionale Programmierung bevorzugen
  • Projekte, die schwere Zustandsmanager vermeiden
  • Flutter-Anfänger lernen reaktive Muster
  • Apps, die leichtgewichtige Zustandslösungen erfordern

Hinweise

  • Erfordert Verständnis funktionaler Programmierkonzepte
  • Kann eine Lernkurve für Anfänger mit sich bringen
  • Beschränkt auf reaktive Muster basierend auf ValueNotifier
  • Nicht ideal für den Einsatz bei sehr groß angelegter Zustandsverwaltung
  • Am besten geeignet für Zustandsbedarf mittlerer Komplexität
  • Ersetzt vollständige reaktive Frameworks wie RxDart nicht

Original-README

Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.

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.

Kategorien

Abhängigkeiten

Abhängigkeiten 2 Einträge

  • collection^1.17.0
  • rx_notifier_annotation>=1.0.0 <2.0.0

Quell-Repository

Projekte, die dieses Paket verwenden

Noch keine Daten verfügbar.