Reputation: 658
I understand there maybe some duplication here, but the other solutions I have found don't do exactly what I need. What I want to do is to launch a particular app and if it isn't installed launch the apps page on Playstore and also AppStore, if using an iPhone. I am pretty close to getting this working, but I need a little help getting over the line.
I have a FloatingAction Button that loads the chosen app and if it isn't installed, loads PlayStore, but it doesn't go directly to the App's page. I haven't testing on iPhone yet, so if that code is garbage, I would appreciate some help there too.
How can I get my app to go straight to the app's page on playstore app and appstore app?
Here is my code
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter_appavailability/flutter_appavailability.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('App Availability'),
),
body: FloatingActionButton(
backgroundColor: Colors.indigo,
onPressed: () => openApp(context),
child: Icon(Icons.open_in_new),
heroTag: "Open App",
),
),
);
}
}
void openApp(BuildContext context) {
try {
AppAvailability.launchApp(Platform.isIOS
? "appname://"
: "com.company.appname"
).then((_) {
print("App Launched!");
}).catchError((err) {
AppAvailability.launchApp(Platform.isIOS
? "appstore://"
: "com.android.vending"
)
// I think I will need to add package name to the playstore package name
// in the line above, but not sure how.
// I have tried com.android.vending?id=com.criticalarc.safezoneapp
// and com.android.vending/com.criticalarc.safezoneapp
.then((_) {});
print(err);
});
} catch (e) {
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text("App Not Installed!"),
),
);
print("App Not Installed!");
}
}
thanks
Upvotes: 2
Views: 4559
Reputation: 34
Try using the the Google Play website link itself
Syntax - https://play.google.com/store/apps/details?id=(complete-with-the-app-package-name)
For eg - https://play.google.com/store/apps/details?id=org.amahi.anywhere
Upvotes: 1