launchPDf method

Future<void> launchPDf(
  1. BuildContext context,
  2. String file
)

Implementation

Future<void> launchPDf(BuildContext context, String file) async{
  try{
    final url = '${html.window.location.origin}/$file.pdf';
    final uri =  Uri.parse(url);
    if (await canLaunchUrl(uri)) {
      launchUrl(uri, webOnlyWindowName: '_blank');
    } else{
      if(context.mounted){
        await _downloadPdf(context, file);
      }
    }
  } catch(e){
    if(context.mounted){
      await _downloadPdf(context, file);
    }
  }
}