semanticFormatterCallback property

SemanticFormatterCallback? semanticFormatterCallback
final

The callback used to create a semantic value from the slider's values.

Defaults to formatting values as a percentage.

This is used by accessibility frameworks like TalkBack on Android to inform users what the currently selected value is with more context.

In the example below, a slider for currency values is configured to announce a value with a currency label.

RangeSlider(
  values: _dollarsRange,
  min: 20.0,
  max: 330.0,
  onChanged: (RangeValues newValues) {
    setState(() {
      _dollarsRange = newValues;
    });
  },
  semanticFormatterCallback: (double newValue) {
    return '${newValue.round()} dollars';
  }
 )

Implementation

// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
///
/// In the example below, a slider for currency values is configured to
/// announce a value with a currency label.
///
/// ```dart
/// RangeSlider(
///   values: _dollarsRange,
///   min: 20.0,
///   max: 330.0,
///   onChanged: (RangeValues newValues) {
///     setState(() {
///       _dollarsRange = newValues;
///     });
///   },
///   semanticFormatterCallback: (double newValue) {
///     return '${newValue.round()} dollars';
///   }
///  )
/// ```
///
/// </callout-box>
final SemanticFormatterCallback? semanticFormatterCallback;