This repository has been archived on 2024-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
dialer/lib/features/contacts/widgets/contact_list_widget.dart

40 lines
1.5 KiB
Dart
Raw Normal View History

2024-10-18 19:45:35 +00:00
import 'package:dialer/widgets/color_darkener.dart';
import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:dialer/widgets/username_color_generator.dart';
class ContactListWidget extends StatelessWidget {
final List<Contact> contacts;
const ContactListWidget({Key? key, required this.contacts}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: contacts.length,
itemBuilder: (context, index) {
Contact contact = contacts[index];
String phoneNumber = contact.phones.isNotEmpty ? contact.phones.first.number : 'No phone number';
Color avatarColor = generateColorFromName(contact.displayName);
return ListTile(
leading: (contact.thumbnail != null && contact.thumbnail!.isNotEmpty)
? CircleAvatar(
backgroundImage: MemoryImage(contact.thumbnail!),
)
: CircleAvatar(
backgroundColor: avatarColor,
child: Text(
contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '?',
style: TextStyle(fontSize: 25, color: darken(avatarColor, 0.4)),
),
),
title: Text(contact.displayName),
subtitle: Text(phoneNumber),
onTap: () {
// Handle contact tap
},
);
},
);
}
}