Flutter `launchUrl` redirect to PDF - flutter

I am using flutter launchUrl on android, I tested it downloading pdfs as well, works fine. But if I have a .php url which downloads a PDF I get a white screen. I could set mode: LaunchMode.externalApplication in order to switch to the downloads. Is there a way to open the file in the browser or using the default app?
Uri uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri,
mode: LaunchMode.externalApplication);
}

Related

Open another desktop app with admin privilages within Flutter Desktop app

I am using url launcher package to run another app using my flutter desktop app with the following code:
launchAutoCadApp() async {
SharedPreferencesManager prefs = SharedPreferencesManager();
final String filePath = (await prefs.getCUrl()).toString();
final Uri uri = Uri.file(filePath);
if (!File(uri.toFilePath()).existsSync()) {
throw Exception('$uri does not exist!');
}
if (!await launchUrl(uri)) { //This is where my another desktop app is being initiated
throw Exception('Could not launch $uri');
}
}
I want to initiate my another desktop app with admin privilages from my flutter desktop app i.e a popup should display like this before launching my app.
I have gone through this answer on stackoverflow, but this doesn't fullfil what I want.

Flutter: url launcher facebook and instagram showing it may be broken

await launchUrl(
Uri.parse(
'https://www.facebook.com/$fbid',
),
mode: LaunchMode.externalApplication);
I have this launch url mode. The address works when I use it on my browser however, it does not when I use it inside the Flutter app. It says The link you followed may be broken, or ....
Twitter works fine but Instagram and FB are the ones that cause the error. I feel like something must be done for meta apps that I am missing right now. How can I fix this?
if (Platform.isAndroid) { var fbUrl = "fb://facewebmodal/f?href=" + "https://www.facebook.com/$fbid "; //for android launchFacebook(fbUrl, "https://www.facebook.com/$fbid"); }

Download image in mobile in flutter web

I created a flutter web app that creates an image and generates the base64 data. so I used AnchorElement in the HTML package to download the image to the client, it works on mac and windows but when I want to be downloaded on mobile nothing happen at all.
any clue?
code:
Future<void> downloadImage(Uint8List data8) async {
try {
final base64data = base64Encode(data8);
final a = html.AnchorElement(href: 'data:image/jpeg;base64,$base64data');
a.download = 'image.jpg';
a.click();
a.remove();
} catch (e) {
print(e);
}
}
In general mobile apps need rights to access certain resource, e.g. access the network.
Search for entitlement on iOS like this and manifest on Android.
You need to set these rights in the iOS or Android project. Without this rights, access gets simply denied.

Is there a way to launch Safari or some other external browser on URLs in Flutter apps on iOS?

I have this code:
import 'package:url_launcher/url_launcher.dart';
...
await launch("https://example.org/bigprizes");
It launches a web view within the app on iOS. Instead, I want it to launch in Safari or some other external browser of the user's choice. Is there a way to do that in Flutter?
Look at Step 4 in https://www.digitalocean.com/community/tutorials/flutter-url-launcher
await launch("https://example.org/bigprizes", forceSafariVC: false);
url_launcher plugin (https://pub.dev/packages/url_launcher) has methods launchUrl() and launchUrlString() which both has a property mode where you can specify how the app will open the URL. More details on the Launch mode documentation
Basically you can call it like this:
static Future<void> launchURL(String url) async {
if (await canLaunchUrlString(url)) {
// Passes the URL to the OS to be handled by another application.
await launchUrlString(url, mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch $url';
}
}
check this package https://pub.dev/packages/flutter_linkify it's may be useful for your project

Problem with Webview showing Google Photos in Flutter

I am using flutter_webview_plugin: ^0.3.11
This is my code
Widget build(BuildContext context){
return WebviewScaffold(
url: glbPhotoURL,
withJavascript: true,
scrollBar : true,
withZoom: true
)
url: glbPhotoURL => here glbPhotoURL is a URL that I am passing
When I am using any normal URL it is running fine (like http://www.google.com, http://youtube.com"
Even url like - https://youtu.be/o5UPfG1eIw4 is running fine
But when I am using any google photo url (short url) it is throwing an error net::ERR_UNKNOWN_URL_SCHEME for eg - https://photos.app.goo.gl/FkQenAD8kQQc4TSr6
If I am using the expanded URL it shows the pictures -https://photos.google.com/share/AF1QipNItZG3Cg_hn9__2QnuVh3nNMbRuGxQaQSWZ76qni7L7h0ORbauolcH3AKe0MOnEA?
key=emc1Mk1CenRJRjloMjV5V1AzcmczNUprcGFsbmR3
Please help me resolve the issue
As of now I am running it on Android physical device.
Google Photos uses Firebase Dynamic Links. I suggest launching the link externally. I encountered a similar error on Android before, when Firebase Dynamic Links are being forced to be loaded in a WebView. FDLs are expected to be handled by Google Play Services in Android. But since the WebView doesn't know what to do with the link it's forced to display, the WebView returns "net::ERR_UNKNOWN_URL_SCHEME" error.
Open the link externally by using url_launcher. Use RegEx to filter intent URLs and check if the URL can be launched and be handled externally (outside the app).
var yourURL = "URL goes here";
// Check if URL contains Google Photos URL
yourURL.contains(RegExp('^https://photos\.app\.goo\.gl/.*$')){
// Check if the URL can be launched
if (await canLaunch(yourURL)) {
await launch(yourURL);
} else {
print('Could not launch $yourURL');
}
}