ReactiveSliderColorPicker<T> constructor
ReactiveSliderColorPicker<T> ({
- Key? key,
- String? formControlName,
- FormControl<
T> ? formControl, - Map<
String, ValidationMessageFunction> ? validationMessages, - ControlValueAccessor<
T, double> ? valueAccessor, - ShowErrorsFunction<
T> ? showErrors, - Color? contrastIconColorLight,
- Color contrastIconColorDark = Colors.white,
- InputDecoration? decoration,
- PaletteType paletteType = PaletteType.hsv,
- bool enableAlpha = true,
- @Deprecated('Use empty list in [labelTypes] to disable label.') bool showLabel = true,
- @Deprecated('Use Theme.of(context).textTheme.bodyText1 & 2 to alter text style.') TextStyle? labelTextStyle,
- @Deprecated('Use Theme.of(context).textTheme.bodyText1 & 2 to alter text style.') TextStyle? sliderTextStyle,
- bool displayThumbColor = false,
- Size sliderSize = const Size(260, 40),
- Size indicatorSize = const Size(280, 50),
- bool showSliderText = true,
- bool showIndicator = true,
- Alignment indicatorAlignmentBegin = const Alignment(-1.0, -3.0),
- Alignment indicatorAlignmentEnd = const Alignment(1.0, 3.0),
- BorderRadius indicatorBorderRadius = const BorderRadius.all(Radius.zero),
- double disabledOpacity = 0.5,
- ColorModel colorModel = ColorModel.rgb,
- bool showParams = true,
- List<
ColorLabelType> labelTypes = const [],
Creates a ReactiveSliderColorPicker that wraps the function showDatePicker.
Can optionally provide a formControl
to bind this widget to a control.
Can optionally provide a formControlName
to bind this ReactiveFormField
to a FormControl
.
Must provide one of the arguments formControl
or a formControlName
,
but not both at the same time.
Implementation
ReactiveSliderColorPicker({
Key? key,
String? formControlName,
FormControl<T>? formControl,
Map<String, ValidationMessageFunction>? validationMessages,
ControlValueAccessor<T, double>? valueAccessor,
ShowErrorsFunction<T>? showErrors,
////////////////////////////////////////////////////////////////////////////
Color? contrastIconColorLight,
Color contrastIconColorDark = Colors.white,
InputDecoration? decoration,
PaletteType paletteType = PaletteType.hsv,
bool enableAlpha = true,
@Deprecated('Use empty list in [labelTypes] to disable label.')
bool showLabel = true,
@Deprecated(
'Use Theme.of(context).textTheme.bodyText1 & 2 to alter text style.')
TextStyle? labelTextStyle,
@Deprecated(
'Use Theme.of(context).textTheme.bodyText1 & 2 to alter text style.')
TextStyle? sliderTextStyle,
bool displayThumbColor = false,
Size sliderSize = const Size(260, 40),
Size indicatorSize = const Size(280, 50),
bool showSliderText = true,
bool showIndicator = true,
Alignment indicatorAlignmentBegin = const Alignment(-1.0, -3.0),
Alignment indicatorAlignmentEnd = const Alignment(1.0, 3.0),
BorderRadius indicatorBorderRadius = const BorderRadius.all(Radius.zero),
double disabledOpacity = 0.5,
ColorModel colorModel = ColorModel.rgb,
bool showParams = true,
List<ColorLabelType> labelTypes = const [],
}) : super(
key: key,
formControl: formControl,
formControlName: formControlName,
validationMessages: validationMessages,
builder: (field) {
void _showDialog(
BuildContext context, {
required Color pickerColor,
required ValueChanged<Color> onColorChanged,
// bool enableLabel = false,
}) {
showDialog<Color>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
titlePadding: const EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
content: SingleChildScrollView(
child: SlidePicker(
pickerColor: pickerColor,
onColorChanged: onColorChanged,
// paletteType: paletteType,
enableAlpha: enableAlpha,
displayThumbColor: displayThumbColor,
sliderSize: sliderSize,
showSliderText: showSliderText,
showIndicator: showIndicator,
indicatorSize: indicatorSize,
indicatorAlignmentBegin: indicatorAlignmentBegin,
indicatorAlignmentEnd: indicatorAlignmentEnd,
indicatorBorderRadius: indicatorBorderRadius,
colorModel: colorModel,
showParams: showParams,
labelTypes: labelTypes,
),
),
);
},
);
}
final isEmptyValue =
field.value == null || field.value.toString().isEmpty;
final InputDecoration effectiveDecoration = (decoration ??
const InputDecoration())
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
final iconColor = (field.value?.computeLuminance() ?? 0) > 0.5
? contrastIconColorDark
: contrastIconColorLight;
return IgnorePointer(
ignoring: !field.control.enabled,
child: Opacity(
opacity: field.control.enabled ? 1 : disabledOpacity,
child: Listener(
onPointerDown: (_) => field.control.markAsTouched(),
child: InputDecorator(
decoration: effectiveDecoration.copyWith(
errorText: field.errorText,
enabled: field.control.enabled,
fillColor: field.value,
filled: field.value != null,
suffixIcon: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
color: iconColor,
icon: const Icon(Icons.edit),
onPressed: () {
_showDialog(
field.context,
pickerColor: field.value ?? Colors.transparent,
onColorChanged: field.didChange,
);
},
splashRadius: 0.01,
),
if (field.value != null)
IconButton(
color: iconColor,
icon: const Icon(Icons.clear),
onPressed: () {
field.didChange(null);
},
splashRadius: 0.01,
),
],
),
),
isEmpty:
isEmptyValue && effectiveDecoration.hintText == null,
child: Container(
color: field.value,
),
),
),
),
);
},
);