OndrejKunc / flutter_dynamic_forms

A collection of flutter and dart libraries allowing you to consume complex external forms at runtime.
MIT License
204 stars 60 forks source link

MutableProperty ignoreLastChange #95

Open Overman775 opened 3 years ago

Overman775 commented 3 years ago

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.