Compare commits

..

No commits in common. "179f2015bc3568053c2b739bb53140c6857dadbc" and "4062ae75d36d74604b7b86227e08c05e36c84edf" have entirely different histories.

14 changed files with 186 additions and 602 deletions

View File

@ -1,8 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/> <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera" android:required="false" />
<!-- The INTERNET permission is required for development. Specifically, <!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application the Flutter tool needs it to communicate with the running application

View File

@ -1,8 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/> <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application <application
android:label="com.example.dialer" android:label="com.example.dialer"
android:name="${applicationName}" android:name="${applicationName}"

View File

@ -1,8 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/> <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera" android:required="false" />
<!-- The INTERNET permission is required for development. Specifically, <!-- The INTERNET permission is required for development. Specifically,

View File

@ -1,8 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../widgets/contact_service.dart';
import '../contacts/widgets/add_contact_button.dart';
class CompositionPage extends StatefulWidget { class CompositionPage extends StatefulWidget {
const CompositionPage({super.key}); const CompositionPage({super.key});
@ -15,7 +12,6 @@ class _CompositionPageState extends State<CompositionPage> {
String dialedNumber = ""; String dialedNumber = "";
List<Contact> _allContacts = []; List<Contact> _allContacts = [];
List<Contact> _filteredContacts = []; List<Contact> _filteredContacts = [];
final ContactService _contactService = ContactService();
@override @override
void initState() { void initState() {
@ -24,9 +20,11 @@ class _CompositionPageState extends State<CompositionPage> {
} }
Future<void> _fetchContacts() async { Future<void> _fetchContacts() async {
_allContacts = await _contactService.fetchContacts(); if (await FlutterContacts.requestPermission()) {
_filteredContacts = _allContacts; _allContacts = await FlutterContacts.getContacts(withProperties: true);
setState(() {}); _filteredContacts = _allContacts;
setState(() {});
}
} }
void _filterContacts() { void _filterContacts() {
@ -65,24 +63,9 @@ class _CompositionPageState extends State<CompositionPage> {
}); });
} }
// Function to call a contact's number // Placeholder function for adding contact
void _launchPhoneDialer(String phoneNumber) async { void addContact(String number) {
final uri = Uri(scheme: 'tel', path: phoneNumber); // This function is empty for now
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
debugPrint('Could not launch $phoneNumber');
}
}
// Function to send an SMS to a contact's number
void _launchSms(String phoneNumber) async {
final uri = Uri(scheme: 'sms', path: phoneNumber);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
debugPrint('Could not send SMS to $phoneNumber');
}
} }
@override @override
@ -96,9 +79,9 @@ class _CompositionPageState extends State<CompositionPage> {
// Top half: Display contacts matching dialed number // Top half: Display contacts matching dialed number
Expanded( Expanded(
flex: 2, flex: 2,
child: Container( child:
padding: const EdgeInsets.only( Container(
top: 42.0, left: 16.0, right: 16.0, bottom: 16.0), padding: const EdgeInsets.only(top: 42.0, left: 16.0, right: 16.0, bottom: 16.0),
color: Colors.black, color: Colors.black,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -107,39 +90,32 @@ class _CompositionPageState extends State<CompositionPage> {
child: ListView( child: ListView(
children: _filteredContacts.isNotEmpty children: _filteredContacts.isNotEmpty
? _filteredContacts.map((contact) { ? _filteredContacts.map((contact) {
final phoneNumber = contact.phones.isNotEmpty
? contact.phones.first.number
: 'No phone number';
return ListTile( return ListTile(
title: Text( title: Text(
contact.displayName, contact.displayName,
style: style: const TextStyle(color: Colors.white),
const TextStyle(color: Colors.white),
),
subtitle: Text(
phoneNumber,
style:
const TextStyle(color: Colors.grey),
), ),
subtitle: contact.phones.isNotEmpty
? Text(
contact.phones.first.number,
style: const TextStyle(color: Colors.grey),
)
: null,
trailing: Row( trailing: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
// Call button // Call button
IconButton( IconButton(
icon: Icon(Icons.phone, icon: Icon(Icons.phone, color: Colors.green[300], size: 20),
color: Colors.green[300],
size: 20),
onPressed: () { onPressed: () {
_launchPhoneDialer(phoneNumber); print('Calling ${contact.displayName}');
}, },
), ),
// Message button // Text button
IconButton( IconButton(
icon: Icon(Icons.message, icon: Icon(Icons.message, color: Colors.blue[300], size: 20),
color: Colors.blue[300],
size: 20),
onPressed: () { onPressed: () {
_launchSms(phoneNumber); print('Texting ${contact.displayName}');
}, },
), ),
], ],
@ -149,12 +125,7 @@ class _CompositionPageState extends State<CompositionPage> {
}, },
); );
}).toList() }).toList()
: [ : [Center(child: Text('No contacts found', style: TextStyle(color: Colors.white)))],
Center(
child: Text('No contacts found',
style:
TextStyle(color: Colors.white)))
],
), ),
), ),
], ],
@ -179,16 +150,14 @@ class _CompositionPageState extends State<CompositionPage> {
alignment: Alignment.center, alignment: Alignment.center,
child: Text( child: Text(
dialedNumber, dialedNumber,
style: const TextStyle( style: const TextStyle(fontSize: 24, color: Colors.white),
fontSize: 24, color: Colors.white),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
), ),
IconButton( IconButton(
onPressed: _onClearPress, onPressed: _onClearPress,
icon: const Icon(Icons.backspace, icon: const Icon(Icons.backspace, color: Colors.white),
color: Colors.white),
), ),
], ],
), ),
@ -201,8 +170,7 @@ class _CompositionPageState extends State<CompositionPage> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
Row( Row(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.spaceEvenly,
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('1'), _buildDialButton('1'),
_buildDialButton('2'), _buildDialButton('2'),
@ -210,8 +178,7 @@ class _CompositionPageState extends State<CompositionPage> {
], ],
), ),
Row( Row(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.spaceEvenly,
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('4'), _buildDialButton('4'),
_buildDialButton('5'), _buildDialButton('5'),
@ -219,8 +186,7 @@ class _CompositionPageState extends State<CompositionPage> {
], ],
), ),
Row( Row(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.spaceEvenly,
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('7'), _buildDialButton('7'),
_buildDialButton('8'), _buildDialButton('8'),
@ -228,8 +194,7 @@ class _CompositionPageState extends State<CompositionPage> {
], ],
), ),
Row( Row(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.spaceEvenly,
MainAxisAlignment.spaceEvenly,
children: [ children: [
_buildDialButton('*'), _buildDialButton('*'),
_buildDialButton('0'), _buildDialButton('0'),
@ -244,19 +209,20 @@ class _CompositionPageState extends State<CompositionPage> {
), ),
), ),
), ),
// Add Contact Button with empty function call
Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: FloatingActionButton(
backgroundColor: Colors.blue,
onPressed: () {
addContact(dialedNumber);
},
child: const Icon(Icons.person_add, color: Colors.white),
),
),
], ],
), ),
// Add Contact Button
Positioned(
bottom: 20.0,
left: 0,
right: 0,
child: Center(
child: AddContactButton(),
),
),
// Top Row with Back Arrow // Top Row with Back Arrow
Positioned( Positioned(
top: 40.0, top: 40.0,

View File

@ -17,10 +17,8 @@ class _ContactPageState extends State<ContactPage> {
return Scaffold( return Scaffold(
body: contactState.loading body: contactState.loading
? const LoadingIndicatorWidget() ? const LoadingIndicatorWidget()
: AlphabetScrollPage( // : ContactListWidget(contacts: contactState.contacts),
scrollOffset: contactState.scrollOffset, : AlphabetScrollPage(contacts: contactState.contacts, scrollOffset: contactState.scrollOffset),
contacts: contactState.contacts, // Use all contacts here
),
); );
} }
} }

