| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import '../../core/theme/app_colors.dart';
- import 'package:flutter/material.dart';
- import '../../core/theme/app_colors_extension.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;
- const FormFieldRow({
- super.key,
- required this.label,
- this.value,
- this.hint,
- this.showArrow = true,
- this.readOnly = false,
- this.required = false,
- this.onTap,
- this.onClear,
- });
- @override
- Widget build(BuildContext context) {
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
- 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,
- ),
- ),
- ],
- ),
- ),
- Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- hasValue ? value! : (hint ?? '请选择或填写'),
- style: TextStyle(
- fontSize: AppFontSizes.subtitle,
- color: hasValue
- ? (readOnly ? colors.textPrimary : colors.textPrimary)
- : colors.textPlaceholder,
- ),
- ),
- if (hasValue && onClear != null)
- GestureDetector(
- onTap: onClear,
- child: const Padding(
- padding: EdgeInsets.only(left: 8),
- 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,
- ),
- ],
- ],
- ),
- ],
- ),
- ),
- );
- }
- }
|