iDecoration property

InputDecoration get iDecoration

iDecoration

The InputDecoration for a FormifyTextField widget.

This property defines the visual appearance of the input field, including labels, icons, and hints. It takes into account several factors, such as whether the field is required and whether a custom inputDecoration is provided.

If a custom inputDecoration is provided, it returns a copy of that inputDecoration with any missing properties filled in by the corresponding properties of the widget (e.g., label, prefixIcon, suffixIcon, and hintText). This allows you to customize the appearance while still inheriting some default properties from the widget.

If the field is marked as required (required is set to true), it returns an InputDecoration that includes a red asterisk (*) next to the label to indicate the required status.

If neither a custom inputDecoration nor a required field is specified, it returns a basic InputDecoration with the label, prefix icon, suffix icon, and hint text.

Implementation

InputDecoration get iDecoration {
  if (inputDecoration != null) {
    return inputDecoration!.copyWith(
        labelText: inputDecoration?.labelText ?? label,
        prefixIcon: inputDecoration?.prefixIcon ?? prefixIcon,
        suffixIcon: inputDecoration?.suffixIcon ?? suffixIcon,
        hintText: inputDecoration?.hintText ?? hintText);
  }
  if (required) {
    return InputDecoration(
      label: Text.rich(
        TextSpan(
          text: label,
          children: const [
            TextSpan(text: ' *', style: TextStyle(color: Colors.red)),
          ],
        ),
      ),
      prefixIcon: prefixIcon,
      suffixIcon: suffixIcon,
      hintText: hintText,
    );
  }
  return InputDecoration(
    labelText: label,
    prefixIcon: prefixIcon,
    suffixIcon: suffixIcon,
    hintText: hintText,
  );
}