feat: can share any contact using qr code (#30)
All checks were successful
/ mirror (push) Successful in 4s

Reviewed-on: #30
Co-authored-by: Florian Griffon <florian.griffon@epitech.eu>
Co-committed-by: Florian Griffon <florian.griffon@epitech.eu>
This commit is contained in:
Florian Griffon 2025-01-30 14:15:07 +00:00 committed by stcb
parent e164f68bb8
commit ee1f2ee4b1
4 changed files with 39 additions and 34 deletions

View File

@ -1,5 +1,3 @@
// alphabet_scrollpage.dart
import 'dart:ui';
import 'package:dialer/services/obfuscate_service.dart';
import 'package:dialer/widgets/username_color_generator.dart';
import 'package:flutter/material.dart';

View File

@ -1,11 +1,10 @@
import 'dart:ui';
import 'package:dialer/services/obfuscate_service.dart';
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';
import '../../../services/block_service.dart';
import '../../../services/contact_service.dart';
class ContactModal extends StatefulWidget {
final Contact contact;
@ -139,6 +138,11 @@ class _ContactModalState extends State<ContactModal> {
}
}
void _shareContactAsQRCode() {
// Use the ContactService to show the QR code for the contact's vCard
ContactService().showContactQRCodeDialog(context, widget.contact);
}
@override
Widget build(BuildContext context) {
String email = widget.contact.emails.isNotEmpty
@ -188,6 +192,8 @@ class _ContactModalState extends State<ContactModal> {
onSelected: (String choice) {
if (choice == 'delete') {
_deleteContact();
} else if (choice == 'share') {
_shareContactAsQRCode();
}
// Handle other choices if needed
},

View File

@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_contacts/contact.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:dialer/services/contact_service.dart';
class QRCodeButton extends StatelessWidget {
final List<Contact> contacts;
@ -23,32 +23,13 @@ class QRCodeButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return IconButton(
icon: Icon(Icons.qr_code, color: selfContact != null ? Colors.blue : Colors.grey),
onPressed: selfContact != null
? () {
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: selfContact!.toVCard(),
version: QrVersions.auto,
backgroundColor: Colors.white, // Ensure QR code is visible on black background
size: 200.0,
),
),
);
},
);
}
// Use the ContactService to show the QR code
ContactService().showContactQRCodeDialog(context, selfContact!);
}
: null,
);
}

View File

@ -1,4 +1,6 @@
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 {
@ -15,17 +17,35 @@ class ContactService {
}
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;
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,
),
),
);
},
);
}
}