0

I use ValueNotifier in Flutter and use setValue when data changed.

ValueNotifier<GameResultMessage?> gameResultMessage = ValueNotifier(null);
//
gameResultMessage.value = gameResultMessage;

setValue source code

  set value(T newValue) {
    if (_value == newValue) {
      return;
    }
    _value = newValue;
    notifyListeners();
  }

I want to notify observer everytime whatever data is new or old. (Run some animation)

But when I call notifyListeners() animation will run twice. If I don't call notifyListeners(), animation won't run when data not changed.

How to solve it?

GHH
  • 1,713
  • 1
  • 8
  • 21
  • so the `value` setter is a part of custom `ChangeNotifier` implementing `ValueListenable` or something? if so, why do you use `ValueNotifier` and not your class? – pskink May 17 '23 at 08:58
  • @pskink yes because `ValueNotifier` has callback listener and I use it in other class. – GHH May 18 '23 at 02:04

0 Answers0