David PHAM-VAN

Merge branch 'deepak786-share_adjustments'

# Changelog
## 5.0.5
## 5.1.0
- Fix PdfPreview timer dispose [wwl901215]
- Remove unnecessary _raster call in PdfPreview [yaymalaga]
- Added subject, body and email parameters in sharePdf [Deepak]
- Subject, body and emails parameter to pdf preview [Deepak]
## 5.0.4
... ...
... ... @@ -49,7 +49,10 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
case "sharePdf": {
final byte[] document = call.argument("doc");
final String name = call.argument("name");
PrintingJob.sharePdf(activity, document, name);
final String subject = call.argument("subject");
final String body = call.argument("body");
final ArrayList<String> emails = call.argument("emails");
PrintingJob.sharePdf(activity, document, name, subject, body, emails);
result.success(1);
break;
}
... ...
... ... @@ -207,7 +207,8 @@ public class PrintingJob extends PrintDocumentAdapter {
printing.onCompleted(PrintingJob.this, false, message);
}
static void sharePdf(final Context context, final byte[] data, final String name) {
static void sharePdf(final Context context, final byte[] data, final String name,
final String subject, final String body, final ArrayList<String> emails) {
assert name != null;
try {
... ... @@ -233,6 +234,10 @@ public class PrintingJob extends PrintDocumentAdapter {
shareIntent.setType("application/pdf");
shareIntent.putExtra(Intent.EXTRA_STREAM, apkURI);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
shareIntent.putExtra(Intent.EXTRA_TEXT, body);
shareIntent.putExtra(
Intent.EXTRA_EMAIL, emails != null ? emails.toArray(new String[0]) : null);
Intent chooserIntent = Intent.createChooser(shareIntent, null);
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(
chooserIntent, PackageManager.MATCH_DEFAULT_ONLY);
... ...
... ... @@ -186,7 +186,7 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
)
}
static func sharePdf(data: Data, withSourceRect rect: CGRect, andName name: String) {
static func sharePdf(data: Data, withSourceRect rect: CGRect, andName name: String, subject: String?, body: String?) {
let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
let fileURL = tmpDirURL.appendingPathComponent(name)
... ... @@ -197,7 +197,8 @@ public class PrintJob: UIPrintPageRenderer, UIPrintInteractionControllerDelegate
return
}
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
let activityViewController = UIActivityViewController(activityItems: [fileURL, body], applicationActivities: nil)
activityViewController.setValue(subject, forKey: "subject")
if UI_USER_INTERFACE_IDIOM() == .pad {
let controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController
activityViewController.popoverPresentationController?.sourceView = controller?.view
... ...
... ... @@ -84,7 +84,9 @@ public class PrintingPlugin: NSObject, FlutterPlugin {
width: CGFloat((args["w"] as? NSNumber)?.floatValue ?? 0.0),
height: CGFloat((args["h"] as? NSNumber)?.floatValue ?? 0.0)
),
andName: args["name"] as! String
andName: args["name"] as! String,
subject: args["subject"] as? String,
body: args["body"] as? String
)
result(NSNumber(value: 1))
} else if call.method == "convertHtml" {
... ...
... ... @@ -159,6 +159,9 @@ class PrintingPlugin extends PrintingPlatform {
Uint8List bytes,
String filename,
Rect bounds,
String? subject,
String? body,
List<String>? emails,
) async {
final pdfFile = html.Blob(
<Uint8List>[Uint8List.fromList(bytes)],
... ...
... ... @@ -73,11 +73,26 @@ abstract class PrintingPlatform extends PlatformInterface {
/// Opens the native printer picker interface, and returns the URL of the selected printer.
Future<Printer?> pickPrinter(Rect bounds);
/// Displays a platform popup to share the Pdf document to another application
/// Displays a platform popup to share the Pdf document to another application.
///
/// [subject] will be the email subject if selected application is email.
///
/// [body] will be the extra text that can be shared along with the Pdf document.
/// For email application [body] will be the email body text.
///
/// [emails] will be the list of emails to which you want to share the Pdf document.
/// If the selected application is email application then the these [emails] will be
/// filled in the to address.
///
/// [subject] and [body] will only work for Android and iOS platforms.
/// [emails] will only work for Android Platform.
Future<bool> sharePdf(
Uint8List bytes,
String filename,
Rect bounds,
String? subject,
String? body,
List<String>? emails,
);
/// Convert an html document to a pdf data
... ...
... ... @@ -225,10 +225,16 @@ class MethodChannelPrinting extends PrintingPlatform {
Uint8List bytes,
String filename,
Rect bounds,
String? subject,
String? body,
List<String>? emails,
) async {
final params = <String, dynamic>{
'doc': Uint8List.fromList(bytes),
'name': filename,
'subject': subject,
'body': body,
'emails': emails,
'x': bounds.left,
'y': bounds.top,
'w': bounds.width,
... ...
... ... @@ -36,6 +36,9 @@ class PdfPreview extends StatefulWidget {
this.useActions = true,
this.pages,
this.dynamicLayout = true,
this.shareActionExtraBody,
this.shareActionExtraSubject,
this.shareActionExtraEmails,
}) : super(key: key);
/// Called when a pdf document is needed
... ... @@ -97,6 +100,17 @@ class PdfPreview extends StatefulWidget {
/// channel message while opened.
final bool dynamicLayout;
/// email subject when email application is selected from the share dialog
final String? shareActionExtraSubject;
/// extra text to share with Pdf document
final String? shareActionExtraBody;
/// list of email addresses which will be filled automatically if the email application
/// is selected from the share dialog.
/// This will work only for Android platform.
final List<String>? shareActionExtraEmails;
@override
_PdfPreviewState createState() => _PdfPreviewState();
}
... ... @@ -590,6 +604,9 @@ class _PdfPreviewState extends State<PdfPreview> {
bytes: bytes,
bounds: bounds,
filename: widget.pdfFileName ?? 'document.pdf',
body: widget.shareActionExtraBody,
subject: widget.shareActionExtraSubject,
emails: widget.shareActionExtraEmails,
);
if (result && widget.onShared != null) {
... ...
... ... @@ -135,11 +135,26 @@ mixin Printing {
);
}
/// Displays a platform popup to share the Pdf document to another application
/// Displays a platform popup to share the Pdf document to another application.
///
/// [subject] will be the email subject if selected application is email.
///
/// [body] will be the extra text that can be shared along with the Pdf document.
/// For email application [body] will be the email body text.
///
/// [emails] will be the list of emails to which you want to share the Pdf document.
/// If the selected application is email application then the these [emails] will be
/// filled in the to address.
///
/// [subject] and [body] will only work for Android and iOS platforms.
/// [emails] will only work for Android Platform.
static Future<bool> sharePdf({
required Uint8List bytes,
String filename = 'document.pdf',
Rect? bounds,
String? subject,
String? body,
List<String>? emails,
}) {
bounds ??= Rect.fromCircle(center: Offset.zero, radius: 10);
... ... @@ -147,6 +162,9 @@ mixin Printing {
bytes,
filename,
bounds,
subject,
body,
emails,
);
}
... ...
... ... @@ -7,7 +7,7 @@ description: >
homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 5.0.5
version: 5.1.0
environment:
sdk: ">=2.12.0-0 <3.0.0"
... ...
... ... @@ -118,7 +118,8 @@ class MockPrinting extends Mock
true;
@override
Future<bool> sharePdf(Uint8List bytes, String filename, Rect bounds) async =>
Future<bool> sharePdf(Uint8List bytes, String filename, Rect bounds,
String? subject, String? body, List<String>? emails) async =>
true;
@override
... ...