Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter url_launcher: blank page when opening pdf

Using latest version and failing for Android and iOS: url_launcher: ^6.1.5

<!-- If your app checks for SMS support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="sms" />
        </intent>
        <!-- If your app checks for call support -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="tel" />
        </intent>

...

    static openLink(String link) async {
// https://res.cloudinary.com/recipic/image/upload/v1663798152/odvxwkkztakrpd3gva1j.pdf
        final Uri url = Uri.parse(link);
        if (await canLaunchUrl(url)) {
          await launchUrl(url);
        } else {
          throw 'Could not launch $link';
        }
      }

It just displays a blank page throwing no errors, just:

Accessing hidden method Lsun/misc/Unsafe;->getObject

like image 737
Dani Avatar asked Oct 20 '25 14:10

Dani


1 Answers

Just add this in launchUrl() :

launchUrl(url, mode: LaunchMode.externalApplication,);

and you might need to add this to your AndroidManifest.xml

<intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
        </intent>

then you should be able to open the PDF smoothly!

like image 115
ItsHarsh.json Avatar answered Oct 23 '25 05:10

ItsHarsh.json