颤动范围滑块不动

时间:2021-02-11 13:35:47

标签: flutter dart

我在底部工作表中显示简单的 RangeSlider 问题是它没有移动。

我的代码

<DatePicker
            showTimeOnly
            dateFormat="yyyy-MM-dd"
            selected={*some value*}
            initialDate={dayjs("2012-12-02", "yyyy-MM-dd")}
            name="startTime"
            onChange={(time) => this.callSomeMethod(time, i, 'startTime')}/>

我正在设置 onTap:(){ showModalBottomSheet( context: context, builder: (context){ return Column( children: [ RangeSlider( values: _currentRangeValues, min: 0, max: 10000, divisions: 10, labels: RangeLabels( _currentRangeValues.start.round().toString(), _currentRangeValues.end.round().toString(), ), onChanged: (RangeValues values) { }, ), ], ); } ); }, 状态。

它不动,总是打印 0。

1 个答案:

答案 0 :(得分:0)

将 onChanged 值设置为 _currentRangeValues 以解决您的问题。

MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  RangeValues _currentRangeValues = const RangeValues(0, 1000);

  @override
  Widget build(BuildContext context) {
    return RangeSlider(
      values: _currentRangeValues,
      min: 0,
      max: 1000,
      divisions: 10,
      labels: RangeLabels(
        _currentRangeValues.start.round().toString(),
        _currentRangeValues.end.round().toString(),
      ),
      onChanged: (RangeValues values) {
        setState(() {
          _currentRangeValues = values;
        });
      },
    );
  }
}