Version initiale de Gestion Prix
App Flutter de gestion de stock/prix pour tablette Android (100% local) : scan code-barres (OpenFoodFacts), prix au kilo/litre, packs, inventaire, prix d'achat + marge, filtres de tri, étiquettes PDF, design noir & blanc. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
/// Prise et stockage local des photos de produits.
|
||||
class PhotoService {
|
||||
static final _picker = ImagePicker();
|
||||
|
||||
/// Ouvre l'appareil photo ([ImageSource.camera]) ou la galerie, copie l'image
|
||||
/// choisie dans le stockage de l'app et retourne son chemin local (ou null si annulé).
|
||||
static Future<String?> choisir(ImageSource source) async {
|
||||
final x = await _picker.pickImage(
|
||||
source: source,
|
||||
maxWidth: 1200,
|
||||
imageQuality: 82,
|
||||
);
|
||||
if (x == null) return null;
|
||||
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final dossier = Directory('${dir.path}/photos');
|
||||
if (!await dossier.exists()) await dossier.create(recursive: true);
|
||||
|
||||
final nom = 'produit_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
||||
final dest = '${dossier.path}/$nom';
|
||||
await File(x.path).copy(dest);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/// Vrai si l'url pointe vers un fichier local (photo prise), pas vers le web.
|
||||
static bool estLocale(String? url) =>
|
||||
url != null && url.isNotEmpty && !url.startsWith('http');
|
||||
}
|
||||
Reference in New Issue
Block a user