View File

@ -0,0 +1,15 @@
import 'package:flutter_contacts/flutter_contacts.dart';
// Service to manage contact-related operations
class ContactService {
Future<List<Contact>> fetchContacts() async {
if (await FlutterContacts.requestPermission()) {
return await FlutterContacts.getContacts(withProperties: true, withThumbnail: true, withAccounts: true, withGroups: true);
}
return [];
}
Future<void> addNewContact(Contact contact) async {
await FlutterContacts.insertContact(contact);
}
}

View File

@ -1,122 +1,99 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import '../../widgets/contact_service.dart'; import 'contact_service.dart';
class ContactState extends StatefulWidget { class ContactState extends StatefulWidget {
final Widget child; final Widget child;
const ContactState({super.key, required this.child}); const ContactState({super.key, required this.child});
static _ContactStateState of(BuildContext context) { static _ContactStateState of(BuildContext context) {
return context return context.dependOnInheritedWidgetOfExactType<_InheritedContactState>()!.data;
.dependOnInheritedWidgetOfExactType<_InheritedContactState>()! }
.data;
@override
_ContactStateState createState() => _ContactStateState();
} }
@override class _ContactStateState extends State<ContactState> {
_ContactStateState createState() => _ContactStateState(); final ContactService _contactService = ContactService();
} List<Contact> _contacts = [];
bool _loading = true;
double _scrollOffset = 0.0;
Contact? _selfContact = Contact();
class _ContactStateState extends State<ContactState> { List<Contact> get contacts => _contacts;
final ContactService _contactService = ContactService(); bool get loading => _loading;
List<Contact> _allContacts = []; double get scrollOffset => _scrollOffset;
List<Contact> _favoriteContacts = []; Contact? get selfContact => _selfContact;
bool _loading = true;
double _scrollOffset = 0.0;
Contact? _selfContact = Contact();
// Getters for all contacts and favorites @override
List<Contact> get contacts => _allContacts; void initState() {
List<Contact> get favoriteContacts => _favoriteContacts; super.initState();
bool get loading => _loading; _fetchContacts();
double get scrollOffset => _scrollOffset;
Contact? get selfContact => _selfContact;
@override // Add listener for contact changes
void initState() { FlutterContacts.addListener(_onContactChange);
super.initState(); }
fetchContacts(); // Fetch all contacts by default
FlutterContacts.addListener(_onContactChange);
}
void _onContactChange() => fetchContacts(); void _onContactChange() => _fetchContacts();
@override @override
void dispose() { void dispose() {
FlutterContacts.removeListener(_onContactChange); // Remove listener
super.dispose(); FlutterContacts.removeListener(_onContactChange);
} super.dispose();
}
// Fetch all contacts Future<void> _fetchContacts() async {
Future<void> fetchContacts() async {
setState(() => _loading = true);
try {
List<Contact> contacts = await _contactService.fetchContacts(); List<Contact> contacts = await _contactService.fetchContacts();
_processContacts(contacts);
} finally { debugPrint("Fetched ${contacts.length} contacts");
setState(() => _loading = false);
// Find selfContact before filtering
_selfContact = contacts.firstWhere(
(contact) => contact.displayName.toLowerCase() == "user",
orElse: () => Contact(),
);
if (_selfContact!.phones.isEmpty) {
debugPrint("Self contact has no phone numbers");
_selfContact = null;
}
contacts = contacts.where((contact) => contact.phones.isNotEmpty).toList();
contacts.sort((a, b) => a.displayName.compareTo(b.displayName));
setState(() {
_contacts = contacts;
_loading = false;
_selfContact = _selfContact;
});
}
Future<void> addNewContact(Contact contact) async {
await _contactService.addNewContact(contact);
await _fetchContacts();
}
void setScrollOffset(double offset) {
setState(() {
_scrollOffset = offset;
});
}
@override
Widget build(BuildContext context) {
return _InheritedContactState(
data: this,
child: widget.child,
);
} }
} }
// Fetch only favorite contacts class _InheritedContactState extends InheritedWidget {
Future<void> fetchFavoriteContacts() async { final _ContactStateState data;
setState(() => _loading = true);
try { const _InheritedContactState({required this.data, required super.child});
List<Contact> contacts = await _contactService.fetchFavoriteContacts();
setState(() => _favoriteContacts = contacts); @override
} finally { bool updateShouldNotify(_InheritedContactState oldWidget) => true;
setState(() => _loading = false);
}
} }
void _processContacts(List<Contact> contacts) {
_selfContact = contacts.firstWhere(
(contact) => contact.displayName.toLowerCase() == "user",
orElse: () => Contact(),
);
if (_selfContact!.phones.isEmpty) {
debugPrint("Self contact has no phone numbers");
_selfContact = null;
}
contacts = contacts.where((contact) => contact.phones.isNotEmpty).toList();
contacts.sort((a, b) => a.displayName.compareTo(b.displayName));
setState(() {
_allContacts = contacts;
_favoriteContacts =
contacts.where((contact) => contact.isStarred).toList();
_selfContact = _selfContact;
});
}
Future<void> addNewContact(Contact contact) async {
await _contactService.addNewContact(contact);
await fetchContacts();
}
void setScrollOffset(double offset) {
setState(() {
_scrollOffset = offset;
});
}
@override
Widget build(BuildContext context) {
return _InheritedContactState(
data: this,
child: widget.child,
);
}
}
class _InheritedContactState extends InheritedWidget {
final _ContactStateState data;
const _InheritedContactState({required this.data, required super.child});
@override
bool updateShouldNotify(_InheritedContactState oldWidget) => true;
}

