我正在为BMI计算器编写代码,并且我正在使用滑块的高度,它会返回一个double类型的long类型。我尝试了_startHeight.toInt()
,但没有成功。而且有没有不用分隔就可以显示标签的方法。
这是我的滑块代码。
Slider(
value: _startHeight,
min: 1,
max: 100,
onChanged: (newHeight) {
setState(() {
_startHeight = newHeight;
_startHeight.toInt();
print(_startHeight);
});
},
),
谢谢。
如果您想将_startHeight
设为int
,那么我首先假设您将其定义为int
。
您正在尝试将double
分配给int
,然后将该double
更改为int
。您需要采用其他方法:
onChanged: (double newHeight) {
setState(() {
_startHeight = newHeight.toInt();
print(_startHeight);
});
}