import '../../core/theme/app_colors.dart'; import 'package:flutter/material.dart'; import '../../core/theme/app_colors_extension.dart'; import '../../core/i18n/app_localizations.dart'; /// 表单字段行,左侧标签 + 右侧值 + 可选箭头。 /// /// [required] 为 true 时标签前显示红色星号。 class FormFieldRow extends StatelessWidget { final String label; final String? value; final String? hint; final bool showArrow; final bool readOnly; final bool required; final VoidCallback? onTap; final VoidCallback? onClear; final bool bold; const FormFieldRow({ super.key, required this.label, this.value, this.hint, this.showArrow = true, this.readOnly = false, this.required = false, this.onTap, this.onClear, this.bold = false, }); @override Widget build(BuildContext context) { final colors = Theme.of(context).extension()!; final hasValue = value != null && value!.isNotEmpty; return GestureDetector( onTap: onTap, behavior: HitTestBehavior.opaque, child: Container( padding: EdgeInsets.zero, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text.rich( TextSpan(children: [ TextSpan(text: label, style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.textSecondary)), if (required) TextSpan(text: ' *', style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.danger)), ]), ), const SizedBox(width: 12), Expanded( child: Row( mainAxisSize: MainAxisSize.min, children: [ Expanded( child: Text( hasValue ? value! : (hint ?? AppLocalizations.of(context).get('pleaseSelectOrFill')), maxLines: 1, softWrap: false, overflow: TextOverflow.ellipsis, textAlign: TextAlign.end, style: TextStyle(fontSize: AppFontSizes.subtitle, fontWeight: bold ? FontWeight.w600 : FontWeight.normal, color: hasValue ? colors.textPrimary : colors.textPlaceholder), ), ), if (hasValue && onClear != null) GestureDetector( onTap: onClear, child: const Padding( padding: EdgeInsets.only(left: 4), child: Icon(Icons.close, size: 16, color: Color(0xFFBBBBBB)), ), ) else if (showArrow && !readOnly) ...[ const SizedBox(width: 4), Icon(Icons.chevron_right, size: 14, color: colors.textPlaceholder), ], ], ), ), ], ), ), ); } }