Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2022-05-14 16:26:57 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
726aab13746a4f515601febfb0824ba71dbe4f80
726aab13
1 parent
96059800
Improve PdfPreview memory consumption
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
14 deletions
printing/CHANGELOG.md
printing/lib/src/preview/page.dart
printing/lib/src/preview/pdf_preview.dart
printing/lib/src/preview/raster.dart
printing/CHANGELOG.md
View file @
726aab1
...
...
@@ -4,6 +4,7 @@
-
iOS: Set cutLength to be currentSize.height
[
Liam Downey
]
-
Add Flutter 3 warning workaround
-
Improve PdfPreview memory consumption
## 5.9.0
...
...
printing/lib/src/preview/page.dart
View file @
726aab1
...
...
@@ -16,20 +16,24 @@
import
'package:flutter/material.dart'
;
import
'../raster.dart'
;
/// Represents one PDF page
class
PdfPreviewPage
extends
StatelessWidget
{
/// Create a PDF page widget
const
PdfPreviewPage
({
Key
?
key
,
this
.
page
,
required
this
.
image
,
required
this
.
width
,
required
this
.
height
,
this
.
pdfPreviewPageDecoration
,
this
.
pageMargin
,
})
:
super
(
key:
key
);
/// Image representing the content of the page
final
PdfRaster
?
page
;
final
ImageProvider
image
;
final
int
width
;
final
int
height
;
/// Decoration around the page
final
Decoration
?
pdfPreviewPageDecoration
;
...
...
@@ -39,7 +43,6 @@ class PdfPreviewPage extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
final
im
=
PdfRasterImage
(
page
!);
final
scrollbarTrack
=
Theme
.
of
(
context
)
.
scrollbarTheme
.
thickness
...
...
@@ -66,9 +69,9 @@ class PdfPreviewPage extends StatelessWidget {
],
),
child:
AspectRatio
(
aspectRatio:
page
!.
width
/
page
!.
height
,
aspectRatio:
width
/
height
,
child:
Image
(
image:
im
,
image:
im
age
,
fit:
BoxFit
.
cover
,
),
),
...
...
printing/lib/src/preview/pdf_preview.dart
View file @
726aab1
...
...
@@ -183,8 +183,8 @@ class _PdfPreviewState extends State<PdfPreview> {
if
(!
widget
.
canChangePageFormat
&&
pages
.
isNotEmpty
)
{
format
=
PdfPageFormat
(
pages
.
first
.
page
!.
width
*
PdfPageFormat
.
inch
/
dpi
,
pages
.
first
.
page
!.
height
*
PdfPageFormat
.
inch
/
dpi
,
pages
.
first
.
width
*
PdfPageFormat
.
inch
/
dpi
,
pages
.
first
.
height
*
PdfPageFormat
.
inch
/
dpi
,
marginAll:
5
*
PdfPageFormat
.
mm
,
);
}
...
...
printing/lib/src/preview/raster.dart
View file @
726aab1
...
...
@@ -37,7 +37,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
PdfPageFormat
get
pageFormat
=>
widget
.
pageFormat
;
/// Resulting pages
final
List
<
PdfPreviewPage
>
pages
=
<
PdfPreviewPage
>[];
final
pages
=
<
PdfPreviewPage
>[];
/// Printing subsystem information
PrintingInfo
?
info
;
...
...
@@ -57,6 +57,10 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
@override
void
dispose
()
{
_previewUpdate
?.
cancel
();
for
(
final
e
in
pages
)
{
e
.
image
.
evict
();
}
pages
.
clear
();
super
.
dispose
();
}
...
...
@@ -159,26 +163,35 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
_rastering
=
false
;
return
;
}
setState
(()
{
if
(
pages
.
length
<=
pageNum
)
{
pages
.
add
(
PdfPreviewPage
(
page:
page
,
image:
MemoryImage
(
await
page
.
toPng
()),
width:
page
.
width
,
height:
page
.
height
,
pdfPreviewPageDecoration:
widget
.
pdfPreviewPageDecoration
,
pageMargin:
widget
.
previewPageMargin
,
));
}
else
{
pages
[
pageNum
].
image
.
evict
();
pages
[
pageNum
]
=
PdfPreviewPage
(
page:
page
,
image:
MemoryImage
(
await
page
.
toPng
()),
width:
page
.
width
,
height:
page
.
height
,
pdfPreviewPageDecoration:
widget
.
pdfPreviewPageDecoration
,
pageMargin:
widget
.
previewPageMargin
,
);
}
});
setState
(()
{
});
pageNum
++;
}
for
(
var
index
=
pageNum
;
index
<
pages
.
length
;
index
++)
{
pages
[
index
].
image
.
evict
();
}
pages
.
removeRange
(
pageNum
,
pages
.
length
);
setState
(()
{});
}
catch
(
exception
,
stack
)
{
InformationCollector
?
collector
;
...
...
Please
register
or
login
to post a comment