How to create a age range slider in flutter?

后端 未结 5 2042
清酒与你
清酒与你 2021-01-20 02:29

Would anyone know how to create an age range slider in flutter? A slider which will have two input values. Somewhat like what Tinder has to choose min and max age. a slider

5条回答
  •  执笔经年
    2021-01-20 03:22

    Flutter Version 1.20.0

    We having an update for RangeSlider with the label.

      class RangeWidget extends StatefulWidget {
        @override
        State createState() => _RangeWidget();
      }
      
      class _RangeWidget extends State {
        RangeValues _currentRangeValues = const RangeValues(0, 100);
      
        static String _valueToString(double value) {
          return value.toStringAsFixed(0);
        }
      
        @override
        Widget build(BuildContext context) {
          return new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              RangeSlider(
                values: _currentRangeValues,
                min: 0,
                max: 100,
                divisions: 10,
                labels: RangeLabels(
                  _currentRangeValues.start.round().toString(),
                  _currentRangeValues.end.round().toString(),
                ),
                onChanged: (RangeValues values) {
                  setState(() {
                    _currentRangeValues = values;
                  });
                },
              )
            ],
          );
        }
      }
    

提交回复
热议问题