matthewfx / sleek_circular_slider

Sleek circular slider for Flutter
MIT License
524 stars 102 forks source link

Detect if value change come from user #18

Open RegisSaffi opened 4 years ago

RegisSaffi commented 4 years ago

Thanks for this widget,it is really awesome and customizable, but i am wondering if i want to set a value dynamically how would i do it? well, i can set the initial value and i can update it, but if i want to use both user interaction change and dynamic value change i can't do it, if you can add where i can know if the value change is coming from the user interaction or not, it could be useful in many cases.

matthewfx commented 4 years ago

Hmm... I will think about it. Currently very busy...

estevez-dev commented 4 years ago

Lets assume you have some source where you can get the value when change came not from user. Let it be:

MyDataStorage

With above in mind:

bool _changedHere = false;
double _value = 0;

Widget build(BuildContext context) {
if (!_changedHere) {
  _value = MyDataStorage.getValue(); //Data NOT from user
} else {
  _changedHere == false; //Change was done by user, so we'll not change the value, but only during current widget build
}
return SleekCircularSlider(
  min: 0,
  max: 255,
  initialValue: _value,
  onChangeEnd: (val) {
    setState((){
      _changedHere = true;
      _value = val;
    });
  }
);
}

I don't think this should be done in plugin itself.

spixy commented 3 years ago

Also if you have animations enabled and see a tearing, create one CircularSliderAppearance and then reuse it, don´t create it on every build.

surister commented 3 years ago

Also if you have animations enabled and see a tearing, create one CircularSliderAppearance and then reuse it, don´t create it on every build.

This should be in the docs, the tearing drove me crazy for weeks, I was able to solve it by hacking setStates around the place, but your comment solves everything. Many many thanks @spixy !