Create a button to open app from flutter web - flutter

I would like to create an app in Flutter. The web version contains a button that should open version of android or IOS app according user platform if mobile version of app was installed (like an app install or open banner).
How should I detect is app installed in web flutter?
update:
I tried below code using import 'package:universal_html/html.dart' pakage:
window.location.href = (defaultTargetPlatform ==
TargetPlatform.android)
? 'https://play.google.com/store/apps/details?id=com.amazon.mShop.android.shopping'
: 'https://apps.apple.com/us/app/amazon-shopping/id297606951';
But this just open the store. I'm looking for a solution to open app directly if it was installed.

If this is fine for you, you can use an URL launcher. This way it opens the App store or play store and the user can either download the App or open it.
For Example flutter has a package that does most of this work:
https://github.com/Purus/launch_review
LaunchReview.launch(androidAppId: "yourpackagename", iOSAppId: "appid");
You just need to pass your package name and on ios your app ID
You could also use an URL Launcher:
https://pub.dev/packages/url_launcher
The code would be similar to this:
_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
}
else {
throw 'Could not launch $url';
}
}
URL Example
try {
launch("market://details?id=" + appPackageName);
} on PlatformException catch(e) {
launch("https://play.google.com/store/apps/details?id=" + appPackageName);
} finally {
launch("https://play.google.com/store/apps/details?id=" + appPackageName);
}
Note this code needs to be adapted
Also see this tutorial for help: https://flutteragency.com/open-appstore-playstore-url-in-flutter/
Edit:
If you want to directly open another app you can use something like this:
https://pub.dev/packages/external_app_launcher/
flutter pub add external_app_launcher
The Code would look like this then:
await LaunchApp.openApp(
androidPackageName: 'net.pulsesecure.pulsesecure',
iosUrlScheme: 'pulsesecure://',
appStoreLink: 'itms-apps://itunes.apple.com/us/app/pulse secure/id945832041',// openStore: false
);
// Enter the package name of the App you want to open and for iOS add the URLscheme to the Info.plist file.
// The `openStore` argument decides whether the app redirects to PlayStore or AppStore.
// For testing purpose you can enter com.instagram.android
More infos regarding implementation and additional setup infos you can find here: https://pub.dev/packages/external_app_launcher in the Readme

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.

Opening Google calendar from Flutter app (Deep Linking)

I want to open Google calendar app more specifically the create event page in the app from my another flutter app.
I am using the URL launcher package but it opens the app in chrome
What change should I make in the URL so that the add event page opens directly in the google calendar app.
Currently my URL looks like below
https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda
My code for that part is as below
if (await canLaunchUrl(Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda'))) {
await launchUrl(
Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda'),
mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch URL';
}
rathe than using a HTTP request, you could use googleapis package from https://pub.dev which has inbuilt methods to create Google Calender events directly within the Calender app.
Check package and documentation here.
Happy coding!

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

How to show Oauth Consent screen in flutter

I am trying to user gmail api. Google is asking me to make a video with demo of Oauth consent screen.
While searching in the internet I have found solutions for web and native android android. The docs of flutter packages googleapi and googleapi_auth were not very helful. If anyone has already implemented any suggestions would be helpful.
It's probably too late but here is the code for
' clientViaUserConsent(_clientid, _scopes, userPrompt)
.then((AuthClient client) {
//your code to authenticate any of your google platform
}
Here is the userPrompt function
void userPrompt(String url) async {
if (await canLaunch(url)) {
print("Launching url");
launch(url);
} else {
print("unable to launch the url");
}}
So whenever the clientviauserprompt is called the prompt function will launch the url to the default browser for the user consent.
You have to use urllauncher dependency for this.