Gamal AbdelNasser
Committed by David PHAM-VAN

Save in an isolate when available

1 # Changelog 1 # Changelog
2 2
  3 +## 3.11.0
  4 +
  5 +- Save in an isolate when available
  6 +
3 ## 3.10.8 7 ## 3.10.8
4 8
5 - Add Flutter's Logical Pixel constant 9 - Add Flutter's Logical Pixel constant
@@ -251,11 +251,13 @@ class PdfDocument { @@ -251,11 +251,13 @@ class PdfDocument {
251 251
252 /// Generate the PDF document as a memory file 252 /// Generate the PDF document as a memory file
253 Future<Uint8List> save() async { 253 Future<Uint8List> save() async {
254 - final os = PdfStream();  
255 - if (prev != null) {  
256 - os.putBytes(prev!.bytes);  
257 - }  
258 - await _write(os);  
259 - return os.output(); 254 + return pdfCompute(() async {
  255 + final os = PdfStream();
  256 + if (prev != null) {
  257 + os.putBytes(prev!.bytes);
  258 + }
  259 + await _write(os);
  260 + return os.output();
  261 + });
260 } 262 }
261 } 263 }
@@ -20,3 +20,10 @@ import '../format/object_base.dart'; @@ -20,3 +20,10 @@ import '../format/object_base.dart';
20 20
21 /// Zip compression function 21 /// Zip compression function
22 DeflateCallback defaultDeflate = const ZLibEncoder().encode; 22 DeflateCallback defaultDeflate = const ZLibEncoder().encode;
  23 +
  24 +/// The dart:html implementation of [pdfCompute].
  25 +@pragma('dart2js:tryInline')
  26 +Future<R> pdfCompute<R>(Future<R> Function() computation) async {
  27 + await null;
  28 + return computation();
  29 +}
@@ -15,8 +15,14 @@ @@ -15,8 +15,14 @@
15 */ 15 */
16 16
17 import 'dart:io'; 17 import 'dart:io';
  18 +import 'dart:isolate';
18 19
19 import '../format/object_base.dart'; 20 import '../format/object_base.dart';
20 21
21 /// Zip compression function 22 /// Zip compression function
22 DeflateCallback defaultDeflate = zlib.encode; 23 DeflateCallback defaultDeflate = zlib.encode;
  24 +
  25 +/// The dart:io implementation of [pdfCompute].
  26 +@pragma('vm:prefer-inline')
  27 +Future<R> pdfCompute<R>(Future<R> Function() computation) async =>
  28 + Isolate.run<R>(computation, debugName: 'dart_pdf');
@@ -15,7 +15,7 @@ topics: @@ -15,7 +15,7 @@ topics:
15 version: 3.10.8 15 version: 3.10.8
16 16
17 environment: 17 environment:
18 - sdk: ">=2.18.0 <4.0.0" 18 + sdk: ">=2.19.0 <4.0.0"
19 19
20 dependencies: 20 dependencies:
21 archive: ^3.1.0 21 archive: ^3.1.0