feat: enhance receipt import functionality with category selection and PDF opening support
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'pdf_opener_stub.dart'
|
||||
if (dart.library.js_interop) 'pdf_opener_web.dart' as impl;
|
||||
|
||||
Future<bool> openPdfBytes(Uint8List bytes) => impl.openPdfBytes(bytes);
|
||||
@@ -0,0 +1,3 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
Future<bool> openPdfBytes(Uint8List bytes) async => false;
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'dart:js_interop';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
Future<bool> openPdfBytes(Uint8List bytes) async {
|
||||
final blob = web.Blob(
|
||||
[bytes.toJS].toJS,
|
||||
web.BlobPropertyBag(type: 'application/pdf'),
|
||||
);
|
||||
final url = web.URL.createObjectURL(blob);
|
||||
final openedWindow = web.window.open(url, '_blank', 'noopener,noreferrer');
|
||||
if (openedWindow == null) {
|
||||
web.URL.revokeObjectURL(url);
|
||||
return false;
|
||||
}
|
||||
web.URL.revokeObjectURL(url);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user