I have been looking but couldn't find any reference to this. I would like to create a private setter in Dart to call an additional function after I have changed a private variable.
ViewState _state;
ViewState get state => _state;
set _state(value) {
_state = value;
notifyListeners();
}
How Can I achieve this?
Dart is no allowing private setters, it's true. You can hack it with your own private function
ViewState _state;
ViewState get state => _state;
void _changeState(value) {
_state = value;
notifyListeners();
}
here my sample on DartPad where you can make some experiments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With