157 lines
5.5 KiB
Dart
157 lines
5.5 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flux/core/utils/extensions.dart';
|
|
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
class QrUploadDialog extends StatefulWidget {
|
|
final String deepLinkUrl;
|
|
final String title;
|
|
|
|
const QrUploadDialog({
|
|
super.key,
|
|
required this.deepLinkUrl,
|
|
required this.title,
|
|
});
|
|
|
|
@override
|
|
State<QrUploadDialog> createState() => _QrUploadDialogState();
|
|
}
|
|
|
|
class _QrUploadDialogState extends State<QrUploadDialog> {
|
|
int _initialFileCount = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Memorizziamo quanti file c'erano al momento dell'apertura per contare solo i nuovi ricevuti
|
|
_initialFileCount = context.read<AttachmentsBloc>().state.allFiles.length;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
return BlocConsumer<AttachmentsBloc, AttachmentsState>(
|
|
listenWhen: (previous, current) =>
|
|
current.allFiles.length > previous.allFiles.length,
|
|
listener: (context, state) {
|
|
final sessionReceived = (state.allFiles.length - _initialFileCount).clamp(0, 99999);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
'Nuovo file ricevuto via QR Code! 📄 ($sessionReceived in questa sessione)',
|
|
),
|
|
duration: const Duration(seconds: 2),
|
|
backgroundColor: Colors.green.shade700,
|
|
),
|
|
);
|
|
},
|
|
builder: (context, state) {
|
|
final sessionReceived = (state.allFiles.length - _initialFileCount).clamp(0, 99999);
|
|
|
|
return AlertDialog(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
backgroundColor: theme.colorScheme.surface,
|
|
title: Column(
|
|
children: [
|
|
Icon(
|
|
Icons.qr_code_scanner,
|
|
size: 48,
|
|
color: theme.colorScheme.primary,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
widget.title,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
],
|
|
),
|
|
content: SizedBox(
|
|
height: 400,
|
|
width: 350,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text(
|
|
"Inquadra questo codice con la fotocamera del tuo telefono per scattare e caricare i documenti direttamente qui.",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 14, color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: QrImageView(
|
|
data: widget.deepLinkUrl,
|
|
version: QrVersions.auto,
|
|
size: 200.0,
|
|
embeddedImage: const AssetImage(
|
|
'assets/images/logo.png',
|
|
),
|
|
embeddedImageStyle: const QrEmbeddedImageStyle(
|
|
size: Size(40, 40),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
sessionReceived > 0
|
|
? Icons.check_circle_outline
|
|
: Icons.hourglass_empty,
|
|
size: 18,
|
|
color: sessionReceived > 0
|
|
? Colors.green
|
|
: theme.colorScheme.primary,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
sessionReceived > 0
|
|
? "$sessionReceived file ricevuti! (In ascolto...)"
|
|
: "In attesa di file...",
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.bold,
|
|
color: sessionReceived > 0
|
|
? Colors.green
|
|
: theme.colorScheme.primary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (_initialFileCount > 0 && sessionReceived == 0) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
"($_initialFileCount file già presenti nella pratica)",
|
|
style: const TextStyle(fontSize: 11, color: Colors.grey),
|
|
),
|
|
],
|
|
const SizedBox(height: 8),
|
|
const LinearProgressIndicator(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text(context.l10n.commonClose),
|
|
),
|
|
],
|
|
actionsAlignment: MainAxisAlignment.center,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|