FormBuilderSlider constructor
FormBuilderSlider({
- Key? key,
- required String name,
- FormFieldValidator<
double> ? validator, - required double initialValue,
- InputDecoration decoration = const InputDecoration(),
- ValueChanged<
double?> ? onChanged, - ValueTransformer<
double?> ? valueTransformer, - bool enabled = true,
- FormFieldSetter<
double> ? onSaved, - AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- VoidCallback? onReset,
- FocusNode? focusNode,
- required double min,
- required double max,
- int? divisions,
- Color? activeColor,
- Color? inactiveColor,
- ValueChanged<
double> ? onChangeStart, - ValueChanged<
double> ? onChangeEnd, - String? label,
- SemanticFormatterCallback? semanticFormatterCallback,
- NumberFormat? numberFormat,
- DisplayValues displayValues = DisplayValues.all,
- TextStyle? minTextStyle,
- TextStyle? textStyle,
- TextStyle? maxTextStyle,
- bool autofocus = false,
- MouseCursor? mouseCursor,
- 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,
),
],
),
],
),
),
);
},
);