首页 > 解决方案 > 颤振滑块小部件没有动画

问题描述

我编写了滑块小部件的代码,您可以在其中通过滑动获取高度。但问题是,当您在控制台中打印高度时,它是正确的。但是滑块既不移动,运行时高度值也没有变化。我什至构建了一个 APK,但问题仍然存在于物理设备中。

SliderTheme(
                data: SliderTheme.of(context).copyWith(
                  inactiveTrackColor: Color(0xFF8D8E98),
                  activeTrackColor: Colors.white,
                  thumbColor: Color(0xFFEB1555),
                  overlayColor: Color(0x29EB1555),
                  thumbShape:
                  RoundSliderThumbShape(enabledThumbRadius: 15.0),
                  overlayShape:
                  RoundSliderOverlayShape(overlayRadius: 30.0),
                ),
                child: Slider(
                  value: height.toDouble(),
                  min: 120.0,
                  max: 220.0,
                  onChanged: (double newValue) {
                    setState(() {
                      height = newValue.round();
                    });
                  },
                ),
              ),

甚至使用了 setState 方法。int height 已经声明。

标签: flutterflutter-animation

解决方案


我发现了我在 @override Widget build(BuildContext context)方法中初始化高度值的问题。相反,高度值应该在 _InputPageState(stateful widget class)方法之外的 @override Widget build(BuildContext context)方法中初始化


推荐阅读