import 'package:flutter/material.dart'; import 'package:patbond_flutter/core/theme/app_theme.dart'; import 'package:patbond_flutter/core/widgets/pet_avatar.dart'; import 'package:patbond_flutter/features/community/community_display.dart'; import 'package:patbond_flutter/features/community/community_models.dart'; /// 评论条目(05 号规范 §3.4,demo 气泡形态升共享): /// `PetAvatar sm32` + 10 + 气泡(`surface` 底、`border` 1px、圆角 16、 /// padding 12)——作者名 13/w700 → 4 → 内容 bodyMedium → 6 → 底行 /// (时间 11 `inkSoft` + 仅本人评论的「删除」入口)。 /// /// - @ 回复(单层平铺,契约 replyToUser)以「回复 @昵称:」前缀呈现; /// 降级作者统一「宠友」占位(isDegraded 一个判定口)。 /// - [onDelete] 非 null 才渲染删除入口——**权限判定在调用方**(17 号 /// 后端语义:仅评论作者可删,他人可见评论 403/40301);[deleting] /// 期间入口替换为 14 转圈防重复提交。 /// - 评论点赞(§3.4 底行右端)无契约端点,M3 不渲染。 class CommentTile extends StatelessWidget { const CommentTile({ required this.comment, super.key, this.onDelete, this.deleting = false, this.now, }); final PostComment comment; /// 删除回调;null = 非本人评论,不渲染删除入口。 final VoidCallback? onDelete; /// 删除请求在途(入口转圈锁定)。 final bool deleting; /// 相对时间的参考时钟(测试注入;缺省取当前时间)。 final DateTime? now; @override Widget build(BuildContext context) { final replyTo = comment.replyToUser; return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ PetAvatar(size: PetAvatarSize.sm, url: comment.author.avatarUrl), const SizedBox(width: 10), Expanded( child: Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: AppColors.surface, border: Border.all(color: AppColors.border), borderRadius: BorderRadius.circular(16), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( authorDisplayName(comment.author), style: const TextStyle( color: AppColors.ink, fontSize: 13, fontWeight: FontWeight.w700, ), ), const SizedBox(height: 4), Text.rich( TextSpan( children: [ if (replyTo != null) TextSpan( text: '回复 @${authorDisplayName(replyTo)}:', style: const TextStyle( color: AppColors.inkSoft, fontWeight: FontWeight.w600, ), ), TextSpan(text: comment.content), ], ), style: Theme.of(context).textTheme.bodyMedium, ), const SizedBox(height: 6), Row( children: [ Text( feedRelativeTime(comment.createdAt, now: now), style: const TextStyle( color: AppColors.inkSoft, fontSize: 11, ), ), const Spacer(), if (onDelete != null) deleting ? const Padding( padding: EdgeInsets.all(4), child: SizedBox( width: 14, height: 14, child: CircularProgressIndicator( strokeWidth: 2, color: AppColors.inkSoft, ), ), ) : Semantics( label: '删除评论', button: true, child: InkWell( onTap: onDelete, borderRadius: BorderRadius.circular( AppRadius.pill, ), // 视觉 11 字,触控由 padding 撑到 ≥32 //(气泡内行高受限,不足 44 以热区扩展补偿)。 child: const Padding( padding: EdgeInsets.symmetric( horizontal: 10, vertical: 8, ), child: Text( '删除', style: TextStyle( color: AppColors.inkSoft, fontSize: 11, fontWeight: FontWeight.w600, ), ), ), ), ), ], ), ], ), ), ), ], ); } }