我有开关和滑块。 该按钮应启用和禁用滑块,以便用户不能更改滑块。
我怎样才能完成这件事呢? 谢谢你的帮助。
Switch(
value: notifyswitch,
onChanged: (value) {
setState(() {
notifyswitch = value;
});
},
),
Center(
child: Text(timeoutstring, style: TextStyle(fontSize: 20, color: Theme.of(context).accentColor))
),
Slider(
min: 0.0,
max: 48,
divisions: 24,
value: _timeoutvalue,
onChanged: (value) {
setState(() {
_timeoutvalue = value;
timeoutstring = _timeoutvalue.toInt().toString() + "h";
});
},
)
当switch
值为true时,使滑块的onchanged
为空
Switch(
value: notifyswitch,
onChanged: (value) {
setState(() {
notifyswitch = value;
});
},
),
Center(
child: Text(timeoutstring, style: TextStyle(fontSize: 20, color: Theme.of(context).accentColor))
),
Slider(
min: 0.0,
max: 48,
divisions: 24,
value: _timeoutvalue,
onChanged: notifyswitch?null:(value) {
setState(() {
_timeoutvalue = value;
timeoutstring = _timeoutvalue.toInt().toString() + "h";
});
},
)