feat: can share any contact using qr code (#30)
All checks were successful
/ mirror (push) Successful in 4s
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:
parent
e164f68bb8
commit
ee1f2ee4b1
@ -1,5 +1,3 @@
|
|||||||
// alphabet_scrollpage.dart
|
|
||||||
import 'dart:ui';
|
|
||||||
import 'package:dialer/services/obfuscate_service.dart';
|
import 'package:dialer/services/obfuscate_service.dart';
|
||||||
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';
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'package:dialer/services/obfuscate_service.dart';
|
import 'package:dialer/services/obfuscate_service.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 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.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 '../../../services/contact_service.dart';
|
||||||
|
|
||||||
class ContactModal extends StatefulWidget {
|
class ContactModal extends StatefulWidget {
|
||||||
final Contact contact;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
String email = widget.contact.emails.isNotEmpty
|
String email = widget.contact.emails.isNotEmpty
|
||||||
@ -188,6 +192,8 @@ class _ContactModalState extends State<ContactModal> {
|
|||||||
onSelected: (String choice) {
|
onSelected: (String choice) {
|
||||||
if (choice == 'delete') {
|
if (choice == 'delete') {
|
||||||
_deleteContact();
|
_deleteContact();
|
||||||
|
} else if (choice == 'share') {
|
||||||
|
_shareContactAsQRCode();
|
||||||
}
|
}
|
||||||
// Handle other choices if needed
|
// Handle other choices if needed
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_contacts/contact.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 {
|
class QRCodeButton extends StatelessWidget {
|
||||||
final List<Contact> contacts;
|
final List<Contact> contacts;
|
||||||
@ -23,32 +23,13 @@ class QRCodeButton extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return IconButton(
|
return IconButton(
|
||||||
icon: Icon(Icons.qr_code, color: selfContact != null ? Colors.blue : Colors.grey),
|
icon: Icon(Icons.qr_code, color: selfContact != null ? Colors.blue : Colors.grey),
|
||||||
onPressed: selfContact != null
|
onPressed: selfContact != null
|
||||||
? () {
|
? () {
|
||||||
showDialog(
|
// Use the ContactService to show the QR code
|
||||||
barrierColor: Colors.white24,
|
ContactService().showContactQRCodeDialog(context, selfContact!);
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||||
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
|
|
||||||
// Service to manage contact-related operations
|
// Service to manage contact-related operations
|
||||||
class ContactService {
|
class ContactService {
|
||||||
@ -15,17 +17,35 @@ class ContactService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Contact>> fetchFavoriteContacts() async {
|
Future<List<Contact>> fetchFavoriteContacts() async {
|
||||||
// Fetch all contacts
|
|
||||||
List<Contact> contacts = await fetchContacts();
|
List<Contact> contacts = await fetchContacts();
|
||||||
|
return contacts.where((contact) => contact.isStarred).toList();
|
||||||
// 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 {
|
Future<void> addNewContact(Contact contact) async {
|
||||||
await FlutterContacts.insertContact(contact);
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user