buildSlider method

  1. @protected
Widget buildSlider(
  1. BuildParameters params
)

Implementation

@protected
Widget buildSlider(BuildParameters params) {
  final alias = params.props["alias"] ?? params.id;
  final enabled = parseBool(params.props["enabled"], defaultValue: true);

  final onChanged = events.getValueFunction<double?>(params.context,
      params.actions["onChanged"], params.state, params.parentContext);
  final onSaved = params.props["onSaved"] ??
      (v) {
        if (alias != null) {
          params.state[alias] = v;
        }
      };

  return FormField<double>(
    key:
        UniqueKey(), // otherwise on a ListView, FormField's state would override the real value when reusing widgets
    initialValue: parseDouble(params.props["value"]),
    enabled: enabled,
    autovalidateMode: AutovalidateMode.disabled,
    onSaved: onSaved,
    builder: (state) {
      return Slider(
        key: properties.getKey(params.id),
        value: parseDouble(state.value, defaultValue: 0),
        min: parseDouble(params.props["min"]),
        max: parseDouble(params.props["max"], defaultValue: 1),
        divisions: tryParseInt(params.props["divisions"]),
        thumbColor: tryParseColor(params.props["thumbColor"]),
        activeColor: tryParseColor(params.props["activeColor"]),
        inactiveColor: tryParseColor(params.props["inactiveColor"]),
        secondaryActiveColor:
            tryParseColor(params.props["secondaryActiveColor"]),
        secondaryTrackValue:
            tryParseDouble(params.props["secondaryTrackValue"]),
        label: params.props["label"],
        onChanged: enabled
            ? (val) {
                state.didChange(val);
                if (onChanged != null) {
                  onChanged(val);
                }
              }
            : null,
      );
    },
  );
}