Sync update: 2026-05-19 23:27:14

This commit is contained in:
Hamza-Ayed
2026-05-19 23:27:14 +03:00
parent 1eec712c58
commit 22f1bba6ac
11 changed files with 1090 additions and 593 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:intl/intl.dart';
import '../models/conversation_model.dart';
import '../theme/app_theme.dart';
@@ -17,117 +18,217 @@ class ConversationTile extends StatelessWidget {
Widget build(BuildContext context) {
final lastMsg = conversation.lastMessage;
final hasUnread = conversation.unreadCount > 0;
final isDark = AppTheme.isDark(context);
return ListTile(
return InkWell(
onTap: onTap,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
leading: _buildAvatar(),
title: Row(
children: [
Expanded(
child: Text(
conversation.name,
style: const TextStyle(
color: AppTheme.textPrimary,
fontSize: 16,
fontWeight: FontWeight.w600,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
Text(
_formatTime(conversation.timestamp),
style: TextStyle(
color: hasUnread ? AppTheme.primary : AppTheme.textSecondary,
fontSize: 12,
fontWeight: hasUnread ? FontWeight.bold : FontWeight.normal,
),
),
],
),
subtitle: Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: Row(
children: [
if (lastMsg != null && lastMsg.fromMe) ...[
const Icon(Icons.done_all, size: 16, color: AppTheme.primary), // Or proper ACK double tick
const SizedBox(width: 4),
],
// ── Avatar ──────────────────────────────────────────────────────
_buildAvatar(context, conversation),
const SizedBox(width: 12),
// ── Content ─────────────────────────────────────────────────────
Expanded(
child: Text(
_getSubtitleText(lastMsg),
style: const TextStyle(
color: AppTheme.textSecondary,
fontSize: 14,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Name row + time
Row(
children: [
Expanded(
child: Text(
conversation.name,
style: TextStyle(
color: AppTheme.textPrimary(context),
fontSize: 16.5,
fontWeight: FontWeight.w600,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 6),
Text(
_formatTime(conversation.timestamp),
style: TextStyle(
color: hasUnread
? AppTheme.primary
: AppTheme.textSecondary(context),
fontSize: 12,
fontWeight:
hasUnread ? FontWeight.w600 : FontWeight.normal,
),
),
],
),
const SizedBox(height: 4),
// Subtitle row: ack icon + preview + badges
Row(
children: [
// ── ACK icon for sent messages ───────────────────────
if (lastMsg != null && lastMsg.fromMe) ...[
_buildAckIcon(context, lastMsg.ack),
const SizedBox(width: 3),
],
// ── Message preview ──────────────────────────────────
Expanded(
child: Text(
_getSubtitleText(context, lastMsg),
style: TextStyle(
color: AppTheme.textSecondary(context),
fontSize: 14,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
// ── Trailing badges ──────────────────────────────────
if (conversation.isMuted) ...[
const SizedBox(width: 4),
Icon(Icons.volume_off,
size: 15, color: AppTheme.textSecondary(context)),
],
if (conversation.pinned) ...[
const SizedBox(width: 4),
Icon(Icons.push_pin,
size: 15, color: AppTheme.textSecondary(context)),
],
if (hasUnread) ...[
const SizedBox(width: 6),
_buildUnreadBadge(conversation.unreadCount),
],
],
),
],
),
),
if (conversation.isMuted) ...[
const SizedBox(width: 8),
const Icon(Icons.volume_off, size: 16, color: AppTheme.textSecondary),
],
if (conversation.pinned) ...[
const SizedBox(width: 8),
const Icon(Icons.push_pin, size: 16, color: AppTheme.textSecondary),
],
if (hasUnread) ...[
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.all(6),
decoration: const BoxDecoration(
color: AppTheme.primary,
shape: BoxShape.circle,
),
child: Text(
conversation.unreadCount.toString(),
style: const TextStyle(
color: Colors.black,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
],
],
),
),
);
}
Widget _buildAvatar() {
if (conversation.avatar != null) {
// ── Avatar builder (cached network image + fallback initials) ─────────────
Widget _buildAvatar(BuildContext context, ConversationModel c) {
final isDark = AppTheme.isDark(context);
final fallbackBg =
isDark ? const Color(0xff2a3942) : const Color(0xff6b7c85);
if (c.avatar != null && c.avatar!.isNotEmpty) {
return CircleAvatar(
radius: 26,
backgroundImage: NetworkImage(conversation.avatar!),
backgroundColor: AppTheme.surfaceLight,
radius: 28,
backgroundColor: fallbackBg,
child: ClipOval(
child: CachedNetworkImage(
imageUrl: c.avatar!,
width: 56,
height: 56,
fit: BoxFit.cover,
placeholder: (_, __) => _initialsAvatar(c.name, fallbackBg),
errorWidget: (_, __, ___) => _initialsAvatar(c.name, fallbackBg),
),
),
);
}
// Group icon or person icon
if (c.isGroup) {
return CircleAvatar(
radius: 28,
backgroundColor: fallbackBg,
child: const Icon(Icons.group, color: Colors.white, size: 30),
);
}
return CircleAvatar(
radius: 26,
backgroundColor: AppTheme.primaryDark,
child: Text(
conversation.name.isNotEmpty ? conversation.name[0].toUpperCase() : '?',
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
radius: 28,
backgroundColor: fallbackBg,
child: _initialsAvatar(c.name, fallbackBg),
);
}
Widget _initialsAvatar(String name, Color bg) {
return Container(
width: 56,
height: 56,
color: bg,
alignment: Alignment.center,
child: Icon(
Icons.person,
color: Colors.white,
size: 30,
),
);
}
String _getSubtitleText(LastMessageModel? lastMsg) {
// ── Unread badge ──────────────────────────────────────────────────────────
Widget _buildUnreadBadge(int count) {
return Container(
constraints: const BoxConstraints(minWidth: 20, minHeight: 20),
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: const BoxDecoration(
color: AppTheme.primary,
shape: BoxShape.circle,
),
child: Text(
count > 99 ? '99+' : count.toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 11.5,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
);
}
// ── ACK (delivery status) icon ────────────────────────────────────────────
// Real WhatsApp ACK levels from whatsapp-web.js:
// -1 = error → clock (pending/error)
// 0 = pending → clock
// 1 = sent → single grey tick
// 2 = received → double grey tick
// 3 = read/played→ double blue tick
Widget _buildAckIcon(BuildContext context, int ack) {
switch (ack) {
case -1:
case 0:
// Pending / clock
return Icon(Icons.access_time_rounded,
size: 14, color: AppTheme.textSecondary(context));
case 1:
// Sent — single grey tick
return Icon(Icons.check_rounded,
size: 15, color: AppTheme.textSecondary(context));
case 2:
// Delivered — double grey tick
return Icon(Icons.done_all_rounded,
size: 15, color: AppTheme.textSecondary(context));
case 3:
// Read — double blue tick
return const Icon(Icons.done_all_rounded,
size: 15, color: AppTheme.blueTick);
default:
return const SizedBox.shrink();
}
}
// ── Subtitle text ─────────────────────────────────────────────────────────
String _getSubtitleText(BuildContext context, LastMessageModel? lastMsg) {
if (lastMsg == null) return '';
if (lastMsg.hasMedia) {
return '📷 Photo'; // or other media indicator
return '📷 Photo';
}
return lastMsg.body;
}
// ── Time formatter ────────────────────────────────────────────────────────
String _formatTime(int timestamp) {
if (timestamp == 0) return '';
final dt = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
@@ -137,13 +238,13 @@ class ConversationTile extends StatelessWidget {
final msgDate = DateTime(dt.year, dt.month, dt.day);
if (msgDate == today) {
return DateFormat('hh:mm a').format(dt);
return DateFormat('h:mm a').format(dt);
} else if (msgDate == yesterday) {
return 'Yesterday';
} else if (now.difference(dt).inDays < 7) {
return DateFormat('EEEE').format(dt); // e.g. "Monday"
return DateFormat('EEEE').format(dt);
} else {
return DateFormat('MM/dd/yy').format(dt);
return DateFormat('dd/MM/yy').format(dt);
}
}
}

View File

@@ -52,118 +52,171 @@ class MessageBubble extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isMe = message.fromMe;
final align = isMe ? CrossAxisAlignment.end : CrossAxisAlignment.start;
final bg = isMe ? AppTheme.outgoingMsg : AppTheme.incomingMsg;
final isMe = message.fromMe;
final isDark = AppTheme.isDark(context);
final bg = isMe
? AppTheme.outgoingMsg(context)
: AppTheme.incomingMsg(context);
final radius = isMe
? const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(0),
bottomLeft: Radius.circular(12),
topLeft: Radius.circular(12),
topRight: Radius.circular(4),
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
)
: const BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(12),
bottomLeft: Radius.circular(12),
topLeft: Radius.circular(4),
topRight: Radius.circular(12),
bottomLeft: Radius.circular(12),
bottomRight: Radius.circular(12),
);
// Incoming message shadow/border in light mode
final BoxDecoration decoration = BoxDecoration(
color: bg,
borderRadius: radius,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(isDark ? 0.2 : 0.08),
blurRadius: 2,
offset: const Offset(0, 1),
),
],
);
return Container(
margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
margin: EdgeInsets.only(
top: 2,
bottom: 2,
left: isMe ? 60 : 8,
right: isMe ? 8 : 60,
),
child: Column(
crossAxisAlignment: align,
crossAxisAlignment:
isMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
children: [
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.75,
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: bg,
borderRadius: radius,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Sender name in group chats
if (!isMe && message.author != null) ...[
Text(
message.author!,
style: const TextStyle(
color: AppTheme.primary,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
],
// Media widget
if (message.hasMedia) ...[
InteractiveMediaWidget(message: message),
const SizedBox(height: 6),
],
// Text + time + ACK row
Row(
// Tail + bubble
Stack(
children: [
// Message bubble
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.78,
),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: decoration,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Flexible(
child: Text(
message.body,
// Sender name in group chats (incoming only)
if (!isMe && message.author != null) ...[
Text(
message.author!,
style: const TextStyle(
color: AppTheme.textPrimary,
fontSize: 15,
color: AppTheme.primaryDark,
fontSize: 12.5,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 8),
Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_formatTime(message.timestamp),
style: const TextStyle(
color: AppTheme.textSecondary,
fontSize: 10,
),
),
if (isMe) ...[
const SizedBox(width: 4),
_buildAckIcon(message.ack),
],
],
),
),
const SizedBox(height: 2),
],
// Media
if (message.hasMedia) ...[
InteractiveMediaWidget(message: message),
const SizedBox(height: 4),
],
// Text + time + ACK row
_buildTextTimeRow(context, isMe),
],
),
],
),
),
],
),
],
),
);
}
Widget _buildAckIcon(int ack) {
Widget _buildTextTimeRow(BuildContext context, bool isMe) {
// If body is empty (media-only message), just show time+ack
final hasBody = message.body.trim().isNotEmpty;
if (!hasBody && message.hasMedia) {
// Show only time+ack at bottom right of media
return Align(
alignment: Alignment.bottomRight,
child: _timeAckRow(context, isMe),
);
}
return Wrap(
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.end,
children: [
if (hasBody)
Text(
message.body,
style: TextStyle(
color: AppTheme.textPrimary(context),
fontSize: 15,
),
),
const SizedBox(width: 4),
_timeAckRow(context, isMe),
],
);
}
Widget _timeAckRow(BuildContext context, bool isMe) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_formatTime(message.timestamp),
style: TextStyle(
color: AppTheme.textSecondary(context),
fontSize: 11,
),
),
if (isMe) ...[
const SizedBox(width: 3),
_buildAckIcon(context, message.ack),
],
],
);
}
// ── ACK icon ──────────────────────────────────────────────────────────────
// Real WhatsApp ACK values from whatsapp-web.js:
// -1 = error
// 0 = pending (clock icon)
// 1 = sent (single grey tick ✓)
// 2 = delivered/received (double grey tick ✓✓)
// 3 = read/played (double BLUE tick ✓✓)
Widget _buildAckIcon(BuildContext context, int ack) {
switch (ack) {
case 1: // Pending/Queued
return const Icon(Icons.access_time,
size: 13, color: AppTheme.textSecondary);
case 2: // Sent (single grey tick)
return const Icon(Icons.done, size: 15, color: AppTheme.textSecondary);
case 3: // Delivered (double grey tick)
return const Icon(Icons.done_all,
size: 15, color: AppTheme.textSecondary);
case 4: // Read (double blue tick)
return const Icon(Icons.done_all, size: 15, color: Colors.blue);
case 5: // Played audio/video (double blue with wave icon)
return const Icon(Icons.done_all, size: 15, color: Colors.blue);
case -1:
case 0:
// Pending — clock
return Icon(Icons.access_time_rounded,
size: 14, color: AppTheme.textSecondary(context));
case 1:
// Sent — single grey tick
return Icon(Icons.check_rounded,
size: 16, color: AppTheme.textSecondary(context));
case 2:
// Delivered — double grey tick
return Icon(Icons.done_all_rounded,
size: 16, color: AppTheme.textSecondary(context));
case 3:
// Read — double blue tick
return const Icon(Icons.done_all_rounded,
size: 16, color: AppTheme.blueTick);
default:
return const SizedBox.shrink();
}
@@ -291,7 +344,7 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
width: 140,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.15),
color: Colors.black.withOpacity(0.12),
borderRadius: BorderRadius.circular(8),
),
child: const SizedBox(
@@ -307,32 +360,50 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
return GestureDetector(
onTap: _downloadMedia,
child: Container(
padding: const EdgeInsets.all(12),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.15),
color: Colors.black.withOpacity(0.10),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(_getIcon(), color: AppTheme.textSecondary, size: 32),
const SizedBox(width: 12),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: AppTheme.primary.withOpacity(0.15),
shape: BoxShape.circle,
),
child: Icon(_getIcon(),
color: AppTheme.primary, size: 22),
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
_getLabel(),
style: const TextStyle(
color: AppTheme.textPrimary,
style: TextStyle(
color: AppTheme.textPrimary(context),
fontWeight: FontWeight.w500,
fontSize: 13),
),
const SizedBox(height: 2),
const Text(
'Tap to download',
style:
TextStyle(color: AppTheme.textSecondary, fontSize: 10),
Row(
children: [
Icon(Icons.download_rounded,
size: 12,
color: AppTheme.textSecondary(context)),
const SizedBox(width: 3),
Text(
'Tap to download',
style: TextStyle(
color: AppTheme.textSecondary(context),
fontSize: 11),
),
],
),
],
),
@@ -354,7 +425,7 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
Widget _buildDownloadedMedia(BuildContext context, String base64Data) {
final bytes = base64Decode(base64Data);
// ── Image / Sticker: full-screen viewer on tap ─────────────────────────
// ── Image / Sticker ────────────────────────────────────────────────────
if (widget.message.type == "image" || widget.message.type == "sticker") {
final heroTag = 'img_${widget.message.id}';
return GestureDetector(
@@ -377,7 +448,7 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 250),
constraints: const BoxConstraints(maxHeight: 260),
child: Image.memory(
bytes,
fit: BoxFit.cover,
@@ -391,30 +462,29 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
// ── Audio / Voice Note ─────────────────────────────────────────────────
if (widget.message.type == "audio") {
final durationStr = _audioDurationSeconds > 1
? '${(_audioDurationSeconds ~/ 60).toString().padLeft(1, '0')}:${(_audioDurationSeconds % 60).toString().padLeft(2, '0')}'
: '0:${_audioCurrentSeconds.toString().padLeft(2, '0')}';
final totalSec = _audioDurationSeconds > 1 ? _audioDurationSeconds : _audioCurrentSeconds;
final durationStr =
'${(totalSec ~/ 60).toString().padLeft(1, '0')}:${(totalSec % 60).toString().padLeft(2, '0')}';
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.15),
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: Icon(
_isPlaying
? Icons.pause_circle_filled
: Icons.play_circle_filled,
color: AppTheme.primary,
size: 36,
CircleAvatar(
radius: 18,
backgroundColor: AppTheme.primary,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(
_isPlaying
? Icons.pause_rounded
: Icons.play_arrow_rounded,
color: Colors.white,
size: 20,
),
onPressed: () => _toggleAudioPlayback(base64Data),
),
onPressed: () => _toggleAudioPlayback(base64Data),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
),
const SizedBox(width: 8),
Expanded(
@@ -423,13 +493,14 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
children: [
SliderTheme(
data: SliderTheme.of(context).copyWith(
trackHeight: 2.5,
trackHeight: 2,
thumbShape:
const RoundSliderThumbShape(enabledThumbRadius: 5),
overlayShape:
const RoundSliderOverlayShape(overlayRadius: 10),
activeTrackColor: AppTheme.primary,
inactiveTrackColor: AppTheme.surfaceLight,
inactiveTrackColor:
AppTheme.textSecondary(context).withOpacity(0.3),
thumbColor: AppTheme.primary,
overlayColor: AppTheme.primary.withOpacity(0.2),
),
@@ -438,7 +509,8 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
onChanged: (v) async {
final targetMs =
(v * _audioDurationSeconds * 1000).toInt();
await _player.seek(Duration(milliseconds: targetMs));
await _player
.seek(Duration(milliseconds: targetMs));
},
),
),
@@ -446,10 +518,10 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
padding: const EdgeInsets.only(left: 4),
child: Text(
durationStr,
style: const TextStyle(
color: AppTheme.textSecondary,
fontFamily: 'monospace',
fontSize: 10,
style: TextStyle(
color: AppTheme.textSecondary(context),
fontSize: 11,
fontFeatures: const [FontFeature.tabularFigures()],
),
),
),
@@ -463,21 +535,31 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
// ── Default: Document / File ───────────────────────────────────────────
return Container(
padding: const EdgeInsets.all(12),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.15),
color: Colors.black.withOpacity(0.10),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.check_circle_outline,
color: AppTheme.primary, size: 32),
const SizedBox(width: 12),
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: AppTheme.primary.withOpacity(0.15),
shape: BoxShape.circle,
),
child: const Icon(Icons.insert_drive_file_rounded,
color: AppTheme.primary, size: 22),
),
const SizedBox(width: 10),
Text(
_getLabel(),
style: const TextStyle(
color: AppTheme.textPrimary, fontWeight: FontWeight.w500),
style: TextStyle(
color: AppTheme.textPrimary(context),
fontWeight: FontWeight.w500,
fontSize: 13),
),
],
),
@@ -487,30 +569,30 @@ class _InteractiveMediaWidgetState extends State<InteractiveMediaWidget> {
IconData _getIcon() {
switch (widget.message.type) {
case "image":
return Icons.photo_outlined;
return Icons.photo_camera_rounded;
case "video":
return Icons.videocam_outlined;
return Icons.videocam_rounded;
case "audio":
return Icons.audiotrack_outlined;
return Icons.mic_rounded;
case "sticker":
return Icons.emoji_emotions_outlined;
return Icons.emoji_emotions_rounded;
default:
return Icons.insert_drive_file_outlined;
return Icons.insert_drive_file_rounded;
}
}
String _getLabel() {
switch (widget.message.type) {
case "image":
return "Image Attachment";
return "Photo";
case "video":
return "Video Attachment";
return "Video";
case "audio":
return "Audio / Voice Note";
return "Voice note";
case "sticker":
return "Sticker Attachment";
return "Sticker";
default:
return "File Attachment";
return "File";
}
}
}