Showing
3 changed files
with
6 additions
and
36 deletions
| @@ -35,44 +35,10 @@ Future<PdfImage> wrapWidget( | @@ -35,44 +35,10 @@ Future<PdfImage> wrapWidget( | ||
| 35 | 35 | ||
| 36 | final RenderRepaintBoundary wrappedWidget = | 36 | final RenderRepaintBoundary wrappedWidget = |
| 37 | key.currentContext.findRenderObject(); | 37 | key.currentContext.findRenderObject(); |
| 38 | - ui.Image image = await wrappedWidget.toImage(pixelRatio: pixelRatio); | ||
| 39 | - | ||
| 40 | - image = await _resize(image, width, height); | ||
| 41 | - | 38 | + final ui.Image image = await wrappedWidget.toImage(pixelRatio: pixelRatio); |
| 42 | final ByteData byteData = | 39 | final ByteData byteData = |
| 43 | await image.toByteData(format: ui.ImageByteFormat.rawRgba); | 40 | await image.toByteData(format: ui.ImageByteFormat.rawRgba); |
| 44 | final Uint8List imageData = byteData.buffer.asUint8List(); | 41 | final Uint8List imageData = byteData.buffer.asUint8List(); |
| 45 | return PdfImage(document, | 42 | return PdfImage(document, |
| 46 | image: imageData, width: image.width, height: image.height); | 43 | image: imageData, width: image.width, height: image.height); |
| 47 | } | 44 | } |
| 48 | - | ||
| 49 | -Future<ui.Image> _resize( | ||
| 50 | - ui.Image image, | ||
| 51 | - int width, | ||
| 52 | - int height, | ||
| 53 | -) async { | ||
| 54 | - if (width == null && height == null) { | ||
| 55 | - return image; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - width ??= (height / image.height * image.width).toInt(); | ||
| 59 | - height ??= (width / image.width * image.height).toInt(); | ||
| 60 | - | ||
| 61 | - final Completer<ui.Image> ptr = Completer<ui.Image>(); | ||
| 62 | - final Uint8List data = | ||
| 63 | - (await image.toByteData(format: ui.ImageByteFormat.rawRgba)) | ||
| 64 | - .buffer | ||
| 65 | - .asUint8List(); | ||
| 66 | - ui.decodeImageFromPixels( | ||
| 67 | - data, | ||
| 68 | - image.width, | ||
| 69 | - image.height, | ||
| 70 | - ui.PixelFormat.rgba8888, | ||
| 71 | - (ui.Image result) { | ||
| 72 | - ptr.complete(result); | ||
| 73 | - }, | ||
| 74 | - targetWidth: width, | ||
| 75 | - targetHeight: height, | ||
| 76 | - ); | ||
| 77 | - return ptr.future; | ||
| 78 | -} |
| @@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to | @@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to | ||
| 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing | 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing |
| 5 | repository: https://github.com/DavBfr/dart_pdf | 5 | repository: https://github.com/DavBfr/dart_pdf |
| 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
| 7 | -version: 3.3.0 | 7 | +version: 3.3.1 |
| 8 | 8 | ||
| 9 | environment: | 9 | environment: |
| 10 | sdk: ">=2.3.0 <3.0.0" | 10 | sdk: ">=2.3.0 <3.0.0" |
-
Please register or login to post a comment