FormBuilderSlider constructor

FormBuilderSlider({
  1. Key? key,
  2. required String name,
  3. FormFieldValidator<double>? validator,
  4. required double initialValue,
  5. InputDecoration decoration = const InputDecoration(),
  6. ValueChanged<double?>? onChanged,
  7. ValueTransformer<double?>? valueTransformer,
  8. bool enabled = true,
  9. FormFieldSetter<double>? onSaved,
  10. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  11. VoidCallback? onReset,
  12. FocusNode? focusNode,
  13. required double min,
  14. required double max,
  15. int? divisions,
  16. Color? activeColor,
  17. Color? inactiveColor,
  18. ValueChanged<double>? onChangeStart,
  19. ValueChanged<double>? onChangeEnd,
  20. String? label,
  21. SemanticFormatterCallback? semanticFormatterCallback,
  22. NumberFormat? numberFormat,
  23. DisplayValues displayValues = DisplayValues.all,
  24. TextStyle? minTextStyle,
  25. TextStyle? textStyle,
  26. TextStyle? maxTextStyle,
  27. bool autofocus = false,
  28. MouseCursor? mouseCursor,
  29. bool shouldRequestFocus = false,
})

Creates field for selection of a numerical value on a slider

Implementation

FormBuilderSlider({
  super.key,
  required super.name,
  super.validator,
  required double 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.label,
  this.semanticFormatterCallback,
  this.numberFormat,
  this.displayValues = DisplayValues.all,
  this.minTextStyle,
  this.textStyle,
  this.maxTextStyle,
  this.autofocus = false,
  this.mouseCursor,
  this.shouldRequestFocus = false,
}) : super(
        builder: (FormFieldState<double?> field) {
          final state = field as _FormBuilderSliderState;
          final effectiveNumberFormat =
              numberFormat ?? NumberFormat.compact();

          return InputDecorator(
            decoration: state.decoration,
            child: Container(
              padding: const EdgeInsets.only(top: 10.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Slider(
                    value: field.value!,
                    min: min,
                    max: max,
                    divisions: divisions,
                    activeColor: activeColor,
                    inactiveColor: inactiveColor,
                    onChangeEnd: onChangeEnd,
                    onChangeStart: onChangeStart,
                    label: label,
                    semanticFormatterCallback: semanticFormatterCallback,
                    onChanged: state.enabled
                        ? (value) {
                            if (shouldRequestFocus) {
                              state.requestFocus();
                            }
                            field.didChange(value);
                          }
                        : null,
                    autofocus: autofocus,
                    mouseCursor: mouseCursor,
                    focusNode: state.effectiveFocusNode,
                  ),
                  Row(
                    children: <Widget>[
                      if (displayValues != DisplayValues.none &&
                          displayValues != DisplayValues.current)
                        Text(
                          effectiveNumberFormat.format(min),
                          style: minTextStyle ?? textStyle,
                        ),
                      const Spacer(),
                      if (displayValues != DisplayValues.none &&
                          displayValues != DisplayValues.minMax)
                        Text(
                          effectiveNumberFormat.format(field.value),
                          style: textStyle,
                        ),
                      const Spacer(),
                      if (displayValues != DisplayValues.none &&
                          displayValues != DisplayValues.current)
                        Text(
                          effectiveNumberFormat.format(max),
                          style: maxTextStyle ?? textStyle,
                        ),
                    ],
                  ),
                ],
              ),
            ),
          );
        },
      );