David PHAM-VAN

Improve console error reporting

# Changelog
## 5.0.4
- Improve console error reporting
## 5.0.3
- Fix RichText annotations
... ...
... ... @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'printing'
s.version = '0.0.1'
s.version = '1.0.0'
s.summary = 'Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers'
s.description = <<-DESC
Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
... ...
... ... @@ -23,6 +23,7 @@ import 'dart:js_util';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart' show Rect;
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:image/image.dart' as im;
... ... @@ -65,7 +66,30 @@ class PrintingPlugin extends PrintingPlatform {
PdfPageFormat format,
bool dynamicLayout,
) async {
final result = await onLayout(format);
late Uint8List result;
try {
result = await onLayout(format);
} catch (e, s) {
InformationCollector? collector;
assert(() {
collector = () sync* {
yield StringProperty('PageFormat', format.toString());
};
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
exception: e,
stack: s,
stackFilter: (input) => input,
library: 'printing',
context: ErrorDescription('while generating a PDF'),
informationCollector: collector,
));
rethrow;
}
if (result.isEmpty) {
return false;
... ...
... ... @@ -29,7 +29,7 @@ import 'raster.dart';
/// The interface that implementations of printing must implement.
abstract class PrintingPlatform extends PlatformInterface {
/// Constructs a UrlLauncherPlatform.
/// Constructs a PrintingPlatform.
PrintingPlatform() : super(token: _token);
static final Object _token = Object();
... ...
... ... @@ -17,6 +17,7 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart' show Rect;
import 'package:flutter/services.dart';
import 'package:pdf/pdf.dart';
... ... @@ -60,7 +61,25 @@ class MethodChannelPrinting extends PrintingPlatform {
Uint8List bytes;
try {
bytes = await job.onLayout!(format);
} catch (e) {
} catch (e, s) {
InformationCollector? collector;
assert(() {
collector = () sync* {
yield StringProperty('PageFormat', format.toString());
};
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
exception: e,
stack: s,
stackFilter: (input) => input,
library: 'printing',
context: ErrorDescription('while generating a PDF'),
informationCollector: collector,
));
if (job.useFFI) {
return setErrorFfi(job, e.toString());
}
... ...
... ... @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
... ... @@ -140,13 +141,42 @@ class _PdfPreviewState extends State<PdfPreview> {
Uint8List _doc;
if (!info.canRaster) {
assert(() {
if (kIsWeb) {
FlutterError.reportError(FlutterErrorDetails(
exception: Exception(
'Unable to find the `pdf.js` library.\nPlease follow the installation instructions at https://github.com/DavBfr/dart_pdf/tree/master/printing#installing'),
library: 'printing',
context: ErrorDescription('while rendering a PDF'),
));
}
return true;
}());
return;
}
try {
_doc = await widget.build(computedPageFormat);
} catch (e) {
error = e;
} catch (exception, stack) {
InformationCollector? collector;
assert(() {
collector = () sync* {
yield StringProperty('PageFormat', computedPageFormat.toString());
};
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
exception: exception,
stack: stack,
library: 'printing',
context: ErrorDescription('while generating a PDF'),
informationCollector: collector,
));
error = exception;
return;
}
... ... @@ -270,7 +300,6 @@ class _PdfPreviewState extends State<PdfPreview> {
if (error != null) {
var content = _showError();
assert(() {
print(error);
content = ErrorWidget(error!);
return true;
}());
... ...
... ... @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'printing'
s.version = '0.0.1'
s.version = '1.0.0'
s.summary = 'Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers'
s.description = <<-DESC
Plugin that allows Flutter apps to generate and print documents to android or ios compatible printers
... ...
... ... @@ -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.3
version: 5.0.4
environment:
sdk: ">=2.12.0-0 <3.0.0"
... ...