48 lines
1.4 KiB
Dart
48 lines
1.4 KiB
Dart
|
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
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|