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,16 +38,22 @@ class DownloadbleFont { @@ -38,16 +38,22 @@ class DownloadbleFont {
38 } 38 }
39 39
40 pdfCache ??= PdfBaseCache.defaultCache; 40 pdfCache ??= PdfBaseCache.defaultCache;
41 - final bytes = await pdfCache.resolve(  
42 - name: name,  
43 - uri: Uri.parse(url),  
44 - headers: headers,  
45 - cache: cache,  
46 - );  
47 -  
48 - return TtfFont(  
49 - bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes),  
50 - protect: protect,  
51 - ); 41 +
  42 + try {
  43 + final bytes = await pdfCache.resolve(
  44 + name: name,
  45 + uri: Uri.parse(url),
  46 + headers: headers,
  47 + cache: cache,
  48 + );
  49 +
  50 + return TtfFont(
  51 + bytes.buffer.asByteData(bytes.offsetInBytes, bytes.lengthInBytes),
  52 + protect: protect,
  53 + );
  54 + } catch (e) {
  55 + print('$e\nError loading $name, fallback to Helvetica.');
  56 + return Font.helvetica();
  57 + }
52 } 58 }
53 } 59 }