buildLabel method

Widget buildLabel(
  1. TInputContext ctx,
  2. String? label,
  3. String? tag,
  4. bool isRequired,
)

Implementation

Widget buildLabel(TInputContext ctx, String? label, String? tag, bool isRequired) {
  if (labelBuilder != null) {
    return labelBuilder!(ctx, label, tag, isRequired);
  }

  if (label == null && tag == null) return const SizedBox.shrink();

  final resolvedLabelStyle = _resolve(labelStyle, ctx.states);
  final resolvedTagStyle = _resolve(tagStyle, ctx.states);

  return Padding(
    padding: const EdgeInsets.only(bottom: 8.0),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        if (label != null)
          Flexible(
            child: RichText(
              text: TextSpan(
                text: label,
                style: resolvedLabelStyle ??
                    TextStyle(
                        fontSize: 12.0,
                        fontWeight: FontWeight.w500,
                        color: !ctx.isDisabled ? ctx.colors.onSurfaceVariant : ctx.colors.onSurfaceVariant.withAlpha(100)),
                children: isRequired ? [TextSpan(text: ' *', style: TextStyle(color: ctx.colors.error))] : null,
              ),
            ),
          ),
        if (tag != null)
          Container(
            padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
            decoration: BoxDecoration(borderRadius: BorderRadius.circular(5.0), color: ctx.colors.surfaceContainer),
            child: Text(tag,
                style: resolvedTagStyle ?? TextStyle(fontSize: 11.0, fontWeight: FontWeight.w300, color: ctx.colors.onSurfaceVariant)),
          ),
      ],
    ),
  );
}