mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-06 01:15:44 -06:00
- Fix grey screen bug when adding labels from documnet upload - Add more permission checks to conditionally show widgets
58 lines
1.5 KiB
Dart
58 lines
1.5 KiB
Dart
import 'dart:developer';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:paperless_api/paperless_api.dart';
|
|
import 'package:paperless_mobile/core/service/file_service.dart';
|
|
import 'package:paperless_mobile/features/notifications/services/local_notification_service.dart';
|
|
|
|
class DocumentScannerCubit extends Cubit<List<File>> {
|
|
final LocalNotificationService _notificationService;
|
|
|
|
DocumentScannerCubit(this._notificationService) : super(const []);
|
|
|
|
void addScan(File file) => emit([...state, file]);
|
|
|
|
void removeScan(int fileIndex) {
|
|
try {
|
|
state[fileIndex].deleteSync();
|
|
final scans = [...state];
|
|
scans.removeAt(fileIndex);
|
|
emit(scans);
|
|
} catch (_) {
|
|
throw const PaperlessApiException(ErrorCode.scanRemoveFailed);
|
|
}
|
|
}
|
|
|
|
void reset() {
|
|
try {
|
|
for (final doc in state) {
|
|
doc.deleteSync();
|
|
if (kDebugMode) {
|
|
log('[ScannerCubit]: Removed ${doc.path}');
|
|
}
|
|
}
|
|
imageCache.clear();
|
|
emit([]);
|
|
} catch (_) {
|
|
throw const PaperlessApiException(ErrorCode.scanRemoveFailed);
|
|
}
|
|
}
|
|
|
|
Future<void> saveToFile(
|
|
Uint8List bytes,
|
|
String fileName,
|
|
String locale,
|
|
) async {
|
|
var file = await FileService.saveToFile(bytes, fileName);
|
|
_notificationService.notifyFileSaved(
|
|
filename: fileName,
|
|
filePath: file.path,
|
|
finished: true,
|
|
locale: locale,
|
|
);
|
|
}
|
|
}
|