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,
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,
}) {
final inputBorder = buildInputBorder(states);
final hasPrefix = beforePreWidget != null || preWidget != null;
final hasSuffix = onClear != null || beforePostWidget != null || infoIcon != null || postWidget != null;
Color resolvedBgColor = backgroundColor.resolve(states);
if (decorationType == TInputDecorationType.filled && !(states.contains(WidgetState.disabled) || states.contains(WidgetState.error))) {
if (resolvedBgColor == context.colors.surfaceContainerLowest) {
final parentColor = context.getBackgroundColor(context.colors.surfaceContainerLowest);
resolvedBgColor = parentColor.adaptiveContrast(context, 0.025);
}
}
return InputDecoration(
border: inputBorder,
enabledBorder: inputBorder,
focusedErrorBorder: inputBorder,
disabledBorder: inputBorder,
focusedBorder: inputBorder,
errorBorder: inputBorder,
contentPadding: fieldPadding,
label: labelPosition == TLabelPosition.aboveField ? null : labelBuilder.resolve(states)(label, tag, isRequired, null),
labelStyle: labelStyle.resolve(states),
floatingLabelStyle: labelStyle.resolve(states),
floatingLabelBehavior: switch (labelPosition) {
TLabelPosition.aboveField => FloatingLabelBehavior.never,
TLabelPosition.floating => FloatingLabelBehavior.auto,
},
isDense: true,
visualDensity: VisualDensity.compact,
hintText: placeholder,
hintStyle: hintStyle.resolve(states),
prefixIconConstraints: BoxConstraints(minHeight: fieldHeight, minWidth: hasPrefix ? 40 : 7.5),
prefixIcon: _buildPreWidget(beforePreWidget),
suffixIconConstraints: BoxConstraints(minHeight: fieldHeight, minWidth: hasSuffix ? 40 : 7.5),
suffixIcon: _buildPostWidget(
beforePostWidget: beforePostWidget, onClear: onClear, infoIcon: labelPosition == TLabelPosition.floating ? infoIcon : null),
filled: decorationType == TInputDecorationType.filled,
fillColor: resolvedBgColor,
);
}