下面的代码仅将滑块从1-10更改,如何在Flutter中更改滑块的同时更改文本?
文本是从API获取的。
double _value = 0.0;
[enter image description here][1] bool _slider = false;
child: _slider == true
? new Container(
margin: EdgeInsets.only(right: 10),
decoration: new BoxDecoration(
color: NNDColors.main,
borderRadius: new BorderRadius.all(
new Radius.circular(5.0)),
boxShadow: [
new BoxShadow(
color: Colors.black38,
offset: new Offset(0.0, 2.0),
blurRadius: 10)
]),
child: new Slider(
value: _value,
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) => _changed(s),
divisions: 10,
min: 0.0,
max: 10.0,
),
void _changed(s) {
setState((){
_value = s;
});
}
答案 0 :(得分:0)
输出:
这是您的操作方法。
double _value = 5;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Testing")),
body: Center(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(right: 10),
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
boxShadow: [new BoxShadow(color: Colors.black38, offset: new Offset(0.0, 2.0), blurRadius: 10)]),
child: new Slider(
value: _value,
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) {
setState(() {
_value = s;
});
},
divisions: 10,
min: 0.0,
max: 10.0,
),
),
Text("Hello World", style: TextStyle(fontSize: 10 * _value)),
],
),
),
);
}