美文网首页
Flutter-Silder

Flutter-Silder

作者: 梦幽辰 | 来源:发表于2020-01-01 20:55 被阅读0次
    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'),
              ],
            ),
          ),
        );
      }
    }
    
    预览

    相关文章

      网友评论

          本文标题:Flutter-Silder

          本文链接:https://www.haomeiwen.com/subject/akygoctx.html