form_field_row.dart 2.1 KB

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