From 9dc756b41ddf33512da1bc058d4b7455a27870f2 Mon Sep 17 00:00:00 2001 From: David PHAM-VAN Date: Sat, 3 Apr 2021 13:00:53 -0300 Subject: [PATCH] Remove unnecessary _raster call in PdfPreview --- README.md | 18 ++++++++++-------- demo/lib/app.dart | 10 +++++----- printing/CHANGELOG.md | 1 + printing/lib/src/pdf_preview.dart | 12 +++++++++++- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 73942512..edb5e014 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,17 @@ # Pdf for Dart and Flutter -![Dart CI](https://github.com/DavBfr/dart_pdf/workflows/Dart%20CI/badge.svg) -[![pub package](https://img.shields.io/pub/v/pdf.svg)](https://pub.dartlang.org/packages/pdf) -[![pub package](https://img.shields.io/pub/v/printing.svg)](https://pub.dartlang.org/packages/printing) -[![codecov](https://codecov.io/gh/DavBfr/dart_pdf/branch/master/graph/badge.svg)](https://codecov.io/gh/DavBfr/dart_pdf) - +![Dart CI](https://github.com/DavBfr/dart_pdf/workflows/Dart%20CI/badge.svg) [![pub package](https://img.shields.io/pub/v/pdf.svg)](https://pub.dartlang.org/packages/pdf) [![pub package](https://img.shields.io/pub/v/printing.svg)](https://pub.dartlang.org/packages/printing) [![codecov](https://codecov.io/gh/DavBfr/dart_pdf/branch/master/graph/badge.svg)](https://codecov.io/gh/DavBfr/dart_pdf) This set of plugins allows Flutter apps to generate and print pdf files to the device printer. This plugin works for iOS and Android. -* dart pdf: -* flutter printing: -* Live Demo: +- dart pdf: +- flutter printing: +- Live Demo: [![Buy Me A Coffee](https://bmc-cdn.nyc3.digitaloceanspaces.com/BMC-button-images/custom_images/orange_img.png "Buy Me A Coffee")](https://www.buymeacoffee.com/JORBmbw9h "Buy Me A Coffee") + +## Contributing + +Follow the instructions here: [contributing](CONTRIBUTING.md). + +A Makefile is available on the project root directory to download and prepare the dependencies. diff --git a/demo/lib/app.dart b/demo/lib/app.dart index a35c1de8..d5c6d7f2 100644 --- a/demo/lib/app.dart +++ b/demo/lib/app.dart @@ -66,10 +66,11 @@ class MyAppState extends State with SingleTickerProviderStateMixin { initialIndex: _tab, ); _tabController!.addListener(() { - setState(() { - _tab = _tabController!.index; - print('set state 1'); - }); + if (_tab != _tabController!.index) { + setState(() { + _tab = _tabController!.index; + }); + } if (examples[_tab].needsData && !_hasData && !_pending) { _pending = true; askName(context).then((value) { @@ -86,7 +87,6 @@ class MyAppState extends State with SingleTickerProviderStateMixin { setState(() { printingInfo = info; - print('set state 2'); }); } diff --git a/printing/CHANGELOG.md b/printing/CHANGELOG.md index b457191e..5457e7bd 100644 --- a/printing/CHANGELOG.md +++ b/printing/CHANGELOG.md @@ -3,6 +3,7 @@ ## 5.0.5 - Fix PdfPreview timer dispose [wwl901215] +- Remove unnecessary _raster call in PdfPreview [yaymalaga] ## 5.0.4 diff --git a/printing/lib/src/pdf_preview.dart b/printing/lib/src/pdf_preview.dart index 024d2b97..de3797d4 100644 --- a/printing/lib/src/pdf_preview.dart +++ b/printing/lib/src/pdf_preview.dart @@ -128,6 +128,8 @@ class _PdfPreviewState extends State { Timer? previewUpdate; + var _rastering = false; + static const defaultPageFormats = { 'A4': PdfPageFormat.a4, 'Letter': PdfPageFormat.letter, @@ -138,6 +140,11 @@ class _PdfPreviewState extends State { : pageFormat; Future _raster() async { + if (_rastering) { + return; + } + _rastering = true; + Uint8List _doc; if (!info.canRaster) { @@ -154,6 +161,7 @@ class _PdfPreviewState extends State { return true; }()); + _rastering = false; return; } @@ -177,6 +185,7 @@ class _PdfPreviewState extends State { informationCollector: collector, )); error = exception; + _rastering = false; return; } @@ -193,6 +202,7 @@ class _PdfPreviewState extends State { pages: widget.pages, )) { if (!mounted) { + _rastering = false; return; } setState(() { @@ -213,6 +223,7 @@ class _PdfPreviewState extends State { } pages.removeRange(pageNum, pages.length); + _rastering = false; } @override @@ -256,7 +267,6 @@ class _PdfPreviewState extends State { if (oldWidget.build != widget.build) { preview = null; updatePosition = null; - pages.clear(); _raster(); } super.didUpdateWidget(oldWidget);