migliorato upload da mobile
This commit is contained in:
1 parent
8e396a7885
commit
89e5d4014d
10 files changed
+387
-93
No files matched your search
@@ -0,0 +1,49 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:image/image.dart' as img;
|
||||||
|
|
||||||
|
/// Utilità per la gestione delle immagini e normalizzazione dell'orientamento EXIF.
|
||||||
|
class ImageUtils {
|
||||||
|
/// Verifica se l'estensione corrisponde a un'immagine supportata.
|
||||||
|
static bool isImageExtension(String? extension) {
|
||||||
|
if (extension == null) return false;
|
||||||
|
final ext = extension.toLowerCase().replaceAll('.', '');
|
||||||
|
return ['jpg', 'jpeg', 'png', 'webp', 'bmp'].contains(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verifica se un nome file o percorso è un'immagine supportata.
|
||||||
|
static bool isImagePath(String path) {
|
||||||
|
final dotIndex = path.lastIndexOf('.');
|
||||||
|
if (dotIndex == -1 || dotIndex == path.length - 1) return false;
|
||||||
|
return isImageExtension(path.substring(dotIndex + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ruota fisicamente i pixel dell'immagine se contiene metadati EXIF di orientamento
|
||||||
|
/// (tipico delle fotocamere degli smartphone), resettando l'orientamento a 1 (normale).
|
||||||
|
/// Se l'immagine è già dritta o non possiede metadati EXIF, restituisce i byte originali.
|
||||||
|
static Uint8List normalizeOrientation(Uint8List bytes, {String? extension}) {
|
||||||
|
try {
|
||||||
|
final image = img.decodeImage(bytes);
|
||||||
|
if (image == null) return bytes;
|
||||||
|
|
||||||
|
// Se non ha tag di orientamento o è già orientata dritta (1)
|
||||||
|
if (!image.exif.imageIfd.hasOrientation || image.exif.imageIfd.orientation == 1) {
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Applica la rotazione fisica dei pixel e resetta il tag EXIF
|
||||||
|
final baked = img.bakeOrientation(image);
|
||||||
|
|
||||||
|
final ext = extension?.toLowerCase().replaceAll('.', '');
|
||||||
|
final isPng = ext == 'png' || (ext == null && image.hasAlpha);
|
||||||
|
|
||||||
|
if (isPng) {
|
||||||
|
return Uint8List.fromList(img.encodePng(baked));
|
||||||
|
} else {
|
||||||
|
return Uint8List.fromList(img.encodeJpg(baked, quality: 92));
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// In caso di errore di parsing/decodifica, restituisce i byte inalterati
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flux/core/utils/image_utils.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
|
|
||||||
part 'image_upload_state.dart';
|
part 'image_upload_state.dart';
|
||||||
@@ -18,9 +19,29 @@ class ImageUploadCubit extends Cubit<ImageUploadState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearFiles() {
|
||||||
|
emit(state.copyWith(status: ImageUploadStatus.initial, stagedFiles: []));
|
||||||
|
}
|
||||||
|
|
||||||
void addFiles(List<PlatformFile> files) {
|
void addFiles(List<PlatformFile> files) {
|
||||||
|
final List<PlatformFile> processedFiles = files.map((file) {
|
||||||
|
if (file.bytes != null && ImageUtils.isImagePath(file.name)) {
|
||||||
|
final normalizedBytes = ImageUtils.normalizeOrientation(
|
||||||
|
file.bytes!,
|
||||||
|
extension: file.extension,
|
||||||
|
);
|
||||||
|
return PlatformFile(
|
||||||
|
name: file.name,
|
||||||
|
size: normalizedBytes.length,
|
||||||
|
bytes: normalizedBytes,
|
||||||
|
path: file.path,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
List<PlatformFile> newFiles = List.from(state.stagedFiles);
|
List<PlatformFile> newFiles = List.from(state.stagedFiles);
|
||||||
newFiles.addAll(files);
|
newFiles.addAll(processedFiles);
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(status: ImageUploadStatus.success, stagedFiles: newFiles),
|
state.copyWith(status: ImageUploadStatus.success, stagedFiles: newFiles),
|
||||||
);
|
);
|
||||||
@@ -43,12 +64,19 @@ class ImageUploadCubit extends Cubit<ImageUploadState> {
|
|||||||
stagedFiles: files,
|
stagedFiles: files,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final rawBytes = await photo.readAsBytes();
|
||||||
|
final normalizedBytes = ImageUtils.normalizeOrientation(
|
||||||
|
rawBytes,
|
||||||
|
extension: 'jpg',
|
||||||
|
);
|
||||||
|
|
||||||
final List<PlatformFile> newFiles = List.from(files);
|
final List<PlatformFile> newFiles = List.from(files);
|
||||||
newFiles.removeLast();
|
newFiles.removeLast();
|
||||||
final PlatformFile loadedFile = PlatformFile(
|
final PlatformFile loadedFile = PlatformFile(
|
||||||
name: photo.name,
|
name: photo.name,
|
||||||
size: await photo.length(),
|
size: normalizedBytes.length,
|
||||||
bytes: await photo.readAsBytes(),
|
bytes: normalizedBytes,
|
||||||
path: photo.path,
|
path: photo.path,
|
||||||
);
|
);
|
||||||
newFiles.add(loadedFile);
|
newFiles.add(loadedFile);
|
||||||
|
|||||||
@@ -49,45 +49,77 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Upload: $title'),
|
title: Text(title),
|
||||||
automaticallyImplyLeading:
|
centerTitle: true,
|
||||||
state.status != ImageUploadStatus.uploading,
|
automaticallyImplyLeading: false,
|
||||||
),
|
),
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
// --- SEZIONE PULSANTI (Fotocamera / Galleria) ---
|
// --- BARRA SUPERIORE: ANNULLA / INVIA ---
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16.0,
|
||||||
|
vertical: 10.0,
|
||||||
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
// ANNULLA
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ElevatedButton.icon(
|
flex: 2,
|
||||||
onPressed:
|
child: SizedBox(
|
||||||
state.status == ImageUploadStatus.uploading
|
height: 48,
|
||||||
? null
|
|
||||||
: () => _handleCamera(context),
|
|
||||||
icon: const Icon(Icons.camera_alt),
|
|
||||||
label: const Text('SCATTA'),
|
|
||||||
style: ElevatedButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
onPressed:
|
onPressed:
|
||||||
state.status == ImageUploadStatus.uploading
|
state.status == ImageUploadStatus.uploading
|
||||||
? null
|
? null
|
||||||
: () => _handleFilePicker(context),
|
: () => _handleCancel(context),
|
||||||
icon: const Icon(Icons.folder),
|
icon: const Icon(Icons.close, size: 20),
|
||||||
label: const Text("GALLERIA"),
|
label: const Text(
|
||||||
|
'Annulla',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
padding: const EdgeInsets.symmetric(
|
foregroundColor: Colors.red.shade700,
|
||||||
vertical: 16,
|
side: BorderSide(color: Colors.red.shade300),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
// INVIA
|
||||||
|
Expanded(
|
||||||
|
flex: 3,
|
||||||
|
child: SizedBox(
|
||||||
|
height: 48,
|
||||||
|
child: FilledButton.icon(
|
||||||
|
onPressed:
|
||||||
|
state.stagedFiles.isEmpty ||
|
||||||
|
state.status ==
|
||||||
|
ImageUploadStatus.uploading
|
||||||
|
? null
|
||||||
|
: () => _submitAllFiles(context),
|
||||||
|
icon: const Icon(Icons.cloud_upload, size: 20),
|
||||||
|
label: Text(
|
||||||
|
state.stagedFiles.isEmpty
|
||||||
|
? 'Invia'
|
||||||
|
: 'Invia (${state.stagedFiles.length})',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
style: FilledButton.styleFrom(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -96,24 +128,49 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const Divider(),
|
const Divider(height: 1),
|
||||||
|
|
||||||
// --- SEZIONE ANTEPRIME (La GridView Magica) ---
|
// --- SEZIONE ANTEPRIME ---
|
||||||
Expanded(
|
Expanded(
|
||||||
child: state.stagedFiles.isEmpty
|
child: state.stagedFiles.isEmpty
|
||||||
? const Center(
|
? const Center(
|
||||||
child: Text(
|
child: Padding(
|
||||||
"Nessun file selezionato.\nScatta una foto o scegli dalla galleria.",
|
padding: EdgeInsets.all(24.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.add_photo_alternate_outlined,
|
||||||
|
size: 64,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
"Nessun file selezionato",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 17,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
"Tocca 'Scatta' o 'Galleria' in basso per aggiungere foto o documenti.",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(color: Colors.grey),
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: GridView.builder(
|
: GridView.builder(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount:
|
crossAxisCount: 3,
|
||||||
3, // 3 colonne stile galleria
|
|
||||||
crossAxisSpacing: 12,
|
crossAxisSpacing: 12,
|
||||||
mainAxisSpacing: 12,
|
mainAxisSpacing: 12,
|
||||||
),
|
),
|
||||||
@@ -145,7 +202,6 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
return Stack(
|
return Stack(
|
||||||
clipBehavior: Clip.none,
|
clipBehavior: Clip.none,
|
||||||
children: [
|
children: [
|
||||||
// L'ANTEPRIMA
|
|
||||||
Container(
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
@@ -159,19 +215,10 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: isImg
|
child: isImg
|
||||||
? (file.bytes != null
|
|
||||||
// Se abbiamo i bytes (es. scatto da fotocamera) usiamo quelli (a prova di Web!)
|
|
||||||
? Image.memory(
|
? Image.memory(
|
||||||
file.bytes!,
|
file.bytes!,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
)
|
)
|
||||||
// Altrimenti andiamo di file fisico
|
|
||||||
: const Center(
|
|
||||||
child:
|
|
||||||
CircularProgressIndicator(
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
))
|
|
||||||
: const Column(
|
: const Column(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
MainAxisAlignment.center,
|
MainAxisAlignment.center,
|
||||||
@@ -194,11 +241,9 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// IL PULSANTE CESTINO (In alto a destra)
|
|
||||||
Positioned(
|
Positioned(
|
||||||
top: -8,
|
top: -6,
|
||||||
right: -8,
|
right: -6,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () => context
|
onTap: () => context
|
||||||
.read<ImageUploadCubit>()
|
.read<ImageUploadCubit>()
|
||||||
@@ -222,35 +267,77 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// --- SEZIONE INVIA E CHIUDI ---
|
|
||||||
|
// --- SEZIONE INFERIORE (A portata di pollice: Scatta e Galleria) ---
|
||||||
SafeArea(
|
SafeArea(
|
||||||
child: Padding(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 16.0,
|
||||||
|
vertical: 12.0,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.06),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: const Offset(0, -2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
// SCATTA
|
||||||
|
Expanded(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
|
||||||
height: 56,
|
height: 56,
|
||||||
child: ElevatedButton.icon(
|
child: FilledButton.icon(
|
||||||
// Il pulsante si accende SOLO se ci sono file nel carrello
|
|
||||||
onPressed:
|
onPressed:
|
||||||
state.stagedFiles.isEmpty ||
|
state.status ==
|
||||||
state.status == ImageUploadStatus.uploading
|
ImageUploadStatus.uploading
|
||||||
? null
|
? null
|
||||||
: () => _submitAllFiles(context),
|
: () => _handleCamera(context),
|
||||||
icon: const Icon(Icons.cloud_upload),
|
icon: const Icon(Icons.camera_alt, size: 24),
|
||||||
label: Text(
|
label: const Text(
|
||||||
"INVIA ${state.stagedFiles.length} FILE E CHIUDI",
|
'Scatta',
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
style: ElevatedButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: Theme.of(
|
shape: RoundedRectangleBorder(
|
||||||
context,
|
borderRadius: BorderRadius.circular(16),
|
||||||
).colorScheme.primary,
|
),
|
||||||
foregroundColor: Theme.of(
|
),
|
||||||
context,
|
),
|
||||||
).colorScheme.onPrimary,
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
// GALLERIA
|
||||||
|
Expanded(
|
||||||
|
child: SizedBox(
|
||||||
|
height: 56,
|
||||||
|
child: OutlinedButton.icon(
|
||||||
|
onPressed:
|
||||||
|
state.status ==
|
||||||
|
ImageUploadStatus.uploading
|
||||||
|
? null
|
||||||
|
: () => _handleFilePicker(context),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.photo_library,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
label: const Text(
|
||||||
|
'Galleria',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -258,6 +345,35 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (state.status == ImageUploadStatus.uploading)
|
||||||
|
Container(
|
||||||
|
color: Colors.black45,
|
||||||
|
child: const Center(
|
||||||
|
child: Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(24.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
CircularProgressIndicator(),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Caricamento in corso...',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -266,6 +382,40 @@ class ImageUploadScreen extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleCancel(BuildContext context) {
|
||||||
|
final cubit = context.read<ImageUploadCubit>();
|
||||||
|
if (cubit.state.stagedFiles.isNotEmpty) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => AlertDialog(
|
||||||
|
title: const Text('Annullare caricamento?'),
|
||||||
|
content: const Text('I file selezionati verranno rimossi.'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx),
|
||||||
|
child: const Text('No, continua'),
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
cubit.clearFiles();
|
||||||
|
if (Navigator.of(context).canPop()) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Sì, annulla'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (Navigator.of(context).canPop()) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- LOGICA FOTOCAMERA E LIBRERIA ---
|
// --- LOGICA FOTOCAMERA E LIBRERIA ---
|
||||||
Future<void> _handleCamera(BuildContext context) async {
|
Future<void> _handleCamera(BuildContext context) async {
|
||||||
final ImageUploadCubit imageUploadCubit = context.read<ImageUploadCubit>();
|
final ImageUploadCubit imageUploadCubit = context.read<ImageUploadCubit>();
|
||||||
|
|||||||
@@ -43,6 +43,21 @@ class UploadSuccessScreen extends StatelessWidget {
|
|||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(fontSize: 16, color: Colors.black54),
|
style: TextStyle(fontSize: 16, color: Colors.black54),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
if (Navigator.of(context).canPop())
|
||||||
|
OutlinedButton.icon(
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
icon: const Icon(Icons.add_photo_alternate),
|
||||||
|
label: const Text('Carica altri file per questa pratica'),
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
foregroundColor: Colors.green.shade800,
|
||||||
|
side: BorderSide(color: Colors.green.shade600),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 20,
|
||||||
|
vertical: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:flux/core/utils/extensions.dart';
|
|||||||
import 'package:flux/features/attachments/blocs/attachments_bloc.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 StatefulWidget {
|
||||||
final String deepLinkUrl;
|
final String deepLinkUrl;
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
@@ -14,20 +14,33 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
required this.title,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Usiamo i colori del tema per renderlo coerente col tuo design
|
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
return BlocConsumer<AttachmentsBloc, AttachmentsState>(
|
return BlocConsumer<AttachmentsBloc, AttachmentsState>(
|
||||||
listenWhen: (previous, current) =>
|
listenWhen: (previous, current) =>
|
||||||
previous.allFiles.length < current.allFiles.length,
|
current.allFiles.length > previous.allFiles.length,
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
final newCount = state.allFiles.length;
|
final sessionReceived = (state.allFiles.length - _initialFileCount).clamp(0, 99999);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
'File caricato con successo via QR Code! 📄 ($newCount allegati in totale)',
|
'Nuovo file ricevuto via QR Code! 📄 ($sessionReceived in questa sessione)',
|
||||||
),
|
),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
backgroundColor: Colors.green.shade700,
|
backgroundColor: Colors.green.shade700,
|
||||||
@@ -35,7 +48,7 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final fileCount = state.allFiles.length;
|
final sessionReceived = (state.allFiles.length - _initialFileCount).clamp(0, 99999);
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
@@ -51,7 +64,7 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Text(
|
Text(
|
||||||
title,
|
widget.title,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
@@ -62,7 +75,7 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
width: 350,
|
width: 350,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min, // Fondamentale per i dialog
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text(
|
||||||
"Inquadra questo codice con la fotocamera del tuo telefono per scattare e caricare i documenti direttamente qui.",
|
"Inquadra questo codice con la fotocamera del tuo telefono per scattare e caricare i documenti direttamente qui.",
|
||||||
@@ -73,12 +86,11 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors
|
color: Colors.white,
|
||||||
.white, // Lo sfondo bianco salva la vita sui temi scuri
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
),
|
),
|
||||||
child: QrImageView(
|
child: QrImageView(
|
||||||
data: deepLinkUrl,
|
data: widget.deepLinkUrl,
|
||||||
version: QrVersions.auto,
|
version: QrVersions.auto,
|
||||||
size: 200.0,
|
size: 200.0,
|
||||||
embeddedImage: const AssetImage(
|
embeddedImage: const AssetImage(
|
||||||
@@ -94,31 +106,38 @@ class QrUploadDialog extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
fileCount > 0
|
sessionReceived > 0
|
||||||
? Icons.check_circle_outline
|
? Icons.check_circle_outline
|
||||||
: Icons.hourglass_empty,
|
: Icons.hourglass_empty,
|
||||||
size: 18,
|
size: 18,
|
||||||
color: fileCount > 0
|
color: sessionReceived > 0
|
||||||
? Colors.green
|
? Colors.green
|
||||||
: theme.colorScheme.primary,
|
: theme.colorScheme.primary,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
fileCount > 0
|
sessionReceived > 0
|
||||||
? "$fileCount file ricevuti! (In ascolto...)"
|
? "$sessionReceived file ricevuti! (In ascolto...)"
|
||||||
: "In attesa di file...",
|
: "In attesa di file...",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: fileCount > 0
|
color: sessionReceived > 0
|
||||||
? Colors.green
|
? Colors.green
|
||||||
: theme.colorScheme.primary,
|
: 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 SizedBox(height: 8),
|
||||||
const LinearProgressIndicator(), // Per far capire che è "in ascolto"
|
const LinearProgressIndicator(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
import 'package:pdf/widgets.dart' as pw;
|
import 'package:pdf/widgets.dart' as pw;
|
||||||
|
import 'package:flux/core/utils/image_utils.dart';
|
||||||
import 'package:pdfrx/pdfrx.dart' as pdfrx;
|
import 'package:pdfrx/pdfrx.dart' as pdfrx;
|
||||||
|
|
||||||
class _ExportItem {
|
class _ExportItem {
|
||||||
@@ -377,8 +378,12 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
|
|||||||
}
|
}
|
||||||
await document.dispose();
|
await document.dispose();
|
||||||
} else {
|
} else {
|
||||||
// È un'immagine
|
// È un'immagine: normalizziamo l'orientamento EXIF per il PDF
|
||||||
allPagesAsImages.add(fileBytes);
|
final safeBytes = ImageUtils.normalizeOrientation(
|
||||||
|
fileBytes,
|
||||||
|
extension: file.extension,
|
||||||
|
);
|
||||||
|
allPagesAsImages.add(safeBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,10 +536,14 @@ class _SharedAttachmentsSectionState extends State<SharedAttachmentsSection> {
|
|||||||
}
|
}
|
||||||
await document.dispose();
|
await document.dispose();
|
||||||
} else {
|
} else {
|
||||||
// SE È UN'IMMAGINE, la salviamo come singola pagina
|
// SE È UN'IMMAGINE, la salviamo normalizzando l'orientamento
|
||||||
|
final safeBytes = ImageUtils.normalizeOrientation(
|
||||||
|
fileBytes,
|
||||||
|
extension: file.extension,
|
||||||
|
);
|
||||||
itemsToExport.add(
|
itemsToExport.add(
|
||||||
_ExportItem(
|
_ExportItem(
|
||||||
bytes: fileBytes,
|
bytes: safeBytes,
|
||||||
sourceName: baseName,
|
sourceName: baseName,
|
||||||
isMultiPage: false,
|
isMultiPage: false,
|
||||||
pageIndex: 1,
|
pageIndex: 1,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flux/core/utils/functions.dart';
|
import 'package:flux/core/utils/functions.dart';
|
||||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||||
|
import 'package:flux/core/utils/image_utils.dart';
|
||||||
import 'package:pdfrx/pdfrx.dart';
|
import 'package:pdfrx/pdfrx.dart';
|
||||||
import 'package:internet_file/internet_file.dart';
|
import 'package:internet_file/internet_file.dart';
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
|
|||||||
String? _errorMessage;
|
String? _errorMessage;
|
||||||
Uint8List? _fileBytes;
|
Uint8List? _fileBytes;
|
||||||
int _loadToken = 0;
|
int _loadToken = 0;
|
||||||
|
int _rotationTurns = 0;
|
||||||
|
|
||||||
AttachmentModel get _currentAttachment => _items[_currentIndex];
|
AttachmentModel get _currentAttachment => _items[_currentIndex];
|
||||||
bool get isPdf =>
|
bool get isPdf =>
|
||||||
@@ -95,6 +97,7 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
|
|||||||
_isLoading = true;
|
_isLoading = true;
|
||||||
_errorMessage = null;
|
_errorMessage = null;
|
||||||
_fileBytes = null;
|
_fileBytes = null;
|
||||||
|
_rotationTurns = 0;
|
||||||
});
|
});
|
||||||
_loadFile();
|
_loadFile();
|
||||||
}
|
}
|
||||||
@@ -134,6 +137,10 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
|
|||||||
|
|
||||||
if (token != _loadToken || !mounted) return;
|
if (token != _loadToken || !mounted) return;
|
||||||
|
|
||||||
|
if (bytes != null && !isPdf) {
|
||||||
|
bytes = ImageUtils.normalizeOrientation(bytes, extension: item.extension);
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_fileBytes = bytes;
|
_fileBytes = bytes;
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
@@ -269,6 +276,16 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
if (!isPdf)
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.rotate_right),
|
||||||
|
tooltip: 'Ruota',
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_rotationTurns = (_rotationTurns + 1) % 4;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
if (widget.onRename != null || widget.onRenameAttachment != null)
|
if (widget.onRename != null || widget.onRenameAttachment != null)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.edit),
|
icon: const Icon(Icons.edit),
|
||||||
@@ -357,7 +374,12 @@ class _AttachmentViewerScreenState extends State<AttachmentViewerScreen> {
|
|||||||
} else {
|
} else {
|
||||||
return InteractiveViewer(
|
return InteractiveViewer(
|
||||||
maxScale: 5.0,
|
maxScale: 5.0,
|
||||||
child: Center(child: Image.memory(_fileBytes!)),
|
child: Center(
|
||||||
|
child: RotatedBox(
|
||||||
|
quarterTurns: _rotationTurns,
|
||||||
|
child: Image.memory(_fileBytes!),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -494,7 +494,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "4.1.2"
|
version: "4.1.2"
|
||||||
image:
|
image:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: image
|
name: image
|
||||||
sha256: a1e7f4951e538a568e14b856702afc9ae1d2f4b202daced8d22c1b9cd211ce89
|
sha256: a1e7f4951e538a568e14b856702afc9ae1d2f4b202daced8d22c1b9cd211ce89
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,7 @@
|
|||||||
name: flux
|
name: flux
|
||||||
description: "Gestione attività negozio di telefonia"
|
description: "Gestione attività negozio di telefonia"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 2.0.16+72
|
version: 2.0.17+73
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.11.3
|
sdk: ^3.11.3
|
||||||
@@ -23,6 +23,7 @@ dependencies:
|
|||||||
go_router: ^17.2.0
|
go_router: ^17.2.0
|
||||||
google_fonts: ^8.0.2
|
google_fonts: ^8.0.2
|
||||||
image_picker: ^1.2.1
|
image_picker: ^1.2.1
|
||||||
|
image: ^4.10.1
|
||||||
internet_file: ^1.3.0
|
internet_file: ^1.3.0
|
||||||
intl: ^0.20.2
|
intl: ^0.20.2
|
||||||
permission_handler: ^12.0.1
|
permission_handler: ^12.0.1
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
<base href="$FLUTTER_BASE_HREF">
|
<base href="$FLUTTER_BASE_HREF">
|
||||||
|
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
||||||
<meta name="description" content="Gestione attività negozio di telefonia">
|
<meta name="description" content="Gestione attività negozio di telefonia">
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user