GetRxDecorator<T> class

GetRxDecorator for Rx

============================================================================

Why one need to use this decorator? Because of problem with Rx

Mainly, direct using this reactive variables violates all of known design patterns. Client (some View) send command to change state and get result immediately without Model processing.

We should to hide variable itself behind accessors, and this decorator makes it in very handy way.

============================================================================

Without GetRxDecorator

  // declarations:

  /// 1. Variable itself.
  final _clickCounterUdf = 0.obs;

  /// 2. Getter
  int get clickCounterUdf => _clickCounterUdf();

  /// 3. Setter
  set clickCounterUdf(int v) => _clickCounterUdf(_process(v));

  /// 4. Stream
  Stream<int> get clickCounterStreamUdf => _clickCounterUdf.stream;

  /// This processor drops values above 3 down to zero.
  int _process(int v) => v > 3 ? 0 : v;

  //=======================================================

  // using:
  // Somewhere in View
  return Center(
    child: ElevatedButton(
      child: Obx(
         () => Text('value = ${controller.clickCounterUdf}'),
      ),
      onPressed: () => controller.clickCounterUdf++,
    ),
  );

With GetRxDecorator


// declaration:

/// Encapsulated Rx variable
late var clickCounterDecor = 0.obsDeco(setter: (_, newValue, __) =>
  _process(newValue ?? 0));

//=========================================================================

// using:
// Somewhere in View
return Center(
 child: ElevatedButton(
   child: Obx(
         () => Text('value = ${controller.clickCounterDecor}'),
   ),
   onPressed: () => controller.clickCounterDecor++,
 ),
);

Implementers

Constructors

GetRxDecorator(T initial, {GetRxDecoratorSetter<T>? setter, bool? forceRefresh})

Properties

forceRefresh bool?
Force auto refresh.
final
hashCode int
The hash code for this object.
no setterinherited
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setter GetRxDecoratorSetter<T>?
Callback for adjust custom setter. oldValue parameter allows to apply specific algorithms, e.g. without newValue, like a Collatz conjecture (see tests). withArgs parameter allows using additional arguments in algorithms, e.g. type or instance of variable's sender or something (see tests).
final
stream Stream<T>
Decorates .obs inner stream.
no setter
string String
Same as toString() but using a getter.
no setter
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
value ↔ T
Decorates getter.
getter/setter pair

Methods

call([T? value, dynamic args]) → T
Decorates .call(T? value) but with additional args parameter.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
refresh() → void
toString() String
A string representation of this object.
withArgs(dynamic args) → T
Additional setter in cases when no need to change value itself. For example, when every call changes inner value only depending on external arguments (see Collatz conjecture setter test)

Operators

operator ==(Object other) bool
The equality operator.
inherited