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
2020-12-29 16:13:09 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
130ee7da82fad835fb3b6a3bda67724b3ede7039
130ee7da
1 parent
96c31fdf
Implement pan and zoom on PdfPreview widget
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
13 deletions
printing/CHANGELOG.md
printing/lib/src/pdf_preview.dart
printing/CHANGELOG.md
View file @
130ee7d
...
...
@@ -4,6 +4,7 @@
-
Remove deprecated methods
-
Document.save() now returns a Future
-
Implement pan and zoom on PdfPreview widget
## 3.7.2
...
...
printing/lib/src/pdf_preview.dart
View file @
130ee7d
import
'dart:async'
;
import
'dart:math'
;
import
'dart:typed_data'
;
...
...
@@ -100,6 +101,16 @@ class _PdfPreviewState extends State<PdfPreview> {
Object
error
;
int
preview
;
double
updatePosition
;
final
scrollController
=
ScrollController
();
final
transformationController
=
TransformationController
();
Timer
previewUpdate
;
static
const
Map
<
String
,
PdfPageFormat
>
defaultPageFormats
=
<
String
,
PdfPageFormat
>{
'A4'
:
PdfPageFormat
.
a4
,
...
...
@@ -178,6 +189,8 @@ class _PdfPreviewState extends State<PdfPreview> {
@override
void
didUpdateWidget
(
covariant
PdfPreview
oldWidget
)
{
if
(
oldWidget
.
build
!=
widget
.
build
)
{
preview
=
null
;
updatePosition
=
null
;
pages
.
clear
();
_raster
();
}
...
...
@@ -196,13 +209,16 @@ class _PdfPreviewState extends State<PdfPreview> {
});
}
final
mq
=
MediaQuery
.
of
(
context
);
dpi
=
(
min
(
mq
.
size
.
width
-
16
,
widget
.
maxPageWidth
??
double
.
infinity
))
*
mq
.
devicePixelRatio
/
pageFormat
.
width
*
72
;
previewUpdate
?.
cancel
();
previewUpdate
=
Timer
(
const
Duration
(
seconds:
1
),
()
{
final
mq
=
MediaQuery
.
of
(
context
);
dpi
=
(
min
(
mq
.
size
.
width
-
16
,
widget
.
maxPageWidth
??
double
.
infinity
))
*
mq
.
devicePixelRatio
/
pageFormat
.
width
*
72
;
_raster
();
_raster
();
});
super
.
didChangeDependencies
();
}
...
...
@@ -242,8 +258,33 @@ class _PdfPreviewState extends State<PdfPreview> {
return
Scrollbar
(
child:
ListView
.
builder
(
controller:
scrollController
,
itemCount:
pages
.
length
,
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
pages
[
index
],
itemBuilder:
(
BuildContext
context
,
int
index
)
=>
GestureDetector
(
onDoubleTap:
()
{
setState
(()
{
updatePosition
=
scrollController
.
position
.
pixels
;
preview
=
index
;
transformationController
.
value
.
setIdentity
();
});
},
child:
pages
[
index
],
),
),
);
}
Widget
_zoomPreview
()
{
return
GestureDetector
(
onDoubleTap:
()
{
setState
(()
{
preview
=
null
;
});
},
child:
InteractiveViewer
(
transformationController:
transformationController
,
maxScale:
5
,
child:
Center
(
child:
pages
[
preview
]),
),
);
}
...
...
@@ -252,6 +293,26 @@ class _PdfPreviewState extends State<PdfPreview> {
Widget
build
(
BuildContext
context
)
{
final
theme
=
Theme
.
of
(
context
);
Widget
page
;
if
(
preview
!=
null
)
{
page
=
_zoomPreview
();
}
else
{
page
=
Container
(
constraints:
widget
.
maxPageWidth
!=
null
?
BoxConstraints
(
maxWidth:
widget
.
maxPageWidth
)
:
null
,
child:
_createPreview
(),
);
if
(
updatePosition
!=
null
)
{
Timer
.
run
(()
{
scrollController
.
jumpTo
(
updatePosition
);
updatePosition
=
null
;
});
}
}
final
Widget
scrollView
=
Container
(
decoration:
widget
.
scrollViewDecoration
??
BoxDecoration
(
...
...
@@ -263,12 +324,7 @@ class _PdfPreviewState extends State<PdfPreview> {
),
width:
double
.
infinity
,
alignment:
Alignment
.
center
,
child:
Container
(
constraints:
widget
.
maxPageWidth
!=
null
?
BoxConstraints
(
maxWidth:
widget
.
maxPageWidth
)
:
null
,
child:
_createPreview
(),
),
child:
page
,
);
final
actions
=
<
Widget
>[];
...
...
Please
register
or
login
to post a comment