Rate Us: Open playstore app for rating with fallback to https url

This commit is contained in:
Neeraj Gupta 2023-01-07 16:02:24 +05:30
parent 1d490e20b9
commit 5c8cdd2bb0
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
4 changed files with 24 additions and 22 deletions

View file

@ -8,6 +8,7 @@ import 'package:photos/core/network.dart';
import 'package:photos/services/notification_service.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher_string.dart';
class UpdateService {
UpdateService._privateConstructor();
@ -137,15 +138,30 @@ class UpdateService {
);
}
return Platform.isAndroid
? const Tuple2(
"play store",
"https://play.google.com/store/apps/details?id=io.ente.photos",
)
? const Tuple2("play store", "market://details?id=io.ente.photos")
: const Tuple2(
"app store",
"https://apps.apple.com/in/app/ente-photos/id1542026904",
);
}
Future<void> launchReviewUrl() async {
// TODO: Replace with https://pub.dev/packages/in_app_review
final String url = getRateDetails().item2;
try {
await launchUrlString(url, mode: LaunchMode.externalApplication);
} catch (e) {
_logger.severe("Failed top open launch url $url", e);
// Fall back if we fail to open play-store market app on android
if (Platform.isAndroid && url.startsWith("market://")) {
launchUrlString(
"https://play.google.com/store/apps/details?id=io"
".ente.photos",
mode: LaunchMode.externalApplication)
.ignore();
}
}
}
}
class LatestVersionInfo {

View file

@ -6,7 +6,6 @@ import 'package:photos/ui/components/divider_widget.dart';
import 'package:photos/ui/components/models/button_type.dart';
import 'package:photos/ui/components/title_bar_title_widget.dart';
import 'package:photos/ui/notification/update/change_log_entry.dart';
import 'package:url_launcher/url_launcher_string.dart';
class ChangeLogPage extends StatefulWidget {
const ChangeLogPage({
@ -85,9 +84,7 @@ class _ChangeLogPageState extends State<ChangeLogPage> {
icon: Icons.favorite_rounded,
iconColor: enteColorScheme.primary500,
onTap: () async {
launchUrlString(
UpdateService.instance.getRateDetails().item2,
);
await UpdateService.instance.launchReviewUrl();
},
),
const SizedBox(height: 8),

View file

@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
@ -23,7 +21,6 @@ import 'package:photos/utils/data_util.dart';
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/navigation_util.dart';
import 'package:photos/utils/toast_util.dart';
import 'package:url_launcher/url_launcher_string.dart';
class BackupSectionWidget extends StatefulWidget {
const BackupSectionWidget({Key? key}) : super(key: key);
@ -167,8 +164,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
body: "You have successfully freed up " + formatBytes(status.size) + "!",
firstButtonLabel: "Rate us",
firstButtonOnTap: () async {
final url = UpdateService.instance.getRateDetails().item2;
launchUrlString(url);
UpdateService.instance.launchReviewUrl();
},
firstButtonType: ButtonType.primary,
secondButtonLabel: "OK",
@ -206,9 +202,7 @@ class BackupSectionWidgetState extends State<BackupSectionWidget> {
"!",
firstButtonLabel: "Rate us",
firstButtonOnTap: () async {
// TODO: Replace with https://pub.dev/packages/in_app_review
final url = UpdateService.instance.getRateDetails().item2;
launchUrlString(url);
UpdateService.instance.launchReviewUrl();
},
firstButtonType: ButtonType.primary,
secondButtonLabel: "OK",

View file

@ -1,5 +1,3 @@
import 'dart:async';
import 'dart:io';
@ -31,7 +29,6 @@ import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/magic_util.dart';
import 'package:photos/utils/navigation_util.dart';
import 'package:photos/utils/toast_util.dart';
import 'package:url_launcher/url_launcher_string.dart';
class GalleryAppBarWidget extends StatefulWidget {
final GalleryType type;
@ -206,9 +203,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
body: "You have successfully freed up " + formatBytes(status.size) + "!",
firstButtonLabel: "Rate us",
firstButtonOnTap: () async {
// TODO: Replace with https://pub.dev/packages/in_app_review
final url = UpdateService.instance.getRateDetails().item2;
launchUrlString(url);
UpdateService.instance.launchReviewUrl();
},
firstButtonType: ButtonType.primary,
secondButtonLabel: "OK",