Improve camera image processing with overlay and error handling
This commit is contained in:
@@ -276,23 +276,41 @@ class _SharedMobileUploadScreenState extends State<SharedMobileUploadScreen> {
|
||||
// --- LOGICA FOTOCAMERA E LIBRERIA ---
|
||||
Future<void> _handleCamera() async {
|
||||
final picker = ImagePicker();
|
||||
// Apriamo la fotocamera. Qui NON mettiamo il loader perché
|
||||
// l'utente sta guardando l'app nativa del telefono.
|
||||
final photo = await picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
imageQuality: 80,
|
||||
);
|
||||
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, // I bytes ci salvano la vita su Supabase!
|
||||
);
|
||||
setState(() {
|
||||
_stagedFiles.add(platformFile);
|
||||
});
|
||||
if (photo != null) {
|
||||
// 1. Accendiamo l'overlay "Elaborazione foto..."
|
||||
setState(() => _isProcessingLocal = true);
|
||||
|
||||
// 2. TRUCCO NINJA: Lasciamo "respirare" Flutter per 50ms
|
||||
// in modo che faccia in tempo a disegnare l'overlay grigio sullo schermo
|
||||
// prima che readAsBytes() blocchi il processore!
|
||||
await Future.delayed(const Duration(milliseconds: 50));
|
||||
|
||||
try {
|
||||
// 3. Ora facciamo il lavoro pesante
|
||||
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 {
|
||||
// 4. Spegniamo l'overlay, sia che vada a buon fine, sia che ci sia un errore
|
||||
setState(() => _isProcessingLocal = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user