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

48 lines
1.4 KiB
Dart
Raw Normal View History

2024-09-16 15:07:04 +00:00
import 'package:dialer/pages/callingPage.dart';
import 'package:dialer/classes/contactClass.dart';
import 'package:dialer/classes/displayAvatar.dart';
import 'package:dialer/pages/history.dart';
import 'package:flutter/material.dart';
class DisplayContact extends StatelessWidget {
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';
}
}
final Contact contact;
final History? history;
const DisplayContact({super.key, required this.contact, this.history});
void _openVisualPage(BuildContext context) {
Navigator.push(context, MaterialPageRoute(builder: (context) => CallingPage(contact: contact)));
}
@override
Widget build(BuildContext context) {
return ListTile(
leading: DisplayAvatar(contact: contact),
title: Text(contact.name),
subtitle: history != null ? Text(getTimeElapsed(history!.date)) : null,
trailing: InkWell(
onTap: () => _openVisualPage(context),
child: const Icon(Icons.call),
),
onTap: () {
// Ajoutez ici le code pour appeler le contact
},
);
}
}