flutter_dynamic_forms icon indicating copy to clipboard operation
flutter_dynamic_forms copied to clipboard

MutableProperty ignoreLastChange

Open Overman775 opened this issue 3 years ago • 0 comments

Hi! i found some bug in MutableProperty setValue function, maybe it's not a bug, i dont know 😄

Problem what i need force update value, because i listen this value in difrent places, but trigger ignoreLastChange don't usese in void setValue. I have not found ignoreLastChange in the code where this trigger is used, is it a logical mistake?

solution 1: check ignoreLastChange

  void setValue(T value, {bool ignoreLastChange = false}) {
    _ignoreLastChange = ignoreLastChange;
    var oldValue = _cachedValue;
    _cachedValue = value;
    expression.value = value;
    if (ignoreLastChange ? true : _cachedValue != oldValue) {
      valueChangedSubject?.add(_cachedValue);
      notifySubscribers();
    }
  }

solution 2: add trigger force

  void setValue(T value, {bool ignoreLastChange = false, bool force = false}) {
    _ignoreLastChange = ignoreLastChange;
    var oldValue = _cachedValue;
    _cachedValue = value;
    expression.value = value;
    if (force ? true : _cachedValue != oldValue) {
      valueChangedSubject?.add(_cachedValue);
      notifySubscribers();
    }
  }

First variant looking better.

Overman775 avatar Mar 26 '21 14:03 Overman775