|
|
|
@ -4,6 +4,8 @@ import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/services.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:file_picker/file_picker.dart'; |
|
|
|
import 'package:open_file/open_file.dart'; |
|
|
|
import 'package:pdf/widgets.dart' as pw; |
|
|
|
import 'package:qr_flutter/qr_flutter.dart'; |
|
|
|
import 'package:intl/intl.dart'; |
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
@ -912,10 +914,17 @@ Widget _buildImportProgressIndicator() { |
|
|
|
} |
|
|
|
|
|
|
|
void _showQRCode(Product product) { |
|
|
|
final qrUrl = 'https://stock.guycom.mg/${product.reference}'; |
|
|
|
|
|
|
|
Get.dialog( |
|
|
|
AlertDialog( |
|
|
|
// État pour contrôler le type d'affichage (true = URL complète, false = référence seulement) |
|
|
|
RxBool showFullUrl = true.obs; |
|
|
|
|
|
|
|
Get.dialog( |
|
|
|
Obx(() { |
|
|
|
// Données du QR code selon l'état |
|
|
|
final qrData = showFullUrl.value |
|
|
|
? 'https://stock.guycom.mg/${product.reference}' |
|
|
|
: product.reference!; |
|
|
|
|
|
|
|
return AlertDialog( |
|
|
|
title: Row( |
|
|
|
children: [ |
|
|
|
const Icon(Icons.qr_code_2, color: Colors.blue), |
|
|
|
@ -933,6 +942,28 @@ Widget _buildImportProgressIndicator() { |
|
|
|
child: Column( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
children: [ |
|
|
|
// Bouton pour basculer entre URL et référence |
|
|
|
ElevatedButton.icon( |
|
|
|
onPressed: () { |
|
|
|
showFullUrl.value = !showFullUrl.value; |
|
|
|
}, |
|
|
|
icon: Icon( |
|
|
|
showFullUrl.value ? Icons.link : Icons.tag, |
|
|
|
size: 16, |
|
|
|
), |
|
|
|
label: Text( |
|
|
|
showFullUrl.value ? 'URL/Référence' : 'Référence', |
|
|
|
style: const TextStyle(fontSize: 14), |
|
|
|
), |
|
|
|
style: ElevatedButton.styleFrom( |
|
|
|
backgroundColor: showFullUrl.value ? Colors.blue : Colors.green, |
|
|
|
foregroundColor: Colors.white, |
|
|
|
minimumSize: const Size(double.infinity, 36), |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
// Container du QR Code |
|
|
|
Container( |
|
|
|
padding: const EdgeInsets.all(16), |
|
|
|
decoration: BoxDecoration( |
|
|
|
@ -941,13 +972,15 @@ Widget _buildImportProgressIndicator() { |
|
|
|
border: Border.all(color: Colors.grey.shade300), |
|
|
|
), |
|
|
|
child: QrImageView( |
|
|
|
data: qrUrl, |
|
|
|
data: qrData, |
|
|
|
version: QrVersions.auto, |
|
|
|
size: 200, |
|
|
|
backgroundColor: Colors.white, |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
|
|
|
|
// Affichage des données actuelles |
|
|
|
Container( |
|
|
|
padding: const EdgeInsets.all(12), |
|
|
|
decoration: BoxDecoration( |
|
|
|
@ -957,12 +990,12 @@ Widget _buildImportProgressIndicator() { |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
'Référence: ${product.reference}', |
|
|
|
showFullUrl.value ? 'URL Complète' : 'Référence Seulement', |
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold), |
|
|
|
), |
|
|
|
const SizedBox(height: 4), |
|
|
|
Text( |
|
|
|
qrUrl, |
|
|
|
qrData, |
|
|
|
style: const TextStyle(fontSize: 12, color: Colors.grey), |
|
|
|
textAlign: TextAlign.center, |
|
|
|
), |
|
|
|
@ -975,25 +1008,64 @@ Widget _buildImportProgressIndicator() { |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
onPressed: () { |
|
|
|
Clipboard.setData(ClipboardData(text: qrUrl)); |
|
|
|
Clipboard.setData(ClipboardData(text: qrData)); |
|
|
|
Get.back(); |
|
|
|
Get.snackbar( |
|
|
|
'Copié', |
|
|
|
'URL copiée dans le presse-papiers', |
|
|
|
'Copié', |
|
|
|
'${showFullUrl.value ? "URL" : "Référence"} copiée dans le presse-papiers', |
|
|
|
backgroundColor: Colors.green, |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
}, |
|
|
|
child: const Text('Copier URL'), |
|
|
|
child: Text('Copier ${showFullUrl.value ? "URL" : "Référence"}'), |
|
|
|
), |
|
|
|
TextButton( |
|
|
|
onPressed: () => _generatePDF(product, qrData), |
|
|
|
child: const Text('Imprimer en PDF'), |
|
|
|
), |
|
|
|
TextButton( |
|
|
|
onPressed: () => Get.back(), |
|
|
|
child: const Text('Fermer'), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
); |
|
|
|
}), |
|
|
|
); |
|
|
|
} |
|
|
|
Future<void> _generatePDF(Product product, String qrUrl) async { |
|
|
|
final pdf = pw.Document(); |
|
|
|
|
|
|
|
pdf.addPage( |
|
|
|
pw.Page( |
|
|
|
build: (pw.Context context) { |
|
|
|
return pw.Center( |
|
|
|
child: pw.Column( |
|
|
|
children: [ |
|
|
|
pw.Text('QR Code - ${product.name}', style: pw.TextStyle(fontSize: 20)), |
|
|
|
pw.SizedBox(height: 20), |
|
|
|
pw.BarcodeWidget( |
|
|
|
barcode: pw.Barcode.qrCode(), |
|
|
|
data: qrUrl, |
|
|
|
width: 200, |
|
|
|
height: 200, |
|
|
|
), |
|
|
|
pw.SizedBox(height: 20), |
|
|
|
pw.Text('URL/Référence: $qrUrl', style: pw.TextStyle(fontSize: 12)), |
|
|
|
pw.SizedBox(height: 10), |
|
|
|
pw.Text('Référence: ${product.reference}', style: pw.TextStyle(fontSize: 12)), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
}, |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
final output = await getTemporaryDirectory(); |
|
|
|
final file = File("${output.path}/qrcode.pdf"); |
|
|
|
await file.writeAsBytes(await pdf.save()); |
|
|
|
|
|
|
|
OpenFile.open(file.path); |
|
|
|
} |
|
|
|
|
|
|
|
void _editProduct(Product product) { |
|
|
|
final nameController = TextEditingController(text: product.name); |
|
|
|
|