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-10-19 08:09:04 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
329ab53bdde99a4937d483d7bde1bf9688dc473d
329ab53b
1 parent
89e2401b
Implement ListView.builder and ListView.separated
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
182 additions
and
14 deletions
pdf/CHANGELOG.md
pdf/lib/widgets/flex.dart
pdf/pubspec.yaml
pdf/test/all_tests.dart
pdf/test/widget_flex_test.dart
pdf/CHANGELOG.md
View file @
329ab53
# Changelog
## 1.3.23
-
Implement ListView.builder and ListView.separated
## 1.3.22
-
Fix Text alignment
...
...
pdf/lib/widgets/flex.dart
View file @
329ab53
...
...
@@ -546,17 +546,99 @@ class Spacer extends StatelessWidget {
}
}
class
ListView
extends
Flex
{
ListView
(
{
Axis
direction
=
Axis
.
vertical
,
// EdgeInsets padding,
// double spacing = 0.0,
List
<
Widget
>
children
=
const
<
Widget
>[]})
:
super
(
direction:
direction
,
mainAxisAlignment:
MainAxisAlignment
.
start
,
mainAxisSize:
MainAxisSize
.
max
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
verticalDirection:
VerticalDirection
.
down
,
children:
children
);
typedef
IndexedWidgetBuilder
=
Widget
Function
(
Context
context
,
int
index
);
class
ListView
extends
StatelessWidget
{
ListView
({
this
.
direction
=
Axis
.
vertical
,
this
.
reverse
=
false
,
this
.
spacing
=
0
,
this
.
padding
,
this
.
children
=
const
<
Widget
>[],
})
:
itemBuilder
=
null
,
separatorBuilder
=
null
,
itemCount
=
children
.
length
,
super
();
ListView
.
builder
({
this
.
direction
=
Axis
.
vertical
,
this
.
reverse
=
false
,
this
.
spacing
=
0
,
this
.
padding
,
@required
this
.
itemBuilder
,
@required
this
.
itemCount
,
})
:
children
=
null
,
separatorBuilder
=
null
,
super
();
ListView
.
separated
({
this
.
direction
=
Axis
.
vertical
,
this
.
reverse
=
false
,
this
.
padding
,
@required
this
.
itemBuilder
,
@required
this
.
separatorBuilder
,
@required
this
.
itemCount
,
})
:
children
=
null
,
spacing
=
null
,
super
();
final
Axis
direction
;
final
EdgeInsets
padding
;
final
double
spacing
;
final
bool
reverse
;
final
IndexedWidgetBuilder
itemBuilder
;
final
IndexedWidgetBuilder
separatorBuilder
;
final
List
<
Widget
>
children
;
final
int
itemCount
;
Widget
_getItem
(
Context
context
,
int
index
)
{
return
children
==
null
?
itemBuilder
(
context
,
index
)
:
children
[
index
];
}
Widget
_getSeparator
(
Context
context
,
int
index
)
{
return
spacing
==
null
?
separatorBuilder
(
context
,
index
)
:
direction
==
Axis
.
vertical
?
SizedBox
(
height:
spacing
)
:
SizedBox
(
width:
spacing
);
}
@override
Widget
build
(
Context
context
)
{
final
List
<
Widget
>
_children
=
<
Widget
>[];
if
(
reverse
)
{
for
(
int
index
=
itemCount
-
1
;
index
>=
0
;
index
--)
{
_children
.
add
(
_getItem
(
context
,
index
));
if
(
spacing
!=
0
&&
index
>
0
)
{
_children
.
add
(
_getSeparator
(
context
,
index
));
}
}
}
else
{
for
(
int
index
=
0
;
index
<
itemCount
;
index
++)
{
_children
.
add
(
_getItem
(
context
,
index
));
if
(
spacing
!=
0
&&
index
<
itemCount
-
1
)
{
_children
.
add
(
_getSeparator
(
context
,
index
));
}
}
}
final
Widget
widget
=
Flex
(
direction:
direction
,
mainAxisAlignment:
MainAxisAlignment
.
start
,
mainAxisSize:
MainAxisSize
.
max
,
crossAxisAlignment:
CrossAxisAlignment
.
center
,
verticalDirection:
VerticalDirection
.
down
,
children:
_children
,
);
if
(
padding
!=
null
)
{
return
Padding
(
padding:
padding
,
child:
widget
,
);
}
return
widget
;
}
}
...
...
pdf/pubspec.yaml
View file @
329ab53
...
...
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
1.3.2
2
version
:
1.3.2
3
environment
:
sdk
:
"
>=2.1.0
<3.0.0"
...
...
pdf/test/all_tests.dart
View file @
329ab53
...
...
@@ -29,6 +29,7 @@ import 'type1_test.dart' as type1;
import
'widget_basic_test.dart'
as
widget_basic
;
import
'widget_clip_test.dart'
as
widget_clip
;
import
'widget_container_test.dart'
as
widget_container
;
import
'widget_flex_test.dart'
as
widget_flex
;
import
'widget_multipage_test.dart'
as
widget_multipage
;
import
'widget_table_test.dart'
as
widget_table
;
import
'widget_test.dart'
as
widget
;
...
...
@@ -51,6 +52,7 @@ void main() {
widget_basic
.
main
();
widget_clip
.
main
();
widget_container
.
main
();
widget_flex
.
main
();
widget_multipage
.
main
();
widget_table
.
main
();
widget_text
.
main
();
...
...
pdf/test/widget_flex_test.dart
0 → 100644
View file @
329ab53
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
'dart:io'
;
import
'package:pdf/pdf.dart'
;
import
'package:pdf/widgets.dart'
;
import
'package:test/test.dart'
;
Document
pdf
;
void
main
(
)
{
setUpAll
(()
{
Document
.
debug
=
true
;
pdf
=
Document
();
});
test
(
'Flex Widgets ListView'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
ListView
(
spacing:
20
,
padding:
const
EdgeInsets
.
all
(
10
),
children:
<
Widget
>[
Text
(
'Line 1'
),
Text
(
'Line 2'
),
Text
(
'Line 3'
),
],
),
),
);
});
test
(
'Flex Widgets ListView.builder'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
ListView
.
builder
(
itemBuilder:
(
Context
context
,
int
index
)
=>
Text
(
'Line
$index
'
),
itemCount:
30
,
spacing:
2
,
reverse:
true
,
),
),
);
});
test
(
'Flex Widgets ListView.separated'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
ListView
.
separated
(
separatorBuilder:
(
Context
context
,
int
index
)
=>
Container
(
color:
PdfColors
.
grey
,
height:
0.5
,
margin:
const
EdgeInsets
.
symmetric
(
vertical:
10
),
),
itemBuilder:
(
Context
context
,
int
index
)
=>
Text
(
'Line
$index
'
),
itemCount:
10
,
),
),
);
});
tearDownAll
(()
{
final
File
file
=
File
(
'widgets-flex.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
});
}
...
...
Please
register
or
login
to post a comment