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
2021-03-08 17:02:58 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6ee4d26a6e72c00236dcf832d084f59b799ce110
6ee4d26a
1 parent
e59b0d05
Simplify platform interface
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
64 deletions
printing/lib/printing_web.dart
printing/lib/src/interface.dart
printing/lib/src/method_channel.dart
printing/lib/src/print_job.dart
printing/lib/src/printing.dart
printing/test/printing_test.dart
printing/lib/printing_web.dart
View file @
6ee4d26
...
...
@@ -59,9 +59,11 @@ class PrintingPlugin extends PrintingPlatform {
@override
Future
<
bool
>
layoutPdf
(
Printer
?
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
bool
dynamicLayout
,
)
async
{
final
result
=
await
onLayout
(
format
);
...
...
@@ -158,16 +160,6 @@ class PrintingPlugin extends PrintingPlatform {
}
@override
Future
<
bool
>
directPrintPdf
(
Printer
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
)
{
return
layoutPdf
(
onLayout
,
name
,
format
);
}
@override
Future
<
List
<
Printer
>>
listPrinters
()
{
throw
UnimplementedError
();
}
...
...
printing/lib/src/interface.dart
View file @
6ee4d26
...
...
@@ -60,6 +60,7 @@ abstract class PrintingPlatform extends PlatformInterface {
/// and false if it is canceled.
/// throws an exception in case of error
Future
<
bool
>
layoutPdf
(
Printer
?
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
...
...
@@ -71,18 +72,6 @@ abstract class PrintingPlatform extends PlatformInterface {
/// Opens the native printer picker interface, and returns the URL of the selected printer.
Future
<
Printer
?>
pickPrinter
(
Rect
bounds
);
/// Prints a Pdf document to a specific local printer with no UI
///
/// returns a future with a `bool` set to true if the document is printed
/// and false if it is canceled.
/// throws an exception in case of error
Future
<
bool
>
directPrintPdf
(
Printer
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
);
/// Displays a platform popup to share the Pdf document to another application
Future
<
bool
>
sharePdf
(
Uint8List
bytes
,
...
...
printing/lib/src/method_channel.dart
View file @
6ee4d26
...
...
@@ -15,7 +15,6 @@
*/
import
'dart:async'
;
import
'dart:io'
;
import
'dart:typed_data'
;
import
'package:flutter/rendering.dart'
show
Rect
;
...
...
@@ -62,14 +61,14 @@ class MethodChannelPrinting extends PrintingPlatform {
try
{
bytes
=
await
job
.
onLayout
!(
format
);
}
catch
(
e
)
{
if
(
Platform
.
isMacOS
||
Platform
.
isIOS
)
{
if
(
job
.
useFFI
)
{
return
setErrorFfi
(
job
,
e
.
toString
());
}
rethrow
;
}
if
(
Platform
.
isMacOS
||
Platform
.
isIOS
)
{
if
(
job
.
useFFI
)
{
return
setDocumentFfi
(
job
,
bytes
);
}
...
...
@@ -139,6 +138,7 @@ class MethodChannelPrinting extends PrintingPlatform {
@override
Future
<
bool
>
layoutPdf
(
Printer
?
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
...
...
@@ -149,6 +149,7 @@ class MethodChannelPrinting extends PrintingPlatform {
);
final
params
=
<
String
,
dynamic
>{
if
(
printer
!=
null
)
'printer'
:
printer
.
url
,
'name'
:
name
,
'job'
:
job
.
index
,
'width'
:
format
.
width
,
...
...
@@ -199,37 +200,6 @@ class MethodChannelPrinting extends PrintingPlatform {
}
@override
Future
<
bool
>
directPrintPdf
(
Printer
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
)
async
{
final
job
=
_printJobs
.
add
(
onCompleted:
Completer
<
bool
>(),
onLayout:
onLayout
,
);
final
params
=
<
String
,
dynamic
>{
'name'
:
name
,
'printer'
:
printer
.
url
,
'width'
:
format
.
width
,
'height'
:
format
.
height
,
'marginLeft'
:
format
.
marginLeft
,
'marginTop'
:
format
.
marginTop
,
'marginRight'
:
format
.
marginRight
,
'marginBottom'
:
format
.
marginBottom
,
'job'
:
job
.
index
,
};
await
_channel
.
invokeMethod
<
int
>(
'printPdf'
,
params
);
try
{
return
await
job
.
onCompleted
!.
future
;
}
finally
{
_printJobs
.
remove
(
job
.
index
);
}
}
@override
Future
<
bool
>
sharePdf
(
Uint8List
bytes
,
String
filename
,
...
...
printing/lib/src/print_job.dart
View file @
6ee4d26
...
...
@@ -15,6 +15,7 @@
*/
import
'dart:async'
;
import
'dart:io'
;
import
'dart:typed_data'
;
import
'callback.dart'
;
...
...
@@ -29,6 +30,7 @@ class PrintJob {
this
.
onHtmlRendered
,
this
.
onCompleted
,
this
.
onPageRasterized
,
required
this
.
useFFI
,
});
/// Callback used when calling Printing.layoutPdf()
...
...
@@ -45,6 +47,9 @@ class PrintJob {
/// The Job number
final
int
index
;
/// Use the FFI side-channel to send the PDF data
final
bool
useFFI
;
}
/// Represents a list of print jobs
...
...
@@ -69,6 +74,7 @@ class PrintJobs {
onHtmlRendered:
onHtmlRendered
,
onCompleted:
onCompleted
,
onPageRasterized:
onPageRasterized
,
useFFI:
Platform
.
isMacOS
||
Platform
.
isIOS
,
);
_printJobs
[
job
.
index
]
=
job
;
return
job
;
...
...
printing/lib/src/printing.dart
View file @
6ee4d26
...
...
@@ -41,7 +41,12 @@ mixin Printing {
String
name
=
'Document'
,
PdfPageFormat
format
=
PdfPageFormat
.
standard
,
})
{
return
PrintingPlatform
.
instance
.
layoutPdf
(
onLayout
,
name
,
format
);
return
PrintingPlatform
.
instance
.
layoutPdf
(
null
,
onLayout
,
name
,
format
,
);
}
/// Enumerate the available printers on the system.
...
...
@@ -118,7 +123,7 @@ mixin Printing {
String
name
=
'Document'
,
PdfPageFormat
format
=
PdfPageFormat
.
standard
,
})
{
return
PrintingPlatform
.
instance
.
directPrin
tPdf
(
return
PrintingPlatform
.
instance
.
layou
tPdf
(
printer
,
onLayout
,
name
,
...
...
printing/test/printing_test.dart
View file @
6ee4d26
...
...
@@ -108,7 +108,12 @@ class MockPrinting extends Mock
Future
<
PrintingInfo
>
info
()
async
=>
const
PrintingInfo
();
@override
Future
<
bool
>
layoutPdf
(
onLayout
,
String
name
,
PdfPageFormat
format
)
async
=>
Future
<
bool
>
layoutPdf
(
Printer
?
printer
,
LayoutCallback
onLayout
,
String
name
,
PdfPageFormat
format
,
)
async
=>
true
;
@override
...
...
@@ -119,11 +124,6 @@ class MockPrinting extends Mock
Future
<
Printer
?>
pickPrinter
(
Rect
bounds
)
async
=>
null
;
@override
Future
<
bool
>
directPrintPdf
(
Printer
printer
,
onLayout
,
String
name
,
PdfPageFormat
format
)
async
=>
true
;
@override
Stream
<
PdfRaster
>
raster
(
Uint8List
document
,
List
<
int
>?
pages
,
double
dpi
)
async
*
{}
...
...
Please
register
or
login
to post a comment