View File

@ -1,21 +1,16 @@
import 'package:dialer/widgets/username_color_generator.dart'; import 'package:dialer/widgets/username_color_generator.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import '../contact_state.dart';
import '../../../widgets/color_darkener.dart'; import '../../../widgets/color_darkener.dart';
import '../contact_state.dart';
import 'add_contact_button.dart'; import 'add_contact_button.dart';
import 'contact_modal.dart';
import 'share_own_qr.dart'; import 'share_own_qr.dart';
class AlphabetScrollPage extends StatefulWidget { class AlphabetScrollPage extends StatefulWidget {
final double scrollOffset;
final List<Contact> contacts; final List<Contact> contacts;
final double scrollOffset;
const AlphabetScrollPage({ const AlphabetScrollPage({super.key, required this.contacts, required this.scrollOffset});
super.key,
required this.scrollOffset,
required this.contacts,
});
@override @override
_AlphabetScrollPageState createState() => _AlphabetScrollPageState(); _AlphabetScrollPageState createState() => _AlphabetScrollPageState();
@ -36,53 +31,11 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
contactState.setScrollOffset(_scrollController.offset); contactState.setScrollOffset(_scrollController.offset);
} }
Future<void> _refreshContacts() async {
final contactState = ContactState.of(context);
try {
await contactState.fetchContacts();
} catch (e) {
print('Error refreshing contacts: $e');
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to refresh contacts')),
);
}
}
void _toggleFavorite(Contact contact) async {
try {
if (await FlutterContacts.requestPermission()) {
Contact? fullContact = await FlutterContacts.getContact(contact.id,
withProperties: true,
withAccounts: true,
withPhoto: true,
withThumbnail: true);
if (fullContact != null) {
fullContact.isStarred = !fullContact.isStarred;
await FlutterContacts.updateContact(fullContact);
}
await _refreshContacts();
} else {
print("Could not fetch contact details");
}
} catch (e) {
print("Error updating favorite status: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to update contact favorite status')),
);
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final contacts = widget.contacts;
final selfContact = ContactState.of(context).selfContact;
Map<String, List<Contact>> alphabetizedContacts = {}; Map<String, List<Contact>> alphabetizedContacts = {};
for (var contact in contacts) { for (var contact in widget.contacts) {
String firstLetter = contact.displayName.isNotEmpty String firstLetter = contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '#';
? contact.displayName[0].toUpperCase()
: '#';
if (!alphabetizedContacts.containsKey(firstLetter)) { if (!alphabetizedContacts.containsKey(firstLetter)) {
alphabetizedContacts[firstLetter] = []; alphabetizedContacts[firstLetter] = [];
} }
@ -94,8 +47,7 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
return Scaffold( return Scaffold(
backgroundColor: Colors.black, backgroundColor: Colors.black,
body: Column( body: Column(
children: [ children: [ // Top buttons row
// Top buttons row
Container( Container(
color: Colors.black, color: Colors.black,
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
@ -103,7 +55,7 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
AddContactButton(), AddContactButton(),
QRCodeButton(contacts: contacts, selfContact: selfContact), QRCodeButton(contacts: widget.contacts, selfContact: ContactState.of(context).selfContact),
], ],
), ),
), ),
@ -114,14 +66,13 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
itemCount: alphabetKeys.length, itemCount: alphabetKeys.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
String letter = alphabetKeys[index]; String letter = alphabetKeys[index];
List<Contact> contactsForLetter = alphabetizedContacts[letter]!; List<Contact> contacts = alphabetizedContacts[letter]!;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Alphabet Letter Header // Alphabet Letter Header
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
vertical: 8.0, horizontal: 16.0),
child: Text( child: Text(
letter, letter,
style: TextStyle( style: TextStyle(
@ -132,74 +83,25 @@ class _AlphabetScrollPageState extends State<AlphabetScrollPage> {
), ),
), ),
// Contact Entries // Contact Entries
...contactsForLetter.map((contact) { ...contacts.map((contact) {
String phoneNumber = contact.phones.isNotEmpty String phoneNumber = contact.phones.isNotEmpty ? contact.phones.first.number : 'No phone number';
? contact.phones.first.number Color avatarColor = generateColorFromName(contact.displayName);
: 'No phone number';
Color avatarColor =
generateColorFromName(contact.displayName);
return ListTile( return ListTile(
leading: (contact.thumbnail != null && leading: (contact.thumbnail != null && contact.thumbnail!.isNotEmpty)
contact.thumbnail!.isNotEmpty)
? CircleAvatar( ? CircleAvatar(
backgroundImage: backgroundImage: MemoryImage(contact.thumbnail!),
MemoryImage(contact.thumbnail!), )
)
: CircleAvatar( : CircleAvatar(
backgroundColor: avatarColor, backgroundColor: avatarColor,
child: Text( child: Text(
contact.displayName.isNotEmpty contact.displayName.isNotEmpty ? contact.displayName[0].toUpperCase() : '?',
? contact.displayName[0].toUpperCase() style: TextStyle(color: darken(avatarColor, 0.4)),
: '?', ),
style: TextStyle( ),
color: darken(avatarColor, 0.4)), title: Text(contact.displayName, style: TextStyle(color: Colors.white)),
), subtitle: Text(phoneNumber, style: TextStyle(color: Colors.white70)),
),
title: Text(contact.displayName,
style: TextStyle(color: Colors.white)),
subtitle: Text(phoneNumber,
style: TextStyle(color: Colors.white70)),
onTap: () { onTap: () {
showModalBottomSheet( // Handle contact tap
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) {
return ContactModal(
contact: contact,
onEdit: () async {
if (await FlutterContacts.requestPermission()) {
final updatedContact =
await FlutterContacts.openExternalEdit(
contact.id);
if (updatedContact != null) {
await _refreshContacts();
Navigator.of(context).pop();
ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar(
content: Text(
'${contact.displayName} updated successfully!'),
),
);
} else {
ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar(
content:
Text('Edit canceled or failed.'),
),
);
}
}
},
onToggleFavorite: () {
_toggleFavorite(contact);
},
isFavorite: contact.isStarred,
);
},
);
}, },
); );
}), }),

View File

@ -1,227 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:dialer/widgets/username_color_generator.dart';
class ContactModal extends StatelessWidget {
final Contact contact;
final Function onEdit;
final Function onToggleFavorite;
final bool isFavorite;
const ContactModal({
super.key,
required this.contact,
required this.onEdit,
required this.onToggleFavorite,
required this.isFavorite,
});
void _launchPhoneDialer(String phoneNumber) async {
final uri = Uri(scheme: 'tel', path: phoneNumber);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
debugPrint('Could not launch $phoneNumber');
}
}
void _launchSms(String phoneNumber) async {
final uri = Uri(scheme: 'sms', path: phoneNumber);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
debugPrint('Could not launch SMS to $phoneNumber');
}
}
void _launchEmail(String email) async {
final uri = Uri(scheme: 'mailto', path: email);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
debugPrint('Could not launch email to $email');
}
}
@override
Widget build(BuildContext context) {
String phoneNumber = contact.phones.isNotEmpty
? contact.phones.first.number
: 'No phone number';
String email =
contact.emails.isNotEmpty ? contact.emails.first.address : 'No email';
return GestureDetector(
onTap: () => Navigator.of(context).pop(),
child: Container(
color: Colors.black.withOpacity(0.5),
child: GestureDetector(
onTap: () {},
child: FractionallySizedBox(
heightFactor: 0.7,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[900],
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Modal Handle
// Top Bar with Handle and Three-Dot Menu
Stack(
children: [
Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Container(
width: 50,
height: 5,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(5),
),
),
),
),
Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.only(top: 10, right: 10),
child: PopupMenuButton<String>(
icon: Icon(Icons.more_vert, color: Colors.white),
onSelected: (String choice) {
print(
'Selected: $choice'); // Placeholder for menu actions
},
itemBuilder: (BuildContext context) {
return <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: 'show_associated_contacts',
child: Text('Show associated contacts'),
),
PopupMenuItem<String>(
value: 'delete',
child: Text('Delete'),
),
PopupMenuItem<String>(
value: 'share',
child: Text('Share (via QR code)'),
),
PopupMenuItem<String>(
value: 'create_shortcut',
child:
Text('Create shortcut (to home screen)'),
),
PopupMenuItem<String>(
value: 'set_ringtone',
child: Text('Set ringtone'),
),
];
},
),
),
),
],
),
// Contact Profile
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
CircleAvatar(
radius: 50,
backgroundImage: (contact.thumbnail != null &&
contact.thumbnail!.isNotEmpty)
? MemoryImage(contact.thumbnail!)
: null,
backgroundColor:
generateColorFromName(contact.displayName),
child: (contact.thumbnail == null ||
contact.thumbnail!.isEmpty)
? Text(
contact.displayName.isNotEmpty
? contact.displayName[0].toUpperCase()
: '?',
style: TextStyle(
fontSize: 40, color: Colors.white),
)
: null,
),
SizedBox(height: 10),
Text(
contact.displayName,
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
],
),
),
// Contact Actions
Divider(),
ListTile(
leading: Icon(Icons.phone, color: Colors.green),
title: Text(phoneNumber),
onTap: () {
if (contact.phones.isNotEmpty) {
_launchPhoneDialer(phoneNumber);
}
},
),
ListTile(
leading: Icon(Icons.message, color: Colors.blue),
title: Text(phoneNumber),
onTap: () {
if (contact.phones.isNotEmpty) {
_launchSms(phoneNumber);
}
},
),
ListTile(
leading: Icon(Icons.email, color: Colors.orange),
title: Text(email),
onTap: () {
if (contact.emails.isNotEmpty) {
_launchEmail(email);
}
},
),
Divider(),
// Favorite and Edit Buttons
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton.icon(
onPressed: () {
Navigator.of(context).pop();
onToggleFavorite();
},
icon: Icon(contact.isStarred
? Icons.star
: Icons.star_border),
label: Text(
contact.isStarred ? 'Unfavorite' : 'Favorite'),
),
ElevatedButton.icon(
onPressed: () => onEdit(),
icon: Icon(Icons.edit),
label: Text('Edit Contact'),
),
],
),
),
SizedBox(height: 16),
],
),
),
),
),
),
);
}
}

