url_launcher doesn’t always open drive links externally, because android/iOS need proper intent and visibility configuration.
Android
AndroidManifest.xml - Starting from API 30 Android requires, package visibility configuration in your AndroidManifest.xml
<queries>
<!-- If your app opens https URLs -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<!-- If your app makes calls -->
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<!-- If your sends SMS messages -->
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="smsto" />
</intent>
<!-- If your app sends emails -->
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
ios
Add URL schemes to your Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
</array>
Example
if (url != null && await canLaunchUrl(Uri.parse(url))) {
await launchUrl(
Uri.parse(url),
mode: LaunchMode.externalApplication,
);
} else {
debugPrint('Could not launch URL: $url');
}
Deps
url_launcher: ^6.3.2
If you still have any doubts, checkout the Documentation