monorepo/dialer/lib/services/contact_service.dart
Florian Griffon ee1f2ee4b1
All checks were successful
/ mirror (push) Successful in 4s
feat: can share any contact using qr code (#30)
Reviewed-on: #30
Co-authored-by: Florian Griffon <florian.griffon@epitech.eu>
Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
2025-01-30 14:15:07 +00:00

52 lines
1.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:qr_flutter/qr_flutter.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 {
List<Contact> contacts = await fetchContacts();
return contacts.where((contact) => contact.isStarred).toList();
}
Future<void> addNewContact(Contact contact) async {
await FlutterContacts.insertContact(contact);
}
// Function to show an AlertDialog with a QR code for the contact's vCard
void showContactQRCodeDialog(BuildContext context, Contact contact) {
showDialog(
barrierColor: Colors.white24,
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
backgroundColor: Colors.black,
content: SizedBox(
width: 200,
height: 220,
child: QrImageView(
data: contact.toVCard(), // Generate vCard QR code
version: QrVersions.auto,
backgroundColor: Colors.white, // Make sure QR code is visible on black background
size: 200.0,
),
),
);
},
);
}
}