Main coves client
1import 'package:flutter/material.dart';
2
3import '../constants/app_colors.dart';
4
5/// Comments section header with sort dropdown
6///
7/// Displays:
8/// - Comment count with pluralization
9/// - Sort dropdown (Hot/Top/New)
10/// - Empty state when no comments
11class CommentsHeader extends StatelessWidget {
12 const CommentsHeader({
13 required this.commentCount,
14 required this.currentSort,
15 required this.onSortChanged,
16 super.key,
17 });
18
19 final int commentCount;
20 final String currentSort;
21 final void Function(String) onSortChanged;
22
23 static const _sortOptions = ['hot', 'top', 'new'];
24 static const _sortLabels = ['Hot', 'Top', 'New'];
25
26 @override
27 Widget build(BuildContext context) {
28 // Show empty state if no comments
29 if (commentCount == 0) {
30 return Container(
31 padding: const EdgeInsets.symmetric(vertical: 32),
32 child: Column(
33 children: [
34 const Icon(
35 Icons.chat_bubble_outline,
36 size: 48,
37 color: AppColors.textSecondary,
38 ),
39 const SizedBox(height: 16),
40 Text(
41 'No comments yet',
42 style: TextStyle(
43 fontSize: 16,
44 color: AppColors.textPrimary.withValues(alpha: 0.7),
45 ),
46 ),
47 const SizedBox(height: 4),
48 Text(
49 'Be the first to comment',
50 style: TextStyle(
51 fontSize: 14,
52 color: AppColors.textSecondary.withValues(alpha: 0.7),
53 ),
54 ),
55 ],
56 ),
57 );
58 }
59
60 // Show comment count and sort dropdown
61 return Container(
62 padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
63 child: Row(
64 children: [
65 // Comment count with dropdown
66 Expanded(
67 child: PopupMenuButton<String>(
68 initialValue: currentSort,
69 onSelected: onSortChanged,
70 offset: const Offset(0, 40),
71 color: AppColors.backgroundSecondary,
72 child: Row(
73 children: [
74 Text(
75 '$commentCount ${commentCount == 1 ? 'Comment' : 'Comments'}',
76 style: const TextStyle(
77 fontSize: 15,
78 color: AppColors.textSecondary,
79 fontWeight: FontWeight.w600,
80 ),
81 ),
82 const SizedBox(width: 6),
83 const Icon(
84 Icons.arrow_drop_down,
85 color: AppColors.textSecondary,
86 size: 20,
87 ),
88 ],
89 ),
90 itemBuilder: (context) => [
91 for (var i = 0; i < _sortOptions.length; i++)
92 PopupMenuItem<String>(
93 value: _sortOptions[i],
94 child: Text(
95 _sortLabels[i],
96 style: TextStyle(
97 color: currentSort == _sortOptions[i]
98 ? AppColors.primary
99 : AppColors.textPrimary,
100 fontWeight: currentSort == _sortOptions[i]
101 ? FontWeight.w600
102 : FontWeight.normal,
103 ),
104 ),
105 ),
106 ],
107 ),
108 ),
109 ],
110 ),
111 );
112 }
113}