form_field_row.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:flutter/material.dart';
  2. import '../../core/theme/app_colors.dart';
  3. /// Pencil Component/FormField — 表单字段行
  4. ///
  5. /// 左侧标签(14号/secondary) + 右侧值(14号/可placeholder色) + 可选箭头图标
  6. class FormFieldRow extends StatelessWidget {
  7. final String label;
  8. final String? value;
  9. final String? hint;
  10. final bool showArrow;
  11. final bool readOnly;
  12. final VoidCallback? onTap;
  13. const FormFieldRow({
  14. super.key,
  15. required this.label,
  16. this.value,
  17. this.hint,
  18. this.showArrow = true,
  19. this.readOnly = false,
  20. this.onTap,
  21. });
  22. @override
  23. Widget build(BuildContext context) {
  24. final hasValue = value != null && value!.isNotEmpty;
  25. return GestureDetector(
  26. onTap: onTap,
  27. child: Container(
  28. height: 44,
  29. padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),
  30. child: Row(
  31. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  32. children: [
  33. Text(
  34. label,
  35. style: const TextStyle(
  36. fontSize: AppFontSizes.body,
  37. color: AppColors.textSecondary,
  38. ),
  39. ),
  40. Row(
  41. mainAxisSize: MainAxisSize.min,
  42. children: [
  43. Text(
  44. hasValue ? value! : (hint ?? '请选择或填写'),
  45. style: TextStyle(
  46. fontSize: AppFontSizes.body,
  47. color: hasValue
  48. ? (readOnly ? AppColors.textPrimary : AppColors.textPrimary)
  49. : AppColors.textPlaceholder,
  50. ),
  51. ),
  52. if (showArrow && !readOnly) ...[
  53. const SizedBox(width: 4),
  54. const Icon(
  55. Icons.chevron_right,
  56. size: 14,
  57. color: AppColors.textPlaceholder,
  58. ),
  59. ],
  60. ],
  61. ),
  62. ],
  63. ),
  64. ),
  65. );
  66. }
  67. }