FormBuilderRangeSlider constructor

FormBuilderRangeSlider({
  1. Key? key,
  2. required String name,
  3. FormFieldValidator<RangeValues>? validator,
  4. RangeValues? initialValue,
  5. InputDecoration decoration = const InputDecoration(),
  6. ValueChanged<RangeValues?>? onChanged,
  7. ValueTransformer<RangeValues?>? valueTransformer,
  8. bool enabled = true,
  9. FormFieldSetter<RangeValues>? onSaved,
  10. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  11. VoidCallback? onReset,
  12. FocusNode? focusNode,
  13. FormFieldErrorBuilder? errorBuilder,
  14. required double min,
  15. required double max,
  16. int? divisions,
  17. Color? activeColor,
  18. Color? inactiveColor,
  19. ValueChanged<RangeValues>? onChangeStart,
  20. ValueChanged<RangeValues>? onChangeEnd,
  21. RangeLabels? labels,
  22. SemanticFormatterCallback? semanticFormatterCallback,
  23. DisplayValues displayValues = DisplayValues.all,
  24. Widget minValueWidget(
    1. String min
    )?,
  25. Widget valueWidget(
    1. String value
    )?,
  26. Widget maxValueWidget(
    1. String max
    )?,
  27. 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,
  super.errorBuilder,
  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),
             );
           }
         }
         // TODO: Solve focus issue when Flutter team solve this issue
         // https://github.com/flutter/flutter/issues/53958
         return Focus(
           focusNode: state.effectiveFocusNode,
           skipTraversal: true,
           canRequestFocus: state.enabled,
           debugLabel: 'FormBuilderRangeSlider-$name',
           child: InputDecorator(
             decoration: state.decoration,
             isFocused: state.effectiveFocusNode.hasFocus,
             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)),
                     ],
                   ),
                 ],
               ),
             ),
           ),
         );
       },
     );