changed image upload screen from mobile upload screen
This commit is contained in:
60
lib/core/widgets/image_upload/blocs/image_upload_cubit.dart
Normal file
60
lib/core/widgets/image_upload/blocs/image_upload_cubit.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
part 'image_upload_state.dart';
|
||||
|
||||
class ImageUploadCubit extends Cubit<ImageUploadState> {
|
||||
ImageUploadCubit() : super(const ImageUploadState());
|
||||
|
||||
void setStatus(ImageUploadStatus status) {
|
||||
emit(state.copyWith(status: status));
|
||||
}
|
||||
|
||||
void setError(String? message) {
|
||||
emit(
|
||||
state.copyWith(status: ImageUploadStatus.failure, errorMessage: message),
|
||||
);
|
||||
}
|
||||
|
||||
void addFiles(List<PlatformFile> files) {
|
||||
List<PlatformFile> newFiles = List.from(state.stagedFiles);
|
||||
newFiles.addAll(files);
|
||||
emit(
|
||||
state.copyWith(status: ImageUploadStatus.success, stagedFiles: newFiles),
|
||||
);
|
||||
}
|
||||
|
||||
void removeFile(PlatformFile file) {
|
||||
List<PlatformFile> newFiles = List.from(state.stagedFiles);
|
||||
newFiles.remove(file);
|
||||
emit(
|
||||
state.copyWith(status: ImageUploadStatus.success, stagedFiles: newFiles),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> addPhoto(XFile photo) async {
|
||||
final List<PlatformFile> files = List.from(state.stagedFiles);
|
||||
files.add(PlatformFile(name: photo.name, size: 0));
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ImageUploadStatus.addingPicture,
|
||||
stagedFiles: files,
|
||||
),
|
||||
);
|
||||
final List<PlatformFile> newFiles = List.from(files);
|
||||
newFiles.removeLast();
|
||||
final PlatformFile loadedFile = PlatformFile(
|
||||
name: photo.name,
|
||||
size: await photo.length(),
|
||||
bytes: await photo.readAsBytes(),
|
||||
path: photo.path,
|
||||
);
|
||||
newFiles.add(loadedFile);
|
||||
|
||||
emit(
|
||||
state.copyWith(status: ImageUploadStatus.success, stagedFiles: newFiles),
|
||||
);
|
||||
}
|
||||
}
|
||||
29
lib/core/widgets/image_upload/blocs/image_upload_state.dart
Normal file
29
lib/core/widgets/image_upload/blocs/image_upload_state.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
part of 'image_upload_cubit.dart';
|
||||
|
||||
enum ImageUploadStatus { initial, addingPicture, uploading, success, failure }
|
||||
|
||||
class ImageUploadState extends Equatable {
|
||||
final ImageUploadStatus status;
|
||||
final String? errorMessage;
|
||||
final List<PlatformFile> stagedFiles;
|
||||
|
||||
const ImageUploadState({
|
||||
this.status = ImageUploadStatus.initial,
|
||||
this.errorMessage,
|
||||
this.stagedFiles = const [],
|
||||
});
|
||||
ImageUploadState copyWith({
|
||||
ImageUploadStatus? status,
|
||||
String? errorMessage,
|
||||
List<PlatformFile>? stagedFiles,
|
||||
}) {
|
||||
return ImageUploadState(
|
||||
status: status ?? this.status,
|
||||
errorMessage: errorMessage,
|
||||
stagedFiles: stagedFiles ?? this.stagedFiles,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, errorMessage, stagedFiles];
|
||||
}
|
||||
306
lib/core/widgets/image_upload/ui/image_upload_screen.dart
Normal file
306
lib/core/widgets/image_upload/ui/image_upload_screen.dart
Normal file
@@ -0,0 +1,306 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/core/widgets/image_upload/blocs/image_upload_cubit.dart';
|
||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class ImageUploadScreen extends StatelessWidget {
|
||||
final String title;
|
||||
final String companyId;
|
||||
|
||||
const ImageUploadScreen({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.companyId,
|
||||
});
|
||||
|
||||
bool _isImage(String path) {
|
||||
return ['jpg', 'jpeg', 'png', 'webp'].contains(path.fileExtension());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ImageUploadCubit, ImageUploadState>(
|
||||
builder: (context, state) {
|
||||
return BlocListener<AttachmentsBloc, AttachmentsState>(
|
||||
listener: (context, attachmentState) {
|
||||
if (attachmentState.status == AttachmentsStatus.success &&
|
||||
state.status == ImageUploadStatus.uploading) {
|
||||
if (Navigator.of(context).canPop()) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("File caricati con successo! ✅"),
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
context.go('/upload-success');
|
||||
}
|
||||
}
|
||||
if (attachmentState.status == AttachmentsStatus.failure) {
|
||||
context.read<ImageUploadCubit>().setError(attachmentState.error);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Errore: ${state.errorMessage}")),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Upload: $title'),
|
||||
automaticallyImplyLeading:
|
||||
state.status != ImageUploadStatus.uploading,
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
// --- SEZIONE PULSANTI (Fotocamera / Galleria) ---
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed:
|
||||
state.status == ImageUploadStatus.uploading
|
||||
? 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(
|
||||
onPressed:
|
||||
state.status == ImageUploadStatus.uploading
|
||||
? null
|
||||
: () => _handleFilePicker(context),
|
||||
icon: const Icon(Icons.folder),
|
||||
label: const Text("GALLERIA"),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
// --- SEZIONE ANTEPRIME (La GridView Magica) ---
|
||||
Expanded(
|
||||
child: state.stagedFiles.isEmpty
|
||||
? const Center(
|
||||
child: Text(
|
||||
"Nessun file selezionato.\nScatta una foto o scegli dalla galleria.",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
)
|
||||
: GridView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount:
|
||||
3, // 3 colonne stile galleria
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: state.stagedFiles.length,
|
||||
itemBuilder: (context, index) {
|
||||
final file = state.stagedFiles[index];
|
||||
final isImg = _isImage(file.name);
|
||||
if (file.bytes == null) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
// L'ANTEPRIMA
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: isImg
|
||||
? (file.bytes != null
|
||||
// Se abbiamo i bytes (es. scatto da fotocamera) usiamo quelli (a prova di Web!)
|
||||
? Image.memory(
|
||||
file.bytes!,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
// Altrimenti andiamo di file fisico
|
||||
: const Center(
|
||||
child:
|
||||
CircularProgressIndicator(
|
||||
color: Colors.blue,
|
||||
),
|
||||
))
|
||||
: const Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.picture_as_pdf,
|
||||
color: Colors.red,
|
||||
size: 36,
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
"PDF",
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// IL PULSANTE CESTINO (In alto a destra)
|
||||
Positioned(
|
||||
top: -8,
|
||||
right: -8,
|
||||
child: GestureDetector(
|
||||
onTap: () => context
|
||||
.read<ImageUploadCubit>()
|
||||
.removeFile(file),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.red,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
// --- SEZIONE INVIA E CHIUDI ---
|
||||
SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
child: ElevatedButton.icon(
|
||||
// Il pulsante si accende SOLO se ci sono file nel carrello
|
||||
onPressed:
|
||||
state.stagedFiles.isEmpty ||
|
||||
state.status == ImageUploadStatus.uploading
|
||||
? null
|
||||
: () => _submitAllFiles(context),
|
||||
icon: const Icon(Icons.cloud_upload),
|
||||
label: Text(
|
||||
"INVIA ${state.stagedFiles.length} FILE E CHIUDI",
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary,
|
||||
foregroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.onPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// --- LOGICA FOTOCAMERA E LIBRERIA ---
|
||||
Future<void> _handleCamera(BuildContext context) async {
|
||||
final ImageUploadCubit imageUploadCubit = context.read<ImageUploadCubit>();
|
||||
|
||||
final picker = ImagePicker();
|
||||
final photo = await picker.pickImage(source: ImageSource.camera);
|
||||
|
||||
if (photo != null) {
|
||||
imageUploadCubit.addPhoto(photo);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleFilePicker(BuildContext context) async {
|
||||
final ImageUploadCubit imageUploadCubit = context.read<ImageUploadCubit>();
|
||||
final result = await FilePicker.pickFiles(
|
||||
allowMultiple: true,
|
||||
withData: true,
|
||||
);
|
||||
if (result != null) {
|
||||
imageUploadCubit.addFiles(result.files);
|
||||
}
|
||||
}
|
||||
|
||||
// --- LOGICA DI INVIO AL BLoC ---
|
||||
void _submitAllFiles(BuildContext context) {
|
||||
final ImageUploadCubit imageUploadCubit = context.read<ImageUploadCubit>();
|
||||
|
||||
imageUploadCubit.setStatus(ImageUploadStatus.uploading);
|
||||
|
||||
// Lanciamo l'evento del nostro nuovo AttachmentsBloc Agnostico!
|
||||
context.read<AttachmentsBloc>().add(
|
||||
UploadAttachmentsEvent(
|
||||
pickedFiles: imageUploadCubit.state.stagedFiles,
|
||||
companyId: companyId,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
328
lib/core/widgets/image_upload/ui/old_image_upload_screen.dart
Normal file
328
lib/core/widgets/image_upload/ui/old_image_upload_screen.dart
Normal file
@@ -0,0 +1,328 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
|
||||
class OldSharedUploadScreen extends StatefulWidget {
|
||||
final String title;
|
||||
final String companyId;
|
||||
|
||||
const OldSharedUploadScreen({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.companyId,
|
||||
});
|
||||
|
||||
@override
|
||||
State<OldSharedUploadScreen> createState() => _OldSharedUploadScreenState();
|
||||
}
|
||||
|
||||
class _OldSharedUploadScreenState extends State<OldSharedUploadScreen> {
|
||||
// 1. LA NOSTRA STAGING AREA (Il "Carrello")
|
||||
final List<PlatformFile> _stagedFiles = [];
|
||||
|
||||
// 2. STATO DI CARICAMENTO GLOBALE
|
||||
bool _isUploading = false;
|
||||
bool _isProcessingLocal = false;
|
||||
|
||||
// Funzione magica per capire se è un'immagine o un PDF dall'estensione
|
||||
bool _isImage(String path) {
|
||||
final ext = path.split('.').last.toLowerCase();
|
||||
return ['jpg', 'jpeg', 'png', 'webp'].contains(ext);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<AttachmentsBloc, AttachmentsState>(
|
||||
listener: (context, state) {
|
||||
// Quando il BLoC ci dice che ha finito l'upload (Success), chiudiamo la pagina!
|
||||
if (state.status == AttachmentsStatus.success && _isUploading) {
|
||||
// CONTROLLO MAGICO: C'è una pagina dietro di noi?
|
||||
if (Navigator.of(context).canPop()) {
|
||||
// Modalità "App Nativa": siamo entrati dal tasto "Aggiungi"
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("File caricati con successo! ✅")),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
// Modalità "Web/QR Code": Navighiamo alla pagina di successo!
|
||||
// Assicurati di aver importato go_router in questo file
|
||||
|
||||
context.go('/upload-success');
|
||||
}
|
||||
}
|
||||
if (state.status == AttachmentsStatus.failure) {
|
||||
setState(() => _isUploading = false);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text("Errore: ${state.error}")));
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Upload: ${widget.title}"),
|
||||
// Togliamo la freccia indietro se stiamo caricando per evitare macelli
|
||||
automaticallyImplyLeading: !_isUploading,
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
// --- SEZIONE PULSANTI (Fotocamera / Galleria) ---
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: _isUploading ? null : _handleCamera,
|
||||
icon: const Icon(Icons.camera_alt),
|
||||
label: const Text("SCATTA"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _isUploading ? null : _handleFilePicker,
|
||||
icon: const Icon(Icons.folder),
|
||||
label: const Text("GALLERIA"),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
// --- SEZIONE ANTEPRIME (La GridView Magica) ---
|
||||
Expanded(
|
||||
child: _stagedFiles.isEmpty
|
||||
? const Center(
|
||||
child: Text(
|
||||
"Nessun file selezionato.\nScatta una foto o scegli dalla galleria.",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
)
|
||||
: GridView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3, // 3 colonne stile galleria
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: _stagedFiles.length,
|
||||
itemBuilder: (context, index) {
|
||||
final file = _stagedFiles[index];
|
||||
final isImg = _isImage(file.name);
|
||||
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
// L'ANTEPRIMA
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade200,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade300,
|
||||
),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: isImg
|
||||
? (file.bytes != null
|
||||
// Se abbiamo i bytes (es. scatto da fotocamera) usiamo quelli (a prova di Web!)
|
||||
? Image.memory(
|
||||
file.bytes!,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
// Altrimenti andiamo di file fisico
|
||||
: Image.file(
|
||||
File(file.path!),
|
||||
fit: BoxFit.cover,
|
||||
))
|
||||
: const Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.picture_as_pdf,
|
||||
color: Colors.red,
|
||||
size: 36,
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
"PDF",
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// IL PULSANTE CESTINO (In alto a destra)
|
||||
Positioned(
|
||||
top: -8,
|
||||
right: -8,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_stagedFiles.removeAt(index);
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.red,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// --- SEZIONE INVIA E CHIUDI ---
|
||||
SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 56,
|
||||
child: ElevatedButton.icon(
|
||||
// Il pulsante si accende SOLO se ci sono file nel carrello
|
||||
onPressed: _stagedFiles.isEmpty || _isUploading
|
||||
? null
|
||||
: _submitAllFiles,
|
||||
icon: const Icon(Icons.cloud_upload),
|
||||
label: Text(
|
||||
"INVIA ${_stagedFiles.length} FILE E CHIUDI",
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary,
|
||||
foregroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.onPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// --- OVERLAY DI CARICAMENTO ---
|
||||
if (_isUploading || _isProcessingLocal)
|
||||
Container(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
child: Center(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
_isUploading
|
||||
? "Invio in corso..."
|
||||
: "Elaborazione foto...",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- LOGICA FOTOCAMERA E LIBRERIA ---
|
||||
Future<void> _handleCamera() async {
|
||||
setState(() => _isProcessingLocal = true);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
|
||||
try {
|
||||
final picker = ImagePicker();
|
||||
final photo = await picker.pickImage(source: ImageSource.camera);
|
||||
|
||||
if (photo != null) {
|
||||
final photoBytes = await photo.readAsBytes();
|
||||
final photoSize = await photo.length();
|
||||
|
||||
final platformFile = PlatformFile(
|
||||
name: photo.name,
|
||||
size: photoSize,
|
||||
path: photo.path,
|
||||
bytes: photoBytes,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_stagedFiles.add(platformFile);
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
setState(() => _isProcessingLocal = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleFilePicker() async {
|
||||
final result = await FilePicker.pickFiles(
|
||||
allowMultiple: true,
|
||||
withData: true,
|
||||
);
|
||||
if (result != null) {
|
||||
setState(() {
|
||||
_stagedFiles.addAll(result.files);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// --- LOGICA DI INVIO AL BLoC ---
|
||||
void _submitAllFiles() {
|
||||
setState(() => _isUploading = true);
|
||||
|
||||
// Lanciamo l'evento del nostro nuovo AttachmentsBloc Agnostico!
|
||||
context.read<AttachmentsBloc>().add(
|
||||
UploadAttachmentsEvent(
|
||||
pickedFiles: _stagedFiles,
|
||||
companyId: widget.companyId,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
52
lib/core/widgets/image_upload/ui/upload_success_screen.dart
Normal file
52
lib/core/widgets/image_upload/ui/upload_success_screen.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class UploadSuccessScreen extends StatelessWidget {
|
||||
const UploadSuccessScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.green.shade50,
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.green.withValues(alpha: 0.3),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 5,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.check, size: 80, color: Colors.white),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
const Text(
|
||||
"Upload Completato!",
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.green,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
"I file sono stati caricati con successo sulla pratica.\nPuoi chiudere questa pagina o finestra del browser.",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 16, color: Colors.black54),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user