53 lines
1.8 KiB
Dart
53 lines
1.8 KiB
Dart
import 'dart:io';
|
|
import 'package:get/get.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import '../../../core/utils/logger.dart';
|
|
import '../../../core/utils/app_snackbar.dart';
|
|
|
|
class ScannerController extends GetxController {
|
|
var capturedImages = <File>[].obs;
|
|
var isProcessing = false.obs;
|
|
|
|
void addImage(String imagePath) {
|
|
capturedImages.add(File(imagePath));
|
|
AppLogger.print('Added image to batch: $imagePath. Total: ${capturedImages.length}');
|
|
}
|
|
|
|
void removeImage(int index) {
|
|
if (index >= 0 && index < capturedImages.length) {
|
|
capturedImages.removeAt(index);
|
|
}
|
|
}
|
|
|
|
Future<void> uploadBatch() async {
|
|
if (capturedImages.isEmpty) {
|
|
AppSnackbar.showWarning('تنبيه', 'الرجاء تصوير فاتورة واحدة على الأقل');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
isProcessing.value = true;
|
|
AppLogger.print('Uploading batch of ${capturedImages.length} images...');
|
|
|
|
// TODO: Implement actual upload logic with Dio
|
|
await Future.delayed(const Duration(seconds: 2)); // Simulate
|
|
|
|
AppSnackbar.showSuccess('نجاح', 'تم رفع ${capturedImages.length} فواتير للمعالجة بنجاح');
|
|
capturedImages.clear();
|
|
Get.back(); // Go back to dashboard or previous screen
|
|
} catch (e) {
|
|
AppLogger.error('Failed to upload batch', e);
|
|
AppSnackbar.showError('خطأ', 'فشل رفع الفواتير، يرجى المحاولة لاحقاً');
|
|
} finally {
|
|
isProcessing.value = false;
|
|
}
|
|
}
|
|
|
|
Future<String> getSavePath() async {
|
|
final directory = await getTemporaryDirectory();
|
|
final fileName = 'invoice_${DateTime.now().millisecondsSinceEpoch}.jpg';
|
|
return path.join(directory.path, fileName);
|
|
}
|
|
}
|