View File

@ -1,32 +1,23 @@
import 'package:dialer/features/contacts/contact_state.dart';
import 'package:dialer/features/contacts/widgets/alphabet_scroll_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:dialer/widgets/loading_indicator.dart';
class FavoritesPage extends StatefulWidget { class FavoritePage extends StatefulWidget {
const FavoritesPage({super.key}); const FavoritePage({super.key});
@override @override
_FavoritesPageState createState() => _FavoritesPageState(); _FavoritePageState createState() => _FavoritePageState();
} }
class _FavoritesPageState extends State<FavoritesPage> { class _FavoritePageState extends State<FavoritePage> {
@override
void initState() {
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final contactState = ContactState.of(context);
return Scaffold( return Scaffold(
body: contactState.loading backgroundColor: Colors.black,
? const LoadingIndicatorWidget() body: Center( // Center the text within the body
: AlphabetScrollPage( child: Text(
scrollOffset: contactState.scrollOffset, "Hello",
contacts: style: TextStyle(color: Colors.white), // Change text color for visibility
contactState.favoriteContacts, // Use only favorites here ),
), ),
); );
} }
} }

View File

@ -5,15 +5,12 @@ import 'package:dialer/features/history/history_page.dart';
import 'package:dialer/features/composition/composition.dart'; import 'package:dialer/features/composition/composition.dart';
import 'package:flutter_contacts/flutter_contacts.dart'; import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:dialer/features/settings/settings.dart'; import 'package:dialer/features/settings/settings.dart';
import '../../widgets/contact_service.dart';
class _MyHomePageState extends State<MyHomePage> class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
late TabController _tabController; late TabController _tabController;
List<Contact> _allContacts = []; List<Contact> _allContacts = [];
List<Contact> _contactSuggestions = []; List<Contact> _contactSuggestions = [];
final ContactService _contactService = ContactService();
@override @override
void initState() { void initState() {
@ -25,8 +22,10 @@ class _MyHomePageState extends State<MyHomePage>
} }
void _fetchContacts() async { void _fetchContacts() async {
_allContacts = await _contactService.fetchContacts(); if (await FlutterContacts.requestPermission()) {
setState(() {}); _allContacts = await FlutterContacts.getContacts(withProperties: true);
setState(() {});
}
} }
void _onSearchChanged(String query) { void _onSearchChanged(String query) {
@ -62,7 +61,7 @@ class _MyHomePageState extends State<MyHomePage>
backgroundColor: Colors.black, backgroundColor: Colors.black,
body: Column( body: Column(
children: [ children: [
// Persistent Search Bar // Search Bar and 3-dot menu
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 24.0, top: 24.0,
@ -170,7 +169,7 @@ class _MyHomePageState extends State<MyHomePage>
TabBarView( TabBarView(
controller: _tabController, controller: _tabController,
children: const [ children: const [
FavoritesPage(), FavoritePage(),
HistoryPage(), HistoryPage(),
ContactPage(), ContactPage(),
], ],

View File

@ -34,7 +34,7 @@ class KeyManagementPage extends StatelessWidget {
MaterialPageRoute(builder: (context) => const ExportPrivateKeyPage()), MaterialPageRoute(builder: (context) => const ExportPrivateKeyPage()),
); );
break; break;
case 'Delete a key pair': case 'Delete a key pair, warning POPUP':
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => const DeleteKeyPairPage()), MaterialPageRoute(builder: (context) => const DeleteKeyPairPage()),
@ -52,7 +52,7 @@ class KeyManagementPage extends StatelessWidget {
'Display public key as QR code', 'Display public key as QR code',
'Generate a new key pair', 'Generate a new key pair',
'Export private key to password-encrypted file (AES 256)', 'Export private key to password-encrypted file (AES 256)',
'Delete a key pair', 'Delete a key pair, warning POPUP',
]; ];
return Scaffold( return Scaffold(

View File

@ -16,7 +16,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData( theme: ThemeData(
brightness: Brightness.dark brightness: Brightness.dark
), ),
home: SafeArea(child: MyHomePage()), home: const MyHomePage(),
) )
); );
} }

View File

@ -1,31 +0,0 @@
import 'package:flutter_contacts/flutter_contacts.dart';
// Service to manage contact-related operations
class ContactService {
Future<List<Contact>> fetchContacts() async {
if (await FlutterContacts.requestPermission()) {
return await FlutterContacts.getContacts(
withProperties: true,
withThumbnail: true,
withAccounts: true,
withGroups: true,
withPhoto: true);
}
return [];
}
Future<List<Contact>> fetchFavoriteContacts() async {
// Fetch all contacts
List<Contact> contacts = await fetchContacts();
// Filter contacts to only include those with isStarred: true
List<Contact> favoriteContacts =
contacts.where((contact) => contact.isStarred).toList();
return favoriteContacts;
}
Future<void> addNewContact(Contact contact) async {
await FlutterContacts.insertContact(contact);
}
}