I am trying to create a custom vertical slider with 4 in a row and I am using Syncfusion package, however, when I create a customer widget, onchanged parameter does not accept the Function variable when passed.
SfSliderTheme(
data: SfSliderThemeData(
thumbColor: Colors.blue[200],
activeTrackHeight: kactive_slider_height,
inactiveTrackHeight: kinactive_slider_height,
activeTrackColor: kactive_slider_track_color,
inactiveTrackColor: Colors.black,
trackCornerRadius: -1.0,
),
child: SfSlider.vertical(
min: 0.0,
max: 100.0,
value: value,
onChanged: (value) {},
),
),
This is my code and I am using multiple times, I want to create a custom widget but onChanged: does not take void Function onPressed. Is there a way?
CodePudding user response:
It looks like SfSlider.vertical
does take in a ValueChanged
function but I think you're seeing an error because there is not enough type information? Based on the documentation it looks like there is no generic associated with SfSlider
so the callback you should use would use dynamic
e.g (dynamic value) { ... }
child: SfSlider.vertical(
min: 0.0,
max: 100.0,
value: value,
onChanged: (dynamic value) {},
),
CodePudding user response:
While interacting with the slider, we will get the new value in the onChanged method. So that we can update the slider thumb with the new value. The new value is the type of dynamic, because the slider supports numeric and date time types.
double value = 50.0;
SfSlider.vertical(
min: 0.0,
max: 100.0,
value: value,
onChanged: (dynamic newValue) {
setState(() {
value = newValue;
});
},
)