fix: capture photo plus robuste
This commit is contained in:
@@ -43,6 +43,7 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
|
|
||||||
String? _selectedImagePath;
|
String? _selectedImagePath;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
bool _isCapturing = false; // garde anti-double-capture pendant le traitement
|
||||||
|
|
||||||
// Caméra live
|
// Caméra live
|
||||||
CameraController? _cameraController;
|
CameraController? _cameraController;
|
||||||
@@ -585,7 +586,7 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
right: 0,
|
right: 0,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _takePictureManually,
|
onTap: _isCapturing ? null : _takePictureManually,
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 80,
|
height: 80,
|
||||||
width: 80,
|
width: 80,
|
||||||
@@ -607,6 +608,35 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// 6. Overlay bloquant pendant la capture/traitement : empêche de
|
||||||
|
// bouger l'UI ou de relancer une capture tant que la photo n'est pas
|
||||||
|
// chargée (absorbe tous les gestes + voile + indicateur).
|
||||||
|
if (_isCapturing)
|
||||||
|
Positioned.fill(
|
||||||
|
child: AbsorbPointer(
|
||||||
|
child: Container(
|
||||||
|
color: Colors.black.withValues(alpha: 0.45),
|
||||||
|
child: const Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
CircularProgressIndicator(color: Colors.white),
|
||||||
|
SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Photo en cours…',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -721,14 +751,21 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() => _isLoading = true);
|
// Garde anti-double-capture : tout appui supplémentaire pendant le
|
||||||
try {
|
// traitement est ignoré (évite les photos multiples / états incohérents).
|
||||||
try {
|
if (_isCapturing) return;
|
||||||
await _cameraController!.setZoomLevel(1.0);
|
|
||||||
} catch (_) {}
|
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isCapturing = true;
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
// On stoppe le flux d'analyse (obligatoire avant takePicture) puis on
|
||||||
|
// capture IMMÉDIATEMENT, sans étape intermédiaire. Le reset de zoom
|
||||||
|
// inutile (aucun zoom possible sur cet écran) a été retiré pour que la
|
||||||
|
// photo parte sans délai perceptible.
|
||||||
_stopAlignmentDetection();
|
_stopAlignmentDetection();
|
||||||
_stopParallelismDetection(); // NOUVEAU
|
_stopParallelismDetection();
|
||||||
|
|
||||||
final XFile photo = await _cameraController!.takePicture();
|
final XFile photo = await _cameraController!.takePicture();
|
||||||
|
|
||||||
@@ -747,6 +784,7 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
debugPrint('Downscale ignoré: $e');
|
debugPrint('Downscale ignoré: $e');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedImagePath = finalPath;
|
_selectedImagePath = finalPath;
|
||||||
_showLiveCamera = false;
|
_showLiveCamera = false;
|
||||||
@@ -756,7 +794,12 @@ class _CaptureScreenState extends State<CaptureScreen>
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Erreur lors du clic photo: $e');
|
debugPrint('Erreur lors du clic photo: $e');
|
||||||
} finally {
|
} finally {
|
||||||
setState(() => _isLoading = false);
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
_isCapturing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user