Repository: flutter/flutter
File: packages/flutter/lib/src/material/input_decorator.dart (Dart)

Code before:
        icon: icon,
        input: input,
        label: label,
        hint: hint,
        prefix: prefix,
        suffix: suffix,
        prefixIcon: prefixIcon,
        suffixIcon: suffixIcon,
        helperError: helperError,
        counter: counter,
        container: container,
      ),
      textDirection: textDirection,
      textBaseline: textBaseline,
      textAlignVertical: widget.textAlignVertical,
      isFocused: isFocused,
      expands: widget.expands,
    );

    // Pass error or hint text to semantics so screen readers announce it
    // along with the input field (via aria-description on web).
    // Error takes priority over hint since it requires user action.
    // Note: When an error widget is displayed (even without errorText),
    // we don't announce hintText since the visual state shows an error.
    final bool hasErrorWidget = decoration.error != null || decoration.errorText != null;
    final String? semanticsHint = hasErrorWidget ? decoration.errorText : decoration.hintText;

    final Widget result = Semantics(hint: semanticsHint, child: decorator);

    final BoxConstraints? constraints = decoration.constraints;
    if (constraints != null) {
      return ConstrainedBox(constraints: constraints, child: result);
    }
    return result;
  }
}

/// The border, labels, icons, and styles used to decorate a Material
/// Design text field.
///
/// The [TextField] and [InputDecorator] classes use [InputDecoration] objects
/// to describe their decoration. (In fact, this class is merely the
/// configuration of an [InputDecorator], which does all the heavy lifting.)
///
/// {@tool dartpad}
/// This sample shows how to style a `TextField` using an `InputDecorator`. The
/// TextField displays a "send message" icon to the left of the input area,
/// which is surrounded by a border an all sides. It displays the `hintText`
/// inside the input area to help the user understand what input is required. It
/// displays the `helperText` and `counterText` below the input area.
///

Review comment (suggestion):
If there's an error in `decoration.error` but `decoration.errorText` is null, then `semanticsHint` becomes null. Is that a desired result?

I think this may be the "complex case" mentioned in the PR description, is it? If so, let's leave a TODO here explaining what needs to happen.

Code after:
        icon: icon,
        input: input,
        label: label,
        hint: hint,
        prefix: prefix,
        suffix: suffix,
        prefixIcon: prefixIcon,
        suffixIcon: suffixIcon,
        helperError: helperError,
        counter: counter,
        container: container,
      ),
      textDirection: textDirection,
      textBaseline: textBaseline,
      textAlignVertical: widget.textAlignVertical,
      isFocused: isFocused,
      expands: widget.expands,
    );

    // Pass error text to semantics so screen readers announce it along with
    // the input field (via aria-description on web). The hintText is already
    // in the semantics tree via the hint Text widget that merges up through
    // _RenderDecoration's childSemanticsConfigurationDelegate, so we only
    // need to add errorText here. Adding hintText would cause duplication.
    // TODO(flutter-zl): A follow-up using aria-describedby with element IDs
    // will address complex cases (custom error widgets, errors outside
    // InputDecoration, custom announcement ordering). See
    // https://github.com/flutter/flutter/issues/180496#issuecomment-3713178684.
    final String? semanticsHint = decoration.errorText;

    final Widget result = Semantics(hint: semanticsHint, child: decorator);

    final BoxConstraints? constraints = decoration.constraints;
    if (constraints != null) {
      return ConstrainedBox(constraints: constraints, child: result);
    }
    return result;
  }
}

/// The border, labels, icons, and styles used to decorate a Material
/// Design text field.
///
/// The [TextField] and [InputDecorator] classes use [InputDecoration] objects
/// to describe their decoration. (In fact, this class is merely the
/// configuration of an [InputDecorator], which does all the heavy lifting.)
///
/// {@tool dartpad}
/// This sample shows how to style a `TextField` using an `InputDecorator`. The
/// TextField displays a "send message" icon to the left of the input area,
/// which is surrounded by a border an all sides. It displays the `hintText`