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
2019-04-11 07:33:31 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3a91f21aee2919993b7967fa52839194cc04f15a
3a91f21a
1 parent
3f9fe4d0
Set a proper value to context.pagesCount
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
11 deletions
pdf/CHANGELOG.md
pdf/example/main.dart
pdf/lib/widgets/document.dart
pdf/lib/widgets/multi_page.dart
pdf/lib/widgets/widget.dart
pdf/CHANGELOG.md
View file @
3a91f21
...
...
@@ -6,6 +6,7 @@
*
Fix RichText Widget word spacing
*
Improve Theme and TextStyle
*
Implement properly RichText.softWrap
*
Set a proper value to context.pagesCount
# 1.3.7
*
Add Pdf Creation date
...
...
pdf/example/main.dart
View file @
3a91f21
...
...
@@ -30,7 +30,7 @@ void main() {
return
Container
(
alignment:
Alignment
.
centerRight
,
margin:
const
EdgeInsets
.
only
(
top:
1.0
*
PdfPageFormat
.
cm
),
child:
Text
(
'Page
${context.pageNumber}
'
,
child:
Text
(
'Page
${context.pageNumber}
of
${context.pagesCount}
'
,
style:
Theme
.
of
(
context
)
.
defaultTextStyle
.
copyWith
(
color:
PdfColors
.
grey
)));
...
...
pdf/lib/widgets/document.dart
View file @
3a91f21
...
...
@@ -50,11 +50,19 @@ class Document {
final
Theme
theme
;
final
List
<
Page
>
_pages
=
<
Page
>[];
void
addPage
(
Page
page
)
{
page
.
generate
(
this
);
_pages
.
add
(
page
);
}
List
<
int
>
save
()
=>
document
.
save
();
List
<
int
>
save
()
{
for
(
Page
page
in
_pages
)
{
page
.
postProcess
(
this
);
}
return
document
.
save
();
}
}
typedef
BuildCallback
=
Widget
Function
(
Context
context
);
...
...
@@ -63,7 +71,7 @@ typedef BuildListCallback = List<Widget> Function(Context context);
enum
PageOrientation
{
natural
,
landscape
,
portrait
}
class
Page
{
const
Page
(
Page
(
{
this
.
pageFormat
=
PdfPageFormat
.
standard
,
BuildCallback
build
,
this
.
theme
,
...
...
@@ -89,6 +97,8 @@ class Page {
(
orientation
==
PageOrientation
.
portrait
&&
pageFormat
.
width
>
pageFormat
.
height
);
PdfPage
_pdfPage
;
EdgeInsets
get
margin
{
if
(
_margin
!=
null
)
{
if
(
mustRotate
)
{
...
...
@@ -127,8 +137,12 @@ class Page {
@protected
void
generate
(
Document
document
)
{
final
PdfPage
pdfPage
=
PdfPage
(
document
.
document
,
pageFormat:
pageFormat
);
final
PdfGraphics
canvas
=
pdfPage
.
getGraphics
();
_pdfPage
=
PdfPage
(
document
.
document
,
pageFormat:
pageFormat
);
}
@protected
void
postProcess
(
Document
document
)
{
final
PdfGraphics
canvas
=
_pdfPage
.
getGraphics
();
final
EdgeInsets
_margin
=
margin
;
final
BoxConstraints
constraints
=
mustRotate
?
BoxConstraints
(
...
...
@@ -143,7 +157,7 @@ class Page {
inherited
[
calculatedTheme
.
runtimeType
]
=
calculatedTheme
;
final
Context
context
=
Context
(
document:
document
.
document
,
page:
pdfPage
,
page:
_
pdfPage
,
canvas:
canvas
,
inherited:
inherited
);
if
(
_build
!=
null
)
{
...
...
pdf/lib/widgets/multi_page.dart
View file @
3a91f21
...
...
@@ -36,8 +36,19 @@ class NewPage extends Widget {
}
}
class
_MultiPageInstance
{
const
_MultiPageInstance
(
{
@required
this
.
context
,
@required
this
.
constraints
,
@required
this
.
offsetStart
});
final
Context
context
;
final
BoxConstraints
constraints
;
final
double
offsetStart
;
}
class
MultiPage
extends
Page
{
const
MultiPage
(
MultiPage
(
{
PdfPageFormat
pageFormat
=
PdfPageFormat
.
a4
,
BuildListCallback
build
,
this
.
crossAxisAlignment
=
CrossAxisAlignment
.
start
,
...
...
@@ -61,6 +72,8 @@ class MultiPage extends Page {
final
BuildCallback
footer
;
final
List
<
_MultiPageInstance
>
_pages
=
<
_MultiPageInstance
>[];
void
_paintChild
(
Context
context
,
Widget
child
,
double
x
,
double
y
,
double
pageHeight
)
{
if
(
mustRotate
)
{
...
...
@@ -139,13 +152,17 @@ class MultiPage extends Page {
offsetEnd
=
_mustRotate
?
pageHeightMargin
-
_margin
.
left
:
_margin
.
bottom
;
_pages
.
add
(
_MultiPageInstance
(
context:
context
,
constraints:
constraints
,
offsetStart:
offsetStart
,
));
if
(
header
!=
null
)
{
final
Widget
headerWidget
=
header
(
context
);
if
(
headerWidget
!=
null
)
{
headerWidget
.
layout
(
context
,
constraints
,
parentUsesSize:
false
);
assert
(
headerWidget
.
box
!=
null
);
_paintChild
(
context
,
headerWidget
,
_margin
.
left
,
offsetStart
-
headerWidget
.
box
.
height
,
pageFormat
.
height
);
offsetStart
-=
headerWidget
.
box
.
height
;
}
}
...
...
@@ -155,8 +172,6 @@ class MultiPage extends Page {
if
(
footerWidget
!=
null
)
{
footerWidget
.
layout
(
context
,
constraints
,
parentUsesSize:
false
);
assert
(
footerWidget
.
box
!=
null
);
_paintChild
(
context
,
footerWidget
,
_margin
.
left
,
_margin
.
bottom
,
pageFormat
.
height
);
offsetEnd
+=
footerWidget
.
box
.
height
;
}
}
...
...
@@ -218,4 +233,33 @@ class MultiPage extends Page {
index
++;
}
}
@override
void
postProcess
(
Document
document
)
{
final
EdgeInsets
_margin
=
margin
;
for
(
_MultiPageInstance
page
in
_pages
)
{
if
(
header
!=
null
)
{
final
Widget
headerWidget
=
header
(
page
.
context
);
if
(
headerWidget
!=
null
)
{
headerWidget
.
layout
(
page
.
context
,
page
.
constraints
,
parentUsesSize:
false
);
assert
(
headerWidget
.
box
!=
null
);
_paintChild
(
page
.
context
,
headerWidget
,
_margin
.
left
,
page
.
offsetStart
-
headerWidget
.
box
.
height
,
pageFormat
.
height
);
}
}
if
(
footer
!=
null
)
{
final
Widget
footerWidget
=
footer
(
page
.
context
);
if
(
footerWidget
!=
null
)
{
footerWidget
.
layout
(
page
.
context
,
page
.
constraints
,
parentUsesSize:
false
);
assert
(
footerWidget
.
box
!=
null
);
_paintChild
(
page
.
context
,
footerWidget
,
_margin
.
left
,
_margin
.
bottom
,
pageFormat
.
height
);
}
}
}
}
}
...
...
pdf/lib/widgets/widget.dart
View file @
3a91f21
...
...
@@ -36,6 +36,9 @@ class Context {
int
get
pageNumber
=>
document
.
pdfPageList
.
pages
.
indexOf
(
page
)
+
1
;
/// Number of pages in the document.
/// This value is not available in a MultiPage body and will be equal to pageNumber.
/// But can be used in Header and Footer.
int
get
pagesCount
=>
document
.
pdfPageList
.
pages
.
length
;
Context
copyWith
(
...
...
Please
register
or
login
to post a comment