【问题标题】:How to buld slider without sliding function in flutter如何在颤动中构建没有滑动功能的滑块
【发布时间】:2021-06-20 02:14:50
【问题描述】:

我想在 Flutter 中像这样构建滑块(类似于 SleekCircularSlider)

【问题讨论】:

    标签: flutter slider


    【解决方案1】:

    您可以根据需要使用内置的颤振Slider 小部件来实现此目的。找到下面的代码sn-ps。

    final double sliderValue = 90.0;
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(),
          body: Container(
            width: 350,
            height: 350,
            child: SliderTheme(
              data: SliderThemeData(
                overlayColor: Colors.transparent,
                thumbShape: SliderComponentShape.noThumb,
              ),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Text('HTML'),
                      Text(sliderValue.toInt().toString() + '%')
                    ],
                  ),
                  Slider(
                      value: 90,
                      min: 0.0,
                      max: 100.0,
                      divisions: 100,
                      mouseCursor: MouseCursor.uncontrolled,
                      onChanged: (double value) {}),
                ],
              ),
            ),
          ),
        );
      }
    

    【讨论】:

      【解决方案2】:

      final  double value = 0.9;
      
      Container(
                color: Colors.black,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(
                          'html',
                          style: TextStyle(color: Colors.white),
                        ),
                        Text(
                          '$value%',
                          style: TextStyle(color: Colors.grey),
                        )
                      ],
                    ),
                    LinearProgressIndicator(
                      value: 0.9,
                      color: Colors.yellow,
                    )
                  ],
                ),
              ),
      

      【讨论】:

      • 但是我们怎样才能给它添加动画,就像 SleekCircularSlider 默认有的一样
      • 当值 var 改变时使用 setState 或 State 管理监听
      猜你喜欢
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 2020-09-24
      • 2018-11-02
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多