feat: History page has contact modal on profile picture (#31)
Some checks failed
/ mirror (push) Failing after 6s
Some checks failed
/ mirror (push) Failing after 6s
Reviewed-on: #31 Co-authored-by: Florian Griffon <florian.griffon@epitech.eu> Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
This commit is contained in:
parent
f99fdaa160
commit
f3f5c70620
@ -7,6 +7,7 @@ import 'package:url_launcher/url_launcher.dart';
|
|||||||
import 'package:dialer/features/contacts/contact_state.dart';
|
import 'package:dialer/features/contacts/contact_state.dart';
|
||||||
import 'package:dialer/widgets/username_color_generator.dart';
|
import 'package:dialer/widgets/username_color_generator.dart';
|
||||||
import '../../services/block_service.dart';
|
import '../../services/block_service.dart';
|
||||||
|
import '../contacts/widgets/contact_modal.dart';
|
||||||
|
|
||||||
class History {
|
class History {
|
||||||
final Contact contact;
|
final Contact contact;
|
||||||
@ -47,6 +48,45 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _refreshContacts() async {
|
||||||
|
final contactState = ContactState.of(context);
|
||||||
|
try {
|
||||||
|
// Refresh contacts or fetch them again
|
||||||
|
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 {
|
||||||
|
// Ensure you have the necessary permissions to fetch contact details
|
||||||
|
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(); // Refresh the contact list
|
||||||
|
} 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')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _buildHistories() async {
|
Future<void> _buildHistories() async {
|
||||||
final contactState = ContactState.of(context);
|
final contactState = ContactState.of(context);
|
||||||
if (contactState.loading) {
|
if (contactState.loading) {
|
||||||
@ -213,11 +253,53 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: ObfuscatedAvatar(
|
leading: GestureDetector(
|
||||||
imageBytes: contact.thumbnail,
|
onTap: () {
|
||||||
radius: 25,
|
// When the profile picture is tapped, show the ContactModal
|
||||||
backgroundColor: avatarColor,
|
showModalBottomSheet(
|
||||||
fallbackInitial: contact.displayName,
|
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,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ObfuscatedAvatar(
|
||||||
|
imageBytes: contact.thumbnail,
|
||||||
|
radius: 25,
|
||||||
|
backgroundColor: avatarColor,
|
||||||
|
fallbackInitial: contact.displayName,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
title: Text(
|
title: Text(
|
||||||
_obfuscateService.obfuscateData(contact.displayName),
|
_obfuscateService.obfuscateData(contact.displayName),
|
||||||
@ -327,9 +409,8 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
if (phoneNumber == null) {
|
if (phoneNumber == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content:
|
content:
|
||||||
Text('Contact has no phone number'),
|
Text('Contact has no phone number')),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -352,10 +433,8 @@ class _HistoryPageState extends State<HistoryPage>
|
|||||||
icon: Icon(
|
icon: Icon(
|
||||||
isBlocked ? Icons.lock_open : Icons.block,
|
isBlocked ? Icons.lock_open : Icons.block,
|
||||||
color: Colors.white),
|
color: Colors.white),
|
||||||
label: Text(
|
label: Text(isBlocked ? 'Unblock' : 'Block',
|
||||||
isBlocked ? 'Unblock' : 'Block',
|
style: const TextStyle(color: Colors.white)),
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user