Showing
4 changed files
with
27 additions
and
14 deletions
1 | # Pdf for Dart and Flutter | 1 | # Pdf for Dart and Flutter |
2 | 2 | ||
3 | - | ||
4 | -[](https://pub.dartlang.org/packages/pdf) | ||
5 | -[](https://pub.dartlang.org/packages/printing) | ||
6 | -[](https://codecov.io/gh/DavBfr/dart_pdf) | ||
7 | - | 3 | + [](https://pub.dartlang.org/packages/pdf) [](https://pub.dartlang.org/packages/printing) [](https://codecov.io/gh/DavBfr/dart_pdf) |
8 | 4 | ||
9 | This set of plugins allows Flutter apps to generate and print pdf files to the device printer. This plugin works for iOS and Android. | 5 | This set of plugins allows Flutter apps to generate and print pdf files to the device printer. This plugin works for iOS and Android. |
10 | 6 | ||
11 | -* dart pdf: <https://pub.dev/packages/pdf> | ||
12 | -* flutter printing: <https://pub.dev/packages/printing> | ||
13 | -* Live Demo: <https://davbfr.github.io/dart_pdf/> | 7 | +- dart pdf: <https://pub.dev/packages/pdf> |
8 | +- flutter printing: <https://pub.dev/packages/printing> | ||
9 | +- Live Demo: <https://davbfr.github.io/dart_pdf/> | ||
14 | 10 | ||
15 | [](https://www.buymeacoffee.com/JORBmbw9h "Buy Me A Coffee") | 11 | [](https://www.buymeacoffee.com/JORBmbw9h "Buy Me A Coffee") |
12 | + | ||
13 | +## Contributing | ||
14 | + | ||
15 | +Follow the instructions here: [contributing](CONTRIBUTING.md). | ||
16 | + | ||
17 | +A Makefile is available on the project root directory to download and prepare the dependencies. |
@@ -66,10 +66,11 @@ class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | @@ -66,10 +66,11 @@ class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | ||
66 | initialIndex: _tab, | 66 | initialIndex: _tab, |
67 | ); | 67 | ); |
68 | _tabController!.addListener(() { | 68 | _tabController!.addListener(() { |
69 | - setState(() { | ||
70 | - _tab = _tabController!.index; | ||
71 | - print('set state 1'); | ||
72 | - }); | 69 | + if (_tab != _tabController!.index) { |
70 | + setState(() { | ||
71 | + _tab = _tabController!.index; | ||
72 | + }); | ||
73 | + } | ||
73 | if (examples[_tab].needsData && !_hasData && !_pending) { | 74 | if (examples[_tab].needsData && !_hasData && !_pending) { |
74 | _pending = true; | 75 | _pending = true; |
75 | askName(context).then((value) { | 76 | askName(context).then((value) { |
@@ -86,7 +87,6 @@ class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | @@ -86,7 +87,6 @@ class MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | ||
86 | 87 | ||
87 | setState(() { | 88 | setState(() { |
88 | printingInfo = info; | 89 | printingInfo = info; |
89 | - print('set state 2'); | ||
90 | }); | 90 | }); |
91 | } | 91 | } |
92 | 92 |
@@ -128,6 +128,8 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -128,6 +128,8 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
128 | 128 | ||
129 | Timer? previewUpdate; | 129 | Timer? previewUpdate; |
130 | 130 | ||
131 | + var _rastering = false; | ||
132 | + | ||
131 | static const defaultPageFormats = <String, PdfPageFormat>{ | 133 | static const defaultPageFormats = <String, PdfPageFormat>{ |
132 | 'A4': PdfPageFormat.a4, | 134 | 'A4': PdfPageFormat.a4, |
133 | 'Letter': PdfPageFormat.letter, | 135 | 'Letter': PdfPageFormat.letter, |
@@ -138,6 +140,11 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -138,6 +140,11 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
138 | : pageFormat; | 140 | : pageFormat; |
139 | 141 | ||
140 | Future<void> _raster() async { | 142 | Future<void> _raster() async { |
143 | + if (_rastering) { | ||
144 | + return; | ||
145 | + } | ||
146 | + _rastering = true; | ||
147 | + | ||
141 | Uint8List _doc; | 148 | Uint8List _doc; |
142 | 149 | ||
143 | if (!info.canRaster) { | 150 | if (!info.canRaster) { |
@@ -154,6 +161,7 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -154,6 +161,7 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
154 | return true; | 161 | return true; |
155 | }()); | 162 | }()); |
156 | 163 | ||
164 | + _rastering = false; | ||
157 | return; | 165 | return; |
158 | } | 166 | } |
159 | 167 | ||
@@ -177,6 +185,7 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -177,6 +185,7 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
177 | informationCollector: collector, | 185 | informationCollector: collector, |
178 | )); | 186 | )); |
179 | error = exception; | 187 | error = exception; |
188 | + _rastering = false; | ||
180 | return; | 189 | return; |
181 | } | 190 | } |
182 | 191 | ||
@@ -193,6 +202,7 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -193,6 +202,7 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
193 | pages: widget.pages, | 202 | pages: widget.pages, |
194 | )) { | 203 | )) { |
195 | if (!mounted) { | 204 | if (!mounted) { |
205 | + _rastering = false; | ||
196 | return; | 206 | return; |
197 | } | 207 | } |
198 | setState(() { | 208 | setState(() { |
@@ -213,6 +223,7 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -213,6 +223,7 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
213 | } | 223 | } |
214 | 224 | ||
215 | pages.removeRange(pageNum, pages.length); | 225 | pages.removeRange(pageNum, pages.length); |
226 | + _rastering = false; | ||
216 | } | 227 | } |
217 | 228 | ||
218 | @override | 229 | @override |
@@ -256,7 +267,6 @@ class _PdfPreviewState extends State<PdfPreview> { | @@ -256,7 +267,6 @@ class _PdfPreviewState extends State<PdfPreview> { | ||
256 | if (oldWidget.build != widget.build) { | 267 | if (oldWidget.build != widget.build) { |
257 | preview = null; | 268 | preview = null; |
258 | updatePosition = null; | 269 | updatePosition = null; |
259 | - pages.clear(); | ||
260 | _raster(); | 270 | _raster(); |
261 | } | 271 | } |
262 | super.didUpdateWidget(oldWidget); | 272 | super.didUpdateWidget(oldWidget); |
-
Please register or login to post a comment