buildInputDecoration method
InputDecoration
buildInputDecoration(
- BuildContext context,
- Set<
WidgetState> states, { - bool expands = false,
- Widget? beforePostWidget,
- Widget? beforePreWidget,
- String? label,
- String? placeholder,
- String? tag,
- String? helperText,
- List<
String> ? errors, - bool isRequired = false,
- VoidCallback? onClear,
- Widget? infoIcon,
- FloatingLabelAlignment? labelAlignment,
Implementation
InputDecoration buildInputDecoration(
BuildContext context,
Set<WidgetState> states, {
bool expands = false,
Widget? beforePostWidget,
Widget? beforePreWidget,
String? label,
String? placeholder,
String? tag,
String? helperText,
List<String>? errors,
bool isRequired = false,
VoidCallback? onClear,
Widget? infoIcon,
FloatingLabelAlignment? labelAlignment,
}) {
final inputBorder = buildInputBorder(states);
final isFilled = decorationType == TInputDecorationType.filled;
final fillColor = resolveBackgroundColor(context, states);
final hasLabel = (label != null && label.isNotEmpty) || (tag != null && tag.isNotEmpty);
final showFloatingLabel = labelPosition != TLabelPosition.aboveField && hasLabel;
final basePadding = padding ?? size.padding;
final effectivePadding = decorationType == TInputDecorationType.underline
? basePadding.copyWith(top: 0, bottom: basePadding.bottom)
: showFloatingLabel && labelPosition == TLabelPosition.inlineFloating
? basePadding.copyWith(top: basePadding.top / 1.2, bottom: basePadding.bottom / 1.2)
: basePadding;
return InputDecoration(
border: inputBorder,
enabledBorder: inputBorder,
focusedErrorBorder: inputBorder,
disabledBorder: inputBorder,
focusedBorder: inputBorder,
errorBorder: inputBorder,
contentPadding: effectivePadding,
constraints: BoxConstraints(
minHeight: fieldHeight,
maxHeight: expands ? double.infinity : fieldHeight,
),
label: showFloatingLabel ? labelBuilder.resolve(states)(label, tag, isRequired, null) : null,
labelStyle: showFloatingLabel ? labelStyle.resolve(states) : null,
floatingLabelStyle: showFloatingLabel ? floatingLabelStyle.resolve(states) : null,
floatingLabelAlignment: showFloatingLabel ? labelAlignment : null,
floatingLabelBehavior: showFloatingLabel
? switch (labelPosition) {
TLabelPosition.aboveField => FloatingLabelBehavior.never,
TLabelPosition.floating || TLabelPosition.inlineFloating => FloatingLabelBehavior.auto,
}
: FloatingLabelBehavior.never,
isDense: true,
visualDensity: VisualDensity.compact,
hintText: placeholder,
hintStyle: hintStyle.resolve(states),
prefixIconConstraints: BoxConstraints(minHeight: fieldHeight - effectivePadding.vertical, minWidth: effectivePadding.left),
prefixIcon: _buildPreWidget(beforePreWidget),
suffixIconConstraints: BoxConstraints(minHeight: fieldHeight - effectivePadding.vertical, minWidth: effectivePadding.right),
suffixIcon: _buildPostWidget(
beforePostWidget: beforePostWidget,
onClear: onClear,
infoIcon: labelPosition == TLabelPosition.floating || labelPosition == TLabelPosition.inlineFloating ? infoIcon : null,
),
filled: isFilled,
fillColor: fillColor,
focusColor: fillColor,
hoverColor: fillColor,
);
}