David PHAM-VAN

Add Google Fonts fallback to Helvetica

@@ -70,7 +70,7 @@ abstract class PdfBaseCache { @@ -70,7 +70,7 @@ abstract class PdfBaseCache {
70 final bytes = await _download(uri, headers: headers); 70 final bytes = await _download(uri, headers: headers);
71 71
72 if (bytes == null) { 72 if (bytes == null) {
73 - throw FlutterError('Unable to find the asset $name'); 73 + throw FlutterError('Unable to download $uri');
74 } 74 }
75 75
76 if (cache) { 76 if (cache) {
@@ -19,7 +19,7 @@ class DownloadbleFont { @@ -19,7 +19,7 @@ class DownloadbleFont {
19 static var cache = PdfBaseCache.defaultCache; 19 static var cache = PdfBaseCache.defaultCache;
20 20
21 /// Get the font to use in a Pdf document 21 /// Get the font to use in a Pdf document
22 - Future<TtfFont> getFont({ 22 + Future<Font> getFont({
23 PdfBaseCache? pdfCache, 23 PdfBaseCache? pdfCache,
24 bool protect = false, 24 bool protect = false,
25 Map<String, String>? headers, 25 Map<String, String>? headers,
@@ -38,6 +38,8 @@ class DownloadbleFont { @@ -38,6 +38,8 @@ class DownloadbleFont {
38 } 38 }
39 39
40 pdfCache ??= PdfBaseCache.defaultCache; 40 pdfCache ??= PdfBaseCache.defaultCache;
  41 +
  42 + try {
41 final bytes = await pdfCache.resolve( 43 final bytes = await pdfCache.resolve(
42 name: name, 44 name: name,
43 uri: Uri.parse(url), 45 uri: Uri.parse(url),
@@ -49,5 +51,9 @@ class DownloadbleFont { @@ -49,5 +51,9 @@ class DownloadbleFont {
49 bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes), 51 bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes),
50 protect: protect, 52 protect: protect,
51 ); 53 );
  54 + } catch (e) {
  55 + print('$e\nError loading $name, fallback to Helvetica.');
  56 + return Font.helvetica();
  57 + }
52 } 58 }
53 } 59 }