G-EIP-700-TLS-7-1-eip-steph.../lib/classes/displayContact.dart

84 lines
2.4 KiB
Dart
Raw Permalink Normal View History

2024-10-25 11:26:44 +00:00
// DisplayContact.dart
import 'package:dialer/features/composition/composition.dart';
2024-09-16 15:07:04 +00:00
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';
2024-09-16 15:07:04 +00:00
class DisplayContact extends StatelessWidget {
2024-10-25 11:26:44 +00:00
final Contact contact;
final History? history;
const DisplayContact({
super.key,
required this.contact,
this.history,
});
2024-09-16 15:07:04 +00:00
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) {
2024-10-25 11:26:44 +00:00
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const CompositionPage(),
2024-10-25 11:26:44 +00:00
),
);
2024-09-16 15:07:04 +00:00
}
@override
Widget build(BuildContext context) {
return ListTile(
leading: DisplayAvatar(contact: contact),
title: Text(contact.name),
2024-10-25 11:26:44 +00:00
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)}',
2024-10-25 11:26:44 +00:00
),
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)),
],
],
),
2024-09-16 15:07:04 +00:00
trailing: InkWell(
onTap: () => _openVisualPage(context),
child: const Icon(Icons.call),
),
2024-10-25 11:26:44 +00:00
isThreeLine: true,
2024-09-16 15:07:04 +00:00
onTap: () {
2024-10-25 11:26:44 +00:00
// Add code here to handle contact tap
2024-09-16 15:07:04 +00:00
},
);
}
}