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
2023-01-26 16:35:41 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5643485a84292cb42b3d1864a52f36e86223e8e9
5643485a
1 parent
513de74e
Force Flutter 3.7
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
51 additions
and
52 deletions
pdf/lib/src/widgets/multi_page.dart
pdf/pubspec.yaml
printing/lib/printing_web.dart
printing/lib/src/preview/actions.dart
printing/lib/src/preview/controller.dart
printing/lib/src/preview/custom.dart
printing/lib/src/preview/pdf_preview.dart
printing/lib/src/preview/raster.dart
printing/lib/src/printing.dart
printing/lib/src/widget_wrapper.dart
printing/pubspec.yaml
pdf/lib/src/widgets/multi_page.dart
View file @
5643485
...
...
@@ -333,7 +333,7 @@ class MultiPage extends Page {
'You probably need a SpanningWidget or use a single page layout'
);
}
final
span
=
child
as
SpanningWidget
;
final
span
=
child
;
if
(
savedContext
!=
null
)
{
// Restore saved context
...
...
pdf/pubspec.yaml
View file @
5643485
...
...
@@ -9,7 +9,7 @@ screenshots:
version
:
3.9.0
environment
:
sdk
:
"
>=2.1
2
.0
<3.0.0"
sdk
:
"
>=2.1
8
.0
<3.0.0"
dependencies
:
archive
:
^3.1.0
...
...
printing/lib/printing_web.dart
View file @
5643485
...
...
@@ -317,10 +317,10 @@ class PrintingPlugin extends PrintingPlatform {
js
.
context
[
'document'
].
createElement
(
'canvas'
);
final
context
=
canvas
.
getContext
(
'2d'
)
as
html
.
CanvasRenderingContext2D
?;
final
_p
ages
=
final
computedP
ages
=
pages
??
Iterable
<
int
>.
generate
(
numPages
,
(
index
)
=>
index
);
for
(
final
pageIndex
in
_p
ages
)
{
for
(
final
pageIndex
in
computedP
ages
)
{
final
page
=
await
promiseToFuture
<
PdfJsPage
>(
doc
.
getPage
(
pageIndex
+
1
));
try
{
...
...
printing/lib/src/preview/actions.dart
View file @
5643485
...
...
@@ -237,14 +237,14 @@ class PdfPageFormatAction extends StatelessWidget {
final
theme
=
Theme
.
of
(
context
);
final
iconColor
=
theme
.
primaryIconTheme
.
color
??
Colors
.
white
;
final
data
=
PdfPreviewController
.
listen
(
context
);
final
_p
ageFormats
=
<
String
,
PdfPageFormat
>{...
pageFormats
};
final
allP
ageFormats
=
<
String
,
PdfPageFormat
>{...
pageFormats
};
var
format
=
data
.
pageFormat
;
final
orientation
=
data
.
horizontal
;
if
(!
_p
ageFormats
.
values
.
contains
(
data
.
pageFormat
))
{
if
(!
allP
ageFormats
.
values
.
contains
(
data
.
pageFormat
))
{
var
found
=
false
;
for
(
final
f
in
_p
ageFormats
.
values
)
{
for
(
final
f
in
allP
ageFormats
.
values
)
{
if
(
format
.
portrait
==
f
.
portrait
)
{
format
=
f
;
found
=
true
;
...
...
@@ -252,11 +252,11 @@ class PdfPageFormatAction extends StatelessWidget {
}
}
if
(!
found
)
{
_p
ageFormats
[
'---'
]
=
format
;
allP
ageFormats
[
'---'
]
=
format
;
}
}
final
keys
=
_p
ageFormats
.
keys
.
toList
()..
sort
();
final
keys
=
allP
ageFormats
.
keys
.
toList
()..
sort
();
return
DropdownButton
<
PdfPageFormat
>(
dropdownColor:
theme
.
primaryColor
,
...
...
@@ -266,10 +266,10 @@ class PdfPageFormatAction extends StatelessWidget {
),
value:
format
,
items:
List
<
DropdownMenuItem
<
PdfPageFormat
>>.
generate
(
_p
ageFormats
.
length
,
allP
ageFormats
.
length
,
(
int
index
)
{
final
key
=
keys
[
index
];
final
val
=
_p
ageFormats
[
key
]!;
final
val
=
allP
ageFormats
[
key
]!;
return
DropdownMenuItem
<
PdfPageFormat
>(
value:
val
,
child:
Text
(
key
,
style:
TextStyle
(
color:
iconColor
)),
...
...
printing/lib/src/preview/controller.dart
View file @
5643485
...
...
@@ -67,12 +67,9 @@ class PdfPreviewData extends ChangeNotifier {
PdfPageFormat
get
actualPageFormat
=>
_onComputeActualPageFormat
();
String
get
localPageFormat
{
// Flutter 3 workaround
// ignore: omit_local_variable_types
final
WidgetsBinding
?
wbi
=
WidgetsBinding
.
instance
;
final
locale
=
wbi
!.
window
.
locale
;
// ignore: unnecessary_cast
final
cc
=
(
locale
as
Locale
?)?.
countryCode
??
'US'
;
final
wbi
=
WidgetsBinding
.
instance
;
final
locale
=
wbi
.
window
.
locale
;
final
cc
=
locale
.
countryCode
??
'US'
;
if
(
cc
==
'US'
||
cc
==
'CA'
||
cc
==
'MX'
)
{
return
'Letter'
;
...
...
printing/lib/src/preview/custom.dart
View file @
5643485
...
...
@@ -157,9 +157,9 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
void
didChangeDependencies
()
{
if
(!
infoLoaded
)
{
infoLoaded
=
true
;
Printing
.
info
().
then
((
PrintingInfo
_i
nfo
)
{
Printing
.
info
().
then
((
PrintingInfo
printingI
nfo
)
{
setState
(()
{
info
=
_i
nfo
;
info
=
printingI
nfo
;
raster
();
});
});
...
...
@@ -182,8 +182,8 @@ class PdfPreviewCustomState extends State<PdfPreviewCustom>
return
_showError
(
error
!);
}
final
_info
=
info
;
if
(
_info
!=
null
&&
!
_info
.
canRaster
)
{
final
printingInfo
=
info
;
if
(
printingInfo
!=
null
&&
!
printingInfo
.
canRaster
)
{
return
_showError
(
_errorMessage
);
}
...
...
printing/lib/src/preview/pdf_preview.dart
View file @
5643485
...
...
@@ -228,10 +228,10 @@ class PdfPreview extends StatefulWidget {
final
CustomPdfPagesBuilder
?
_pagesBuilder
;
@override
_PdfPreviewState
createState
()
=>
_
PdfPreviewState
();
PdfPreviewState
createState
()
=>
PdfPreviewState
();
}
class
_
PdfPreviewState
extends
State
<
PdfPreview
>
{
class
PdfPreviewState
extends
State
<
PdfPreview
>
{
final
previewWidget
=
GlobalKey
<
PdfPreviewCustomState
>();
late
PdfPreviewData
previewData
;
...
...
@@ -305,9 +305,9 @@ class _PdfPreviewState extends State<PdfPreview> {
void
didChangeDependencies
()
{
if
(!
infoLoaded
)
{
infoLoaded
=
true
;
Printing
.
info
().
then
((
PrintingInfo
_i
nfo
)
{
Printing
.
info
().
then
((
PrintingInfo
printingI
nfo
)
{
setState
(()
{
info
=
_i
nfo
;
info
=
printingI
nfo
;
});
});
}
...
...
printing/lib/src/preview/raster.dart
View file @
5643485
...
...
@@ -100,10 +100,10 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
}
_rastering
=
true
;
Uint8List
_
doc
;
Uint8List
doc
;
final
_info
=
info
;
if
(
_info
!=
null
&&
!
_info
.
canRaster
)
{
final
printingInfo
=
info
;
if
(
printingInfo
!=
null
&&
!
printingInfo
.
canRaster
)
{
assert
(()
{
if
(
kIsWeb
)
{
FlutterError
.
reportError
(
FlutterErrorDetails
(
...
...
@@ -122,7 +122,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
}
try
{
_
doc
=
await
widget
.
build
(
pageFormat
);
doc
=
await
widget
.
build
(
pageFormat
);
}
catch
(
exception
,
stack
)
{
InformationCollector
?
collector
;
...
...
@@ -159,7 +159,7 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
try
{
var
pageNum
=
0
;
await
for
(
final
PdfRaster
page
in
Printing
.
raster
(
_
doc
,
doc
,
dpi:
dpi
,
pages:
widget
.
pages
,
))
{
...
...
printing/lib/src/printing.dart
View file @
5643485
...
...
@@ -74,9 +74,9 @@ mixin Printing {
Rect
?
bounds
,
String
?
title
,
})
async
{
final
_i
nfo
=
await
info
();
final
printingI
nfo
=
await
info
();
if
(
_i
nfo
.
canListPrinters
)
{
if
(
printingI
nfo
.
canListPrinters
)
{
final
printers
=
await
listPrinters
();
printers
.
sort
((
a
,
b
)
{
if
(
a
.
isDefault
)
{
...
...
@@ -88,6 +88,7 @@ mixin Printing {
return
a
.
name
.
compareTo
(
b
.
name
);
});
// ignore: use_build_context_synchronously
return
await
showDialog
<
Printer
>(
context:
context
,
builder:
(
context
)
=>
SimpleDialog
(
...
...
printing/lib/src/widget_wrapper.dart
View file @
5643485
...
...
@@ -144,31 +144,32 @@ class WidgetWrapper extends pw.ImageProvider {
child:
widget
,
);
final
_properties
=
DiagnosticPropertiesBuilder
();
widget
.
debugFillProperties
(
_properties
);
final
prop
=
DiagnosticPropertiesBuilder
();
widget
.
debugFillProperties
(
prop
);
if
(
_properties
.
properties
.
isEmpty
)
{
if
(
prop
.
properties
.
isEmpty
)
{
throw
ErrorDescription
(
'Unable to get the widget properties'
);
}
final
_constraints
=
_properties
.
properties
final
computedConstraints
=
prop
.
properties
.
whereType
<
DiagnosticsProperty
<
BoxConstraints
>>()
.
first
.
value
;
if
(
_constraints
==
null
||
!
_constraints
.
hasBoundedWidth
||
!
_constraints
.
hasBoundedWidth
)
{
if
(
computedConstraints
==
null
||
!
computedConstraints
.
hasBoundedWidth
||
!
computedConstraints
.
hasBoundedWidth
)
{
throw
Exception
(
'Unable to convert an unbounded widget.'
);
}
final
_
repaintBoundary
=
RenderRepaintBoundary
();
final
repaintBoundary
=
RenderRepaintBoundary
();
final
renderView
=
RenderView
(
child:
RenderPositionedBox
(
alignment:
Alignment
.
center
,
child:
_
repaintBoundary
),
alignment:
Alignment
.
center
,
child:
repaintBoundary
),
configuration:
ViewConfiguration
(
size:
Size
(
_constraints
.
maxWidth
,
_constraints
.
maxHeight
),
size:
Size
(
computedConstraints
.
maxWidth
,
computedConstraints
.
maxHeight
),
devicePixelRatio:
ui
.
window
.
devicePixelRatio
),
window:
ui
.
window
,
);
...
...
@@ -177,8 +178,8 @@ class WidgetWrapper extends pw.ImageProvider {
renderView
.
prepareInitialFrame
();
final
buildOwner
=
BuildOwner
(
focusManager:
FocusManager
());
final
_rootElement
=
RenderObjectToWidgetAdapter
<
RenderBox
>(
container:
_repaintBoundary
,
final
rootElement
=
RenderObjectToWidgetAdapter
<
RenderBox
>(
container:
repaintBoundary
,
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
IntrinsicHeight
(
child:
IntrinsicWidth
(
child:
widget
)),
...
...
@@ -186,7 +187,7 @@ class WidgetWrapper extends pw.ImageProvider {
).
attachToRenderTree
(
buildOwner
);
buildOwner
..
buildScope
(
_
rootElement
)
..
buildScope
(
rootElement
)
..
finalizeTree
();
pipelineOwner
...
...
@@ -194,7 +195,7 @@ class WidgetWrapper extends pw.ImageProvider {
..
flushCompositingBits
()
..
flushPaint
();
final
image
=
await
_
repaintBoundary
.
toImage
(
pixelRatio:
pixelRatio
);
final
image
=
await
repaintBoundary
.
toImage
(
pixelRatio:
pixelRatio
);
final
bytes
=
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
rawRgba
);
if
(
bytes
==
null
)
{
throw
Exception
(
'Unable to read image data'
);
...
...
printing/pubspec.yaml
View file @
5643485
...
...
@@ -12,8 +12,8 @@ screenshots:
version
:
5.10.0
environment
:
sdk
:
"
>=2.12.0
<3.0.0"
flutter
:
"
>=1.16.0"
sdk
:
"
>=2.18.0
<3.0.0"
flutter
:
"
>=3.7.0"
dependencies
:
ffi
:
"
>=1.1.0
<3.0.0"
...
...
@@ -22,17 +22,17 @@ dependencies:
flutter_web_plugins
:
sdk
:
flutter
http
:
^0.13.0
image
:
^4.0.0
image
:
^4.0.0
2
js
:
^0.6.3
meta
:
"
>=1.3.0
<2.0.0"
pdf
:
^3.9.0
plugin_platform_interface
:
^2.
0
.0
plugin_platform_interface
:
^2.
1
.0
dev_dependencies
:
flutter_lints
:
^
1.0.4
flutter_lints
:
^
2.0.1
flutter_test
:
sdk
:
flutter
mockito
:
^5.
0.0
mockito
:
^5.
3.2
dependency_overrides
:
pdf
:
...
...
Please
register
or
login
to post a comment