NiiTii
NiiTii

Reputation: 256

How to check when the slider is decrementing and have a function for when it does?

I want to increment the value of a var for when the slider is incrementing and decrement that value when the slider is decrementing, I did the first part but I'm stuck on the second one can anyone point out what I should do?

My slider code:

                              child: Slider(
                                value: sliderValue,
                                min: min,
                                max: activityMax,
                                divisions: 4,
                                label: '${sliderValue.round().toString()}',
                                mouseCursor: MouseCursor.uncontrolled,
                                autofocus: true,
                                onChanged: (value) {
                                  setState(
                                    () {
                                      sliderValue = value;
                                      _amountController.text =
                                          sliderValue.toInt().toString();
                                      sizeHeight += 250;
                                    },
                                  );
                                },
                              ),

Upvotes: 0

Views: 198

Answers (1)

Josteve Adekanbi
Josteve Adekanbi

Reputation: 12673

Try this:

Slider(
   value: sliderValue,
   min: min,
   max: activityMax,
   divisions: 4,
   label: '${sliderValue.round().toString()}',
   mouseCursor: MouseCursor.uncontrolled,
   autofocus: true,
   onChanged: (value) {
     if(value < sliderValue){
       executeWhenDecrementing();
     }
     setState(
        () {
          sliderValue = value;
          _amountController.text = sliderValue.toInt().toString();
      });
    },
)
void executeWhenDecrementing(){
//Do something
}

Upvotes: 2

Related Questions