Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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;
                                    },
                                  );
                                },
                              ),

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading