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-03-05 16:46:18 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3b58cca8d8291d4f00dc1c57f681b8485cdca956
3b58cca8
1 parent
6358dd51
Implement table row vertical alignment
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
7 deletions
pdf/CHANGELOG.md
pdf/lib/widgets/table.dart
pdf/test/widget_table_test.dart
test/golden/widgets-table.pdf
pdf/CHANGELOG.md
View file @
3b58cca
...
...
@@ -3,6 +3,7 @@
## 1.6.0
-
Improve Annotations
-
Implement table row vertical alignment
## 1.5.0
...
...
pdf/lib/widgets/table.dart
View file @
3b58cca
...
...
@@ -21,13 +21,19 @@ part of widget;
/// A horizontal group of cells in a [Table].
@immutable
class
TableRow
{
const
TableRow
({
this
.
children
,
this
.
repeat
=
false
});
const
TableRow
({
this
.
children
,
this
.
repeat
=
false
,
this
.
verticalAlignment
,
});
/// The widgets that comprise the cells in this row.
final
List
<
Widget
>
children
;
/// Repeat this row on all pages
final
bool
repeat
;
final
TableCellVerticalAlignment
verticalAlignment
;
}
enum
TableCellVerticalAlignment
{
bottom
,
middle
,
top
}
...
...
@@ -189,6 +195,7 @@ class Table extends Widget implements SpanningWidget {
this
.
tableWidth
=
TableWidth
.
max
})
:
assert
(
children
!=
null
),
assert
(
defaultColumnWidth
!=
null
),
assert
(
defaultVerticalAlignment
!=
null
),
super
();
factory
Table
.
fromTextArray
({
...
...
@@ -355,22 +362,44 @@ class Table extends Widget implements SpanningWidget {
// Compute final y position
index
=
0
;
int
heightIndex
=
0
;
for
(
TableRow
row
in
children
)
{
if
(
index
++
<
_context
.
firstLine
&&
!
row
.
repeat
)
{
continue
;
}
final
TableCellVerticalAlignment
align
=
row
.
verticalAlignment
??
defaultVerticalAlignment
;
for
(
Widget
child
in
row
.
children
)
{
double
childY
;
switch
(
align
)
{
case
TableCellVerticalAlignment
.
bottom
:
childY
=
totalHeight
-
child
.
box
.
y
-
_heights
[
heightIndex
];
break
;
case
TableCellVerticalAlignment
.
middle
:
childY
=
totalHeight
-
child
.
box
.
y
-
(
_heights
[
heightIndex
]
+
child
.
box
.
height
)
/
2
;
break
;
case
TableCellVerticalAlignment
.
top
:
childY
=
totalHeight
-
child
.
box
.
y
-
child
.
box
.
height
;
break
;
}
child
.
box
=
PdfRect
(
child
.
box
.
x
,
totalHeight
-
child
.
box
.
y
-
child
.
box
.
height
,
child
.
box
.
width
,
child
.
box
.
height
);
child
.
box
.
x
,
childY
,
child
.
box
.
width
,
child
.
box
.
height
,
);
}
if
(
index
>=
_context
.
lastLine
)
{
break
;
}
heightIndex
++;
}
box
=
PdfRect
(
0
,
0
,
totalWidth
,
totalHeight
);
...
...
pdf/test/widget_table_test.dart
View file @
3b58cca
...
...
@@ -145,6 +145,47 @@ void main() {
));
});
test
(
'Table Widget TableCellVerticalAlignment'
,
()
{
pdf
.
addPage
(
MultiPage
(
build:
(
Context
context
)
{
return
<
Widget
>[
Table
(
defaultColumnWidth:
const
FixedColumnWidth
(
20
),
children:
List
<
TableRow
>.
generate
(
TableCellVerticalAlignment
.
values
.
length
,
(
int
index
)
{
final
TableCellVerticalAlignment
align
=
TableCellVerticalAlignment
.
values
[
index
%
TableCellVerticalAlignment
.
values
.
length
];
return
TableRow
(
verticalAlignment:
align
,
children:
<
Widget
>[
Container
(
child:
Text
(
'Vertical'
),
color:
PdfColors
.
red
,
),
Container
(
child:
Text
(
'alignment
$index
'
),
color:
PdfColors
.
yellow
,
height:
60
,
),
Container
(
child:
Text
(
align
.
toString
().
substring
(
27
)),
color:
PdfColors
.
green
,
),
],
);
},
),
),
];
},
),
);
});
tearDownAll
(()
{
final
File
file
=
File
(
'widgets-table.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
...
...
test/golden/widgets-table.pdf
View file @
3b58cca
No preview for this file type
Please
register
or
login
to post a comment