FormBuilderRangeSlider constructor
FormBuilderRangeSlider({
- Key? key,
- required String name,
- FormFieldValidator<
RangeValues> ? validator, - RangeValues? initialValue,
- InputDecoration decoration = const InputDecoration(),
- ValueChanged<
RangeValues?> ? onChanged, - ValueTransformer<
RangeValues?> ? valueTransformer, - bool enabled = true,
- FormFieldSetter<
RangeValues> ? onSaved, - AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- VoidCallback? onReset,
- FocusNode? focusNode,
- required double min,
- required double max,
- int? divisions,
- Color? activeColor,
- Color? inactiveColor,
- ValueChanged<
RangeValues> ? onChangeStart, - ValueChanged<
RangeValues> ? onChangeEnd, - RangeLabels? labels,
- SemanticFormatterCallback? semanticFormatterCallback,
- DisplayValues displayValues = DisplayValues.all,
- Widget minValueWidget(
- String min
- Widget valueWidget(
- String value
- Widget maxValueWidget(
- String max
- NumberFormat? numberFormat,
Creates field to select a range of values on a Slider
Implementation
FormBuilderRangeSlider({
super.key,
required super.name,
super.validator,
super.initialValue,
super.decoration,
super.onChanged,
super.valueTransformer,
super.enabled,
super.onSaved,
super.autovalidateMode = AutovalidateMode.disabled,
super.onReset,
super.focusNode,
required this.min,
required this.max,
this.divisions,
this.activeColor,
this.inactiveColor,
this.onChangeStart,
this.onChangeEnd,
this.labels,
this.semanticFormatterCallback,
this.displayValues = DisplayValues.all,
this.minValueWidget,
this.valueWidget,
this.maxValueWidget,
this.numberFormat,
}) : super(builder: (FormFieldState<RangeValues?> field) {
final state = field as _FormBuilderRangeSliderState;
final effectiveNumberFormat = numberFormat ?? NumberFormat.compact();
if (field.value == null ||
field.value!.start < min ||
field.value!.start > max ||
field.value!.end < min ||
field.value!.end > max) {
if (initialValue == null) {
field.setValue(RangeValues(min, min));
} else {
field.setValue(
RangeValues(initialValue.start, initialValue.end),
);
}
}
return InputDecorator(
decoration: state.decoration,
child: Container(
padding: const EdgeInsets.only(top: 10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RangeSlider(
values: field.value!,
min: min,
max: max,
divisions: divisions,
activeColor: activeColor,
inactiveColor: inactiveColor,
onChangeEnd: onChangeEnd,
onChangeStart: onChangeStart,
labels: labels,
semanticFormatterCallback: semanticFormatterCallback,
onChanged: state.enabled
? (values) {
field.didChange(values);
}
: null,
),
Row(
children: <Widget>[
if (displayValues != DisplayValues.none &&
displayValues != DisplayValues.current)
minValueWidget
?.call(effectiveNumberFormat.format(min)) ??
Text(effectiveNumberFormat.format(min)),
const Spacer(),
if (displayValues != DisplayValues.none &&
displayValues != DisplayValues.minMax)
valueWidget?.call(
'${effectiveNumberFormat.format(field.value!.start)} - ${effectiveNumberFormat.format(field.value!.end)}') ??
Text(
'${effectiveNumberFormat.format(field.value!.start)} - ${effectiveNumberFormat.format(field.value!.end)}'),
const Spacer(),
if (displayValues != DisplayValues.none &&
displayValues != DisplayValues.current)
maxValueWidget
?.call(effectiveNumberFormat.format(max)) ??
Text(effectiveNumberFormat.format(max)),
],
),
],
),
),
);
});