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
Carsten Fregin
2022-12-02 15:07:35 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
David PHAM-VAN
2023-01-15 14:25:40 -0400
Commit
4cda7b84cab33387067e3a221ba3a74f5f077f09
4cda7b84
1 parent
da16bf4b
Add Choice Field
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
0 deletions
pdf/CHANGELOG.md
pdf/lib/src/pdf/obj/annotation.dart
pdf/lib/src/widgets/forms.dart
pdf/test/widget_form_test.dart
test/golden/widgets-form.pdf
pdf/CHANGELOG.md
View file @
4cda7b8
...
...
@@ -9,6 +9,7 @@
-
Update Image dependency
-
Fix lints
-
Add options to customise border in Dataset widget
[
838
]
-
Add Choice Field
[
Carsten Fregin
]
## 3.8.4
...
...
pdf/lib/src/pdf/obj/annotation.dart
View file @
4cda7b8
...
...
@@ -31,6 +31,73 @@ import 'object.dart';
import
'object_dict.dart'
;
import
'page.dart'
;
class
PdfChoiceField
extends
PdfAnnotWidget
{
PdfChoiceField
({
required
PdfRect
rect
,
required
this
.
textColor
,
required
this
.
font
,
required
this
.
fontSize
,
required
this
.
items
,
String
?
fieldName
,
this
.
value
,
this
.
defaultValue
,
})
:
super
(
rect:
rect
,
fieldType:
'/Ch'
,
fieldName:
fieldName
,
);
final
List
<
String
>
items
;
final
PdfColor
textColor
;
final
String
?
value
;
final
String
?
defaultValue
;
final
Set
<
PdfFieldFlags
>?
fieldFlags
=
{
PdfFieldFlags
.
combo
,
};
final
PdfFont
font
;
final
double
fontSize
;
@override
void
build
(
PdfPage
page
,
PdfObject
object
,
PdfDict
params
)
{
super
.
build
(
page
,
object
,
params
);
// What is /F?
//params['/F'] = const PdfNum(4);
params
[
'/Ff'
]
=
PdfNum
(
fieldFlagsValue
);
params
[
'/Opt'
]
=
PdfArray
<
PdfString
>(
items
.
map
((
e
)
=>
PdfString
.
fromString
(
e
)).
toList
());
if
(
defaultValue
!=
null
)
{
params
[
'/DV'
]
=
PdfString
.
fromString
(
defaultValue
!);
}
if
(
value
!=
null
)
{
params
[
'/V'
]
=
PdfString
.
fromString
(
value
!);
}
else
{
params
[
'/V'
]
=
const
PdfNull
();
}
final
buf
=
PdfStream
();
final
g
=
PdfGraphics
(
page
,
buf
);
g
.
setFillColor
(
textColor
);
g
.
setFont
(
font
,
fontSize
);
params
[
'/DA'
]
=
PdfSecString
.
fromStream
(
object
,
buf
);
// What is /TU? Tooltip?
//params['/TU'] = PdfString.fromString('Select from list');
}
int
get
fieldFlagsValue
{
if
(
fieldFlags
==
null
||
fieldFlags
!.
isEmpty
)
{
return
0
;
}
return
fieldFlags
!
.
map
<
int
>((
PdfFieldFlags
e
)
=>
1
<<
e
.
index
)
.
reduce
((
int
a
,
int
b
)
=>
a
|
b
);
}
}
class
PdfAnnot
extends
PdfObjectDict
{
PdfAnnot
(
this
.
pdfPage
,
this
.
annot
)
:
super
(
pdfPage
.
pdfDocument
,
type:
'/Annot'
)
{
...
...
pdf/lib/src/widgets/forms.dart
View file @
4cda7b8
...
...
@@ -31,6 +31,46 @@ import 'text_style.dart';
import
'theme.dart'
;
import
'widget.dart'
;
class
ChoiceField
extends
StatelessWidget
{
ChoiceField
({
this
.
width
=
120
,
this
.
height
=
13
,
this
.
textStyle
,
required
this
.
name
,
required
this
.
items
,
this
.
value
,
});
final
String
name
;
final
TextStyle
?
textStyle
;
final
double
width
;
final
double
height
;
final
List
<
String
>
items
;
final
String
?
value
;
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
final
_textStyle
=
Theme
.
of
(
context
).
defaultTextStyle
.
merge
(
textStyle
);
final
pdfRect
=
context
.
localToGlobal
(
box
!);
final
bf
=
PdfChoiceField
(
textColor:
_textStyle
.
color
!,
fieldName:
name
,
value:
value
,
font:
_textStyle
.
font
!.
getFont
(
context
),
fontSize:
_textStyle
.
fontSize
!,
items:
items
,
rect:
pdfRect
,
);
PdfAnnot
(
context
.
page
,
bf
);
}
@override
Widget
build
(
Context
context
)
{
return
SizedBox
(
width:
width
,
height:
height
);
}
}
class
Checkbox
extends
SingleChildWidget
{
Checkbox
({
required
this
.
value
,
...
...
pdf/test/widget_form_test.dart
View file @
4cda7b8
...
...
@@ -98,6 +98,17 @@ void main() {
Decorated
(
child:
TextField
(
name:
'Address'
)),
//
SizedBox
(
width:
double
.
infinity
,
height:
10
),
Label
(
label:
'ChoiceField:'
,
width:
100
),
Decorated
(
child:
ChoiceField
(
name:
'Test Choice'
,
items:
[
'One'
,
'Two'
,
'Blue'
,
'Yellow'
,
'Test äöüß'
,
])),
//
SizedBox
(
width:
double
.
infinity
,
height:
10
),
//
Label
(
label:
'Postcode:'
,
width:
100
),
Decorated
(
...
...
@@ -114,6 +125,7 @@ void main() {
name:
'Country'
,
color:
PdfColors
.
blue
,
)),
//
SizedBox
(
width:
double
.
infinity
,
height:
10
),
//
...
...
test/golden/widgets-form.pdf
View file @
4cda7b8
No preview for this file type
Please
register
or
login
to post a comment