Fix: Passage à l'appareil photo classique et suppression de l'auto-capture
This commit is contained in:
@@ -2,7 +2,6 @@ import 'dart:io';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:google_mlkit_document_scanner/google_mlkit_document_scanner.dart';
|
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -26,7 +25,6 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
String? _selectedImagePath;
|
String? _selectedImagePath;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
/// Gère la demande de permission et la sélection d'image depuis la galerie
|
|
||||||
Future<void> _handleGallerySelection() async {
|
Future<void> _handleGallerySelection() async {
|
||||||
PermissionStatus status;
|
PermissionStatus status;
|
||||||
|
|
||||||
@@ -83,8 +81,8 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sessionProvider = context.watch<SessionProvider>();
|
final sessionProvider = context.watch<SessionProvider>();
|
||||||
final title = sessionProvider.isSessionActive
|
final title = sessionProvider.isSessionActive
|
||||||
? 'Cible ${sessionProvider.targetCount + 1}'
|
? 'Cible ${sessionProvider.targetCount + 1}'
|
||||||
: 'Source';
|
: 'Source';
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -104,7 +102,8 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
child: ImageSourceButton(
|
child: ImageSourceButton(
|
||||||
icon: Icons.camera_alt,
|
icon: Icons.camera_alt,
|
||||||
label: 'Scanner',
|
label: 'Scanner',
|
||||||
onPressed: _isLoading ? null : _scanDocument,
|
// Appelle maintenant l'appareil photo classique
|
||||||
|
onPressed: _isLoading ? null : _openStandardCamera,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
@@ -143,10 +142,6 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Widget _buildGuide() {
|
Widget _buildGuide() {
|
||||||
return Card(
|
return Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@@ -192,25 +187,17 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _scanDocument() async {
|
// NOUVELLE FONCTION : Ouvre l'appareil photo classique 100% Manuel
|
||||||
setState(() => _isLoading = true);
|
Future<void> _openStandardCamera() async {
|
||||||
try {
|
final status = await Permission.camera.request();
|
||||||
final options = DocumentScannerOptions(
|
if (status.isGranted) {
|
||||||
documentFormat: DocumentFormat.jpeg,
|
_captureImage(ImageSource.camera);
|
||||||
mode: ScannerMode.base,
|
} else {
|
||||||
pageLimit: 1,
|
if (mounted) {
|
||||||
isGalleryImport: false,
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
);
|
const SnackBar(content: Text('Accès à l\'appareil photo requis')),
|
||||||
final scanner = DocumentScanner(options: options);
|
);
|
||||||
final documents = await scanner.scanDocument();
|
|
||||||
if (documents.images.isNotEmpty) {
|
|
||||||
_selectedImagePath = documents.images.first;
|
|
||||||
_analyzeImage();
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Erreur scan: $e');
|
|
||||||
} finally {
|
|
||||||
if (mounted) setState(() => _isLoading = false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +211,10 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
imageQuality: 90,
|
imageQuality: 90,
|
||||||
);
|
);
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
_selectedImagePath = image.path;
|
setState(() {
|
||||||
|
_selectedImagePath = image.path;
|
||||||
|
});
|
||||||
|
// On appelle directement l'analyse avec le bon chemin de fichier
|
||||||
_analyzeImage();
|
_analyzeImage();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -236,6 +226,8 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
|
|
||||||
void _analyzeImage() {
|
void _analyzeImage() {
|
||||||
if (_selectedImagePath == null) return;
|
if (_selectedImagePath == null) return;
|
||||||
|
|
||||||
|
// Correction de la redirection pour ouvrir proprement le CropScreen
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
@@ -246,4 +238,4 @@ class _CaptureScreenState extends State<CaptureScreen> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ class _SessionSetupScreenState extends State<SessionSetupScreen> {
|
|||||||
|
|
||||||
// Shots per target
|
// Shots per target
|
||||||
const Text(
|
const Text(
|
||||||
'Nombre de balles par cible',
|
'Nombre de balles pour la cible actuelle',
|
||||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
|||||||
Reference in New Issue
Block a user