Skip to content

Commit

Permalink
Remove unnecessary _raster call in PdfPreview
Browse files Browse the repository at this point in the history
  • Loading branch information
DavBfr committed Apr 3, 2021
1 parent 0bec0f4 commit 9dc756b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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: <https://pub.dev/packages/pdf>
* flutter printing: <https://pub.dev/packages/printing>
* Live Demo: <https://davbfr.github.io/dart_pdf/>
- dart pdf: <https://pub.dev/packages/pdf>
- flutter printing: <https://pub.dev/packages/printing>
- Live Demo: <https://davbfr.github.io/dart_pdf/>

[![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.
10 changes: 5 additions & 5 deletions demo/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ class MyAppState extends State<MyApp> 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) {
Expand All @@ -86,7 +87,6 @@ class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {

setState(() {
printingInfo = info;
print('set state 2');
});
}

Expand Down
1 change: 1 addition & 0 deletions printing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 5.0.5

- Fix PdfPreview timer dispose [wwl901215]
- Remove unnecessary _raster call in PdfPreview [yaymalaga]

## 5.0.4

Expand Down
12 changes: 11 additions & 1 deletion printing/lib/src/pdf_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class _PdfPreviewState extends State<PdfPreview> {

Timer? previewUpdate;

var _rastering = false;

static const defaultPageFormats = <String, PdfPageFormat>{
'A4': PdfPageFormat.a4,
'Letter': PdfPageFormat.letter,
Expand All @@ -138,6 +140,11 @@ class _PdfPreviewState extends State<PdfPreview> {
: pageFormat;

Future<void> _raster() async {
if (_rastering) {
return;
}
_rastering = true;

Uint8List _doc;

if (!info.canRaster) {
Expand All @@ -154,6 +161,7 @@ class _PdfPreviewState extends State<PdfPreview> {
return true;
}());

_rastering = false;
return;
}

Expand All @@ -177,6 +185,7 @@ class _PdfPreviewState extends State<PdfPreview> {
informationCollector: collector,
));
error = exception;
_rastering = false;
return;
}

Expand All @@ -193,6 +202,7 @@ class _PdfPreviewState extends State<PdfPreview> {
pages: widget.pages,
)) {
if (!mounted) {
_rastering = false;
return;
}
setState(() {
Expand All @@ -213,6 +223,7 @@ class _PdfPreviewState extends State<PdfPreview> {
}

pages.removeRange(pageNum, pages.length);
_rastering = false;
}

@override
Expand Down Expand Up @@ -256,7 +267,6 @@ class _PdfPreviewState extends State<PdfPreview> {
if (oldWidget.build != widget.build) {
preview = null;
updatePosition = null;
pages.clear();
_raster();
}
super.didUpdateWidget(oldWidget);
Expand Down

0 comments on commit 9dc756b

Please sign in to comment.