// DisplayContact.dart import 'package:dialer/features/composition/composition.dart'; import 'package:dialer/classes/contactClass.dart'; import 'package:dialer/classes/displayAvatar.dart'; import 'package:flutter/material.dart'; import 'package:dialer/features/history/history_page.dart'; class DisplayContact extends StatelessWidget { final Contact contact; final History? history; const DisplayContact({ super.key, required this.contact, this.history, }); String getTimeElapsed(DateTime date) { final now = DateTime.now(); final difference = now.difference(date); if (difference.inDays > 0) { return '${difference.inDays} days ago'; } else if (difference.inHours > 0) { return '${difference.inHours} hours ago'; } else if (difference.inMinutes > 0) { return '${difference.inMinutes} minutes ago'; } else { return 'Just now'; } } void _openVisualPage(BuildContext context) { Navigator.push( context, MaterialPageRoute( builder: (context) => const CompositionPage(), ), ); } @override Widget build(BuildContext context) { return ListTile( leading: DisplayAvatar(contact: contact), title: Text(contact.name), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(contact.phoneNumber), if (contact.publicKey != null) Text( 'key: ${contact.publicKey!.substring(0, 2)}...${contact.publicKey!.substring(contact.publicKey!.length - 2)}', ), if (history != null) ...[ Row( children: [ Icon( history!.callType == 'incoming' ? Icons.call_received : Icons.call_made, size: 16, color: history!.callStatus == 'missed' ? Colors.red : Colors.green, ), const SizedBox(width: 4), Text('${history!.callStatus}, attempts: ${history!.attempts}'), ], ), Text(getTimeElapsed(history!.date)), ], ], ), trailing: InkWell( onTap: () => _openVisualPage(context), child: const Icon(Icons.call), ), isThreeLine: true, onTap: () { // Add code here to handle contact tap }, ); } }