Refactor QrUploadDialog to integrate BlocListener for attachment state management
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flux/core/utils/extensions.dart';
|
import 'package:flux/core/utils/extensions.dart';
|
||||||
|
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||||
import 'package:qr_flutter/qr_flutter.dart';
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
|
|
||||||
class QrUploadDialog extends StatelessWidget {
|
class QrUploadDialog extends StatelessWidget {
|
||||||
@@ -17,77 +19,85 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
// Usiamo i colori del tema per renderlo coerente col tuo design
|
// Usiamo i colori del tema per renderlo coerente col tuo design
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return AlertDialog(
|
return BlocListener<AttachmentsBloc, AttachmentsState>(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
listener: (context, state) {
|
||||||
backgroundColor: theme.colorScheme.surface,
|
if (state.status == AttachmentsStatus.success) {
|
||||||
title: Column(
|
Navigator.of(context).pop();
|
||||||
children: [
|
}
|
||||||
Icon(
|
},
|
||||||
Icons.qr_code_scanner,
|
listenWhen: (previous, current) => previous.status != current.status,
|
||||||
size: 48,
|
child: AlertDialog(
|
||||||
color: theme.colorScheme.primary,
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
),
|
backgroundColor: theme.colorScheme.surface,
|
||||||
const SizedBox(height: 16),
|
title: Column(
|
||||||
Text(
|
children: [
|
||||||
title,
|
Icon(
|
||||||
textAlign: TextAlign.center,
|
Icons.qr_code_scanner,
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
size: 48,
|
||||||
),
|
color: theme.colorScheme.primary,
|
||||||
],
|
),
|
||||||
),
|
const SizedBox(height: 16),
|
||||||
content: SizedBox(
|
Text(
|
||||||
height: 400,
|
title,
|
||||||
width: 350,
|
textAlign: TextAlign.center,
|
||||||
child: SingleChildScrollView(
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
child: Column(
|
),
|
||||||
mainAxisSize: MainAxisSize.min, // Fondamentale per i dialog
|
],
|
||||||
children: [
|
),
|
||||||
const Text(
|
content: SizedBox(
|
||||||
"Inquadra questo codice con la fotocamera del tuo telefono per scattare e caricare i documenti direttamente qui.",
|
height: 400,
|
||||||
textAlign: TextAlign.center,
|
width: 350,
|
||||||
style: TextStyle(fontSize: 14, color: Colors.grey),
|
child: SingleChildScrollView(
|
||||||
),
|
child: Column(
|
||||||
const SizedBox(height: 24),
|
mainAxisSize: MainAxisSize.min, // Fondamentale per i dialog
|
||||||
Container(
|
children: [
|
||||||
padding: const EdgeInsets.all(16),
|
const Text(
|
||||||
decoration: BoxDecoration(
|
"Inquadra questo codice con la fotocamera del tuo telefono per scattare e caricare i documenti direttamente qui.",
|
||||||
color: Colors
|
textAlign: TextAlign.center,
|
||||||
.white, // Lo sfondo bianco salva la vita sui temi scuri
|
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
),
|
||||||
child: QrImageView(
|
const SizedBox(height: 24),
|
||||||
data: deepLinkUrl,
|
Container(
|
||||||
version: QrVersions.auto,
|
padding: const EdgeInsets.all(16),
|
||||||
size: 200.0,
|
decoration: BoxDecoration(
|
||||||
//Opzionale: puoi metterci il logo di FLUX in mezzo!
|
color: Colors
|
||||||
embeddedImage: const AssetImage('assets/images/logo.png'),
|
.white, // Lo sfondo bianco salva la vita sui temi scuri
|
||||||
embeddedImageStyle: const QrEmbeddedImageStyle(
|
borderRadius: BorderRadius.circular(16),
|
||||||
size: Size(40, 40),
|
),
|
||||||
|
child: QrImageView(
|
||||||
|
data: deepLinkUrl,
|
||||||
|
version: QrVersions.auto,
|
||||||
|
size: 200.0,
|
||||||
|
//Opzionale: puoi metterci il logo di FLUX in mezzo!
|
||||||
|
embeddedImage: const AssetImage('assets/images/logo.png'),
|
||||||
|
embeddedImageStyle: const QrEmbeddedImageStyle(
|
||||||
|
size: Size(40, 40),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 16),
|
||||||
const SizedBox(height: 16),
|
Text(
|
||||||
Text(
|
"In attesa di file...",
|
||||||
"In attesa di file...",
|
style: TextStyle(
|
||||||
style: TextStyle(
|
fontSize: 12,
|
||||||
fontSize: 12,
|
fontWeight: FontWeight.bold,
|
||||||
fontWeight: FontWeight.bold,
|
color: theme.colorScheme.primary,
|
||||||
color: theme.colorScheme.primary,
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 8),
|
||||||
const SizedBox(height: 8),
|
const LinearProgressIndicator(), // Per far capire che è "in ascolto"
|
||||||
const LinearProgressIndicator(), // Per far capire che è "in ascolto"
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
child: Text(context.l10n.commonClose),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
actionsAlignment: MainAxisAlignment.center,
|
||||||
),
|
),
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
child: Text(context.l10n.commonClose),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
actionsAlignment: MainAxisAlignment.center,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user