165 lines
5.0 KiB
Dart
165 lines
5.0 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../core/data/models/comment.dart';
|
|
import '../../../core/data/models/drama.dart';
|
|
import '../../../core/data/repositories/comment_repository.dart';
|
|
import '../../../core/data/repositories/interaction_repository.dart';
|
|
import '../../../core/data/services/comment_controller.dart';
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
|
|
/// First loaded top-level comment shown under the card player.
|
|
class PlayerFeaturedComment extends StatefulWidget {
|
|
const PlayerFeaturedComment({
|
|
super.key,
|
|
required this.drama,
|
|
required this.onViewAll,
|
|
});
|
|
|
|
final Drama drama;
|
|
final VoidCallback onViewAll;
|
|
|
|
@override
|
|
State<PlayerFeaturedComment> createState() => _PlayerFeaturedCommentState();
|
|
}
|
|
|
|
class _PlayerFeaturedCommentState extends State<PlayerFeaturedComment> {
|
|
late final CommentController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = CommentController(
|
|
comments: context.read<CommentRepository>(),
|
|
interactions: context.read<InteractionRepository>(),
|
|
dramaId: widget.drama.id,
|
|
);
|
|
unawaited(_controller.load());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: _controller,
|
|
builder: (context, _) {
|
|
if (_controller.comments.isEmpty) return const SizedBox.shrink();
|
|
return _card(context, _controller.comments.first);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _card(BuildContext context, DramaComment comment) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
return Container(
|
|
key: const Key('player-featured-comment'),
|
|
padding: const EdgeInsets.fromLTRB(13, 12, 13, 10),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF14161E),
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: AppColors.border),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 30,
|
|
height: 30,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppColors.secondary.withValues(alpha: 0.18),
|
|
border: Border.all(
|
|
color: AppColors.secondary.withValues(alpha: 0.4),
|
|
),
|
|
),
|
|
child: Text(
|
|
_initial(comment.nickname),
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
comment.nickname.isEmpty
|
|
? l10n.localViewer
|
|
: comment.nickname,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: 11.5,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
),
|
|
if (comment.likeCount > 0) ...[
|
|
const Icon(
|
|
Icons.favorite_rounded,
|
|
size: 13,
|
|
color: AppColors.blue,
|
|
),
|
|
const SizedBox(width: 3),
|
|
Text(
|
|
'${comment.likeCount}',
|
|
style: const TextStyle(color: AppColors.muted, fontSize: 10),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
comment.content,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.cream,
|
|
fontSize: 11.5,
|
|
height: 1.4,
|
|
),
|
|
),
|
|
const SizedBox(height: 7),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: TextButton(
|
|
key: const Key('player-comments-view-all'),
|
|
onPressed: widget.onViewAll,
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: AppColors.secondary,
|
|
minimumSize: const Size(44, 32),
|
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
textStyle: const TextStyle(
|
|
fontSize: 10.5,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
child: Text(l10n.viewAll),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
String _initial(String nickname) {
|
|
final trimmed = nickname.trim();
|
|
return trimmed.isEmpty ? '?' : trimmed.substring(0, 1).toUpperCase();
|
|
}
|
|
}
|