class SliderDemo extends StatefulWidget {
@override
_SliderDemoState createState() => _SliderDemoState();
}
class _SliderDemoState extends State<SliderDemo> {
double _sliderItemA = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SilderDemo'),
elevation: 0,
),
body: Container(
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Slider(
value: _sliderItemA,
onChanged: (value) {
setState(() {
_sliderItemA = value;
});
},
min: 0,
max: 10,
divisions: 10, // 将滑块划分为几份
label: '${_sliderItemA.toInt()}', // 将double转换为int类型的数值,一遍label显示
activeColor: Theme.of(context).accentColor,
inactiveColor: Theme.of(context).accentColor.withOpacity(0.3), // 未滑到的区域的颜色
)
],
),
SizedBox(height: 16,),
Text('SliderValue: $_sliderItemA'),
],
),
),
);
}
}
预览
网友评论