Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider custom thumb #2282

Open
VijayakumarMariappan opened this issue Feb 13, 2025 · 0 comments
Open

Slider custom thumb #2282

VijayakumarMariappan opened this issue Feb 13, 2025 · 0 comments
Labels
open Open sliders Sliders component

Comments

@VijayakumarMariappan
Copy link
Collaborator

Hi alpitebiztrait,

Currently, there is no direct support to show the tooltip at bottom of the range slider. So, we meet your requirement using startThumbIcon and endThumbIcon properties and prepared a sample for your reference.

late SfRangeValues _values;
late NumberFormat _numberFormat;
late TextEditingController _rangeStartController;
late TextEditingController _rangeEndController;

Widget _buildThumbIcon(TextEditingController controller) {
  return Transform.translate(
    // Here 20 is thumb diameter and 5 is spacing between thumb and text.
    offset: const Offset(0, 25),
    child: OverflowBox(
      maxWidth: 150,
      child: TextField(
        textAlign: TextAlign.center,
        decoration:
            const InputDecoration(border: InputBorder.none, isDense: true),
        controller: controller,
      ),
    ),
  );
}

String _getFormattedText(dynamic value) {
  return _numberFormat.format(value);
}

@override
void initState() {
  _values = const SfRangeValues(3.0, 7.0);
  _numberFormat = NumberFormat('#.## €');
  _rangeStartController = TextEditingController();
  _rangeEndController = TextEditingController();
  super.initState();
}

@override
void dispose() {
  _rangeStartController.dispose();
  _rangeEndController.dispose();
  super.dispose();
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: SfRangeSlider(
      min: 0.0,
      max: 10.0,
      startThumbIcon: _buildThumbIcon(_rangeStartController),
      endThumbIcon: _buildThumbIcon(_rangeEndController),
      values: _values,
      onChangeStart: (SfRangeValues newValues) {
        _rangeStartController.text = _getFormattedText(newValues.start);
        _rangeEndController.text = _getFormattedText(newValues.end);
      },
      onChanged: (SfRangeValues newValues) {
        setState(() {
          _rangeStartController.text = _getFormattedText(newValues.start);
          _rangeEndController.text = _getFormattedText(newValues.end);
          _values = newValues;
        });
      },
      onChangeEnd: (SfRangeValues newValues) {
        _rangeStartController.text = "";
        _rangeEndController.text = "";
      },
    ),
  );
}

We hope that this solution will fulfill your requirement. Kindly let us know if you need further assistance with this.

Regards, Praveen G.

Hey thanks for this but how can I also implement the custom thumb widget now?

Originally posted by @vinayOB in #518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open Open sliders Sliders component
Projects
None yet
Development

No branches or pull requests

1 participant