Атрибут модификатора вызывается во время сборки, поэтому вы не можете установить состояние. Чтобы получить окончательное значение (когда пользователь поднимает палец), используйте onChangedEnd и onChange для каждого шага.
import 'package:flutter/material.dart';
import 'package:sleek_circular_slider/sleek_circular_slider.dart';
class WeightSlider extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<WeightSlider> {
double myValue;
@override
void initState() {
super.initState();
myValue = 0;
}
otherMethod(String rounded) {
print("rounded: " + rounded);
}
@override
Widget build(BuildContext context) {
final slider = SleekCircularSlider(
min: 0,
max: 120.0,
initialValue: 60,
appearance: CircularSliderAppearance(
size: 279,
startAngle: 120,
angleRange: 300,
animationEnabled: true,
infoProperties: InfoProperties(
bottomLabelText: 'kg',
bottomLabelStyle: TextStyle(
fontSize: 25,
),
mainLabelStyle: TextStyle(
fontSize: 70,
fontFamily: 'RalewaySemiBold',
),
),
customColors: CustomSliderColors(
hideShadow: true,
trackColor: Color(0XFFFFF176),
dotColor: Color(0XFFFAFAFA),
progressBarColor: Color(0XFF00E676),
),
customWidths: CustomSliderWidths(
trackWidth: 5,
progressBarWidth: 20,
handlerSize: 4,
)),
innerWidget: (double value) {
// use your custom widget inside the slider (gets a slider value from the callback)
return Column(
children: <Widget>[
Slider(
value: value,
min: 0,
max: 120,
onChanged: (double weight) {
setState(() {
String newValue = weight.ceil().toInt().toString();
print("$newValue");
otherMethod(newValue);
});
}),
Container(
color: Colors.deepPurpleAccent,
child: Text(
"Test text $value",
style: TextStyle(color: Colors.black),
))
],
);
},
onChangeEnd: (double weight) {
setState(() {
String newValue = weight.ceil().toInt().toString();
print("$newValue");
otherMethod(newValue);
});
},
);
return Container(
child: Column(
children: <Widget>[
Center(child: slider),
],
),
);
}
}