40 lines
1.5 KiB
Dart
40 lines
1.5 KiB
Dart
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
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |