From e5894498a2ad200ce45a2ee4d54ac8e12403ee95 Mon Sep 17 00:00:00 2001 From: mark-cachy Date: Thu, 23 Apr 2026 19:32:51 +0200 Subject: [PATCH] feat: implement mobile upload screen with camera and file picker functionality --- lib/core/widgets/mobile_upload_screen.dart | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 lib/core/widgets/mobile_upload_screen.dart diff --git a/lib/core/widgets/mobile_upload_screen.dart b/lib/core/widgets/mobile_upload_screen.dart new file mode 100644 index 0000000..c86d80e --- /dev/null +++ b/lib/core/widgets/mobile_upload_screen.dart @@ -0,0 +1,117 @@ +import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:image_picker/image_picker.dart'; +import 'package:file_picker/file_picker.dart'; +import 'package:flux/features/customers/blocs/customer_files_bloc.dart'; + +class MobileUploadScreen extends StatelessWidget { + final String customerId; + final String customerName; + + const MobileUploadScreen({ + super.key, + required this.customerId, + required this.customerName, + }); + + @override + Widget build(BuildContext context) { + return BlocListener( + listener: (context, state) { + if (state.status == CustomerFilesStatus.success) { + ScaffoldMessenger.of( + context, + ).showSnackBar(const SnackBar(content: Text("File caricato! ✅"))); + } + if (state.status == CustomerFilesStatus.failure) { + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text("Errore: ${state.error}"))); + } + }, + child: Scaffold( + appBar: AppBar(title: Text("Upload: $customerName")), + body: Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + _UploadButton( + title: "SCATTA FOTO", + icon: Icons.camera_alt_rounded, + onTap: () => _handleCamera(context), + ), + const SizedBox(height: 20), + _UploadButton( + title: "CARICA DA MEMORIA", + icon: Icons.file_present_rounded, + onTap: () => _handleFilePicker(context), + isSecondary: true, + ), + ], + ), + ), + ), + ); + } + + Future _handleCamera(BuildContext context) async { + final picker = ImagePicker(); + final photo = await picker.pickImage( + source: ImageSource.camera, + imageQuality: 80, + ); + if (photo != null && context.mounted) { + context.read().add( + UploadCustomerFileEvent(photo: File(photo.path)), + ); + } + } + + Future _handleFilePicker(BuildContext context) async { + final result = await FilePicker.pickFiles(withData: true); + if (result != null && context.mounted) { + context.read().add( + UploadCustomerFileEvent(pickedFile: result.files.first), + ); + } + } +} + +class _UploadButton extends StatelessWidget { + final String title; + final IconData icon; + final VoidCallback onTap; + final bool isSecondary; + + const _UploadButton({ + required this.title, + required this.icon, + required this.onTap, + this.isSecondary = false, + }); + + @override + Widget build(BuildContext context) { + return SizedBox( + width: double.infinity, + height: 80, + child: ElevatedButton.icon( + onPressed: onTap, + icon: Icon(icon, size: 28), + label: Text( + title, + style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + style: ElevatedButton.styleFrom( + backgroundColor: isSecondary ? Colors.grey[200] : null, + foregroundColor: isSecondary ? Colors.black87 : null, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + ), + ), + ); + } +}