Skip to content

Commit

Permalink
Share and rate app (#140)
Browse files Browse the repository at this point in the history
* share and rate app

* change icons

* improve error handling

* put await

* minor changes
  • Loading branch information
cp-sidhdhi-p authored Nov 20, 2024
1 parent 293bd5d commit 17048f5
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 8 deletions.
1 change: 0 additions & 1 deletion docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ <h1>{{ site.title }}</h1>
crossorigin="anonymous"></script>
<script>
anchors.add();

</script>
</body>
</html>
3 changes: 3 additions & 0 deletions khelo/assets/images/ic_share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions khelo/assets/images/ic_star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,23 @@
"profile_setting_contact_support": "Contact support",
"profile_setting_privacy_policy_title": "Privacy policy",
"profile_setting_terms_and_condition_title": "Terms and condition",
"profile_setting_share_app_title": "Share app",
"profile_setting_rate_us_title": "Rate us",
"profile_setting_app_version_text": "App Version: {version}",
"profile_setting_scan_to_play_text": "Scan to play!",
"profile_setting_scan_to_play_description": "This QR code allows you to easily add the player to the team.",
"profile_setting_use_scanner_description": "Use your phone camera or a QR code app to scan the code above and easily add the player to the team.",
"profile_setting_share_app_message": "Elevate your cricket scoring game with Khelo! 🏏\n\nEffortlessly score matches, track stats, and manage your teams.\n\n👉 Download Now:\n📱 Android: {androidLink}\n🍎 iOS: {iosLink}\n\nStart scoring smarter today!",
"@profile_setting_share_app_message" : {
"placeholders": {
"androidLink": {
"type": "String"
},
"iosLink": {
"type": "String"
}
}
},

"@_NOTIFICATION": {
},
Expand Down
6 changes: 6 additions & 0 deletions khelo/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,8 @@ PODS:
- Flutter
- MTBBarcodeScanner
- RecaptchaInterop (100.0.0)
- share_plus (0.0.1):
- Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand Down Expand Up @@ -1474,6 +1476,7 @@ DEPENDENCIES:
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
- qr_code_scanner (from `.symlinks/plugins/qr_code_scanner/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite (from `.symlinks/plugins/sqflite/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
Expand Down Expand Up @@ -1553,6 +1556,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/permission_handler_apple/ios"
qr_code_scanner:
:path: ".symlinks/plugins/qr_code_scanner/ios"
share_plus:
:path: ".symlinks/plugins/share_plus/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
sqflite:
Expand Down Expand Up @@ -1611,6 +1616,7 @@ SPEC CHECKSUMS:
PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851
qr_code_scanner: bb67d64904c3b9658ada8c402e8b4d406d5d796e
RecaptchaInterop: 7d1a4a01a6b2cb1610a47ef3f85f0c411434cb21
share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
Toast: 1f5ea13423a1e6674c4abdac5be53587ae481c4e
Expand Down
4 changes: 4 additions & 0 deletions khelo/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-apps</string>
</array>
</dict>
</plist>
8 changes: 8 additions & 0 deletions khelo/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions khelo/lib/ui/flow/profile/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class ProfileScreen extends ConsumerStatefulWidget {

class _ProfileScreenState extends ConsumerState<ProfileScreen>
with WidgetsBindingObserver {
final privacyPolicyUrl = "https://canopas.github.io/khelo/privacy-policy";
final termsAndConditionsUrl =
"https://canopas.github.io/khelo/terms-and-condition";
final playStoreLink =
"https://play.google.com/store/apps/details?id=com.canopas.khelo";
final appStoreLink = "https://apps.apple.com/app/khelo/id6480175424";

late ProfileViewNotifier notifier;

@override
Expand Down Expand Up @@ -189,15 +196,27 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen>
context,
icon: Assets.images.icPrivacyPolicy,
title: context.l10n.profile_setting_privacy_policy_title,
onTap: () => notifier
.openUrl("https://canopas.github.io/khelo/privacy-policy"),
onTap: () => notifier.openUrl(privacyPolicyUrl),
),
_settingItem(
context,
icon: Assets.images.icTermsConditions,
title: context.l10n.profile_setting_terms_and_condition_title,
onTap: () => notifier
.openUrl("https://canopas.github.io/khelo/terms-and-condition"),
onTap: () => notifier.openUrl(termsAndConditionsUrl),
),
_settingItem(
context,
icon: Assets.images.icShare,
title: context.l10n.profile_setting_share_app_title,
onTap: () => notifier.onShareApp(context.l10n
.profile_setting_share_app_message(
playStoreLink, appStoreLink)),
),
_settingItem(
context,
icon: Assets.images.icStar,
title: context.l10n.profile_setting_rate_us_title,
onTap: () => notifier.onRateUs(),
),
_settingItem(
context,
Expand Down
31 changes: 30 additions & 1 deletion khelo/lib/ui/flow/profile/profile_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'dart:io';

import 'package:data/api/user/user_models.dart';
import 'package:data/service/auth/auth_service.dart';
import 'package:data/service/device/device_service.dart';
import 'package:data/service/user/user_service.dart';
import 'package:data/storage/app_preferences.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';

part 'profile_view_model.freezed.dart';
Expand All @@ -25,6 +28,8 @@ final profileStateProvider =
});

class ProfileViewNotifier extends StateNotifier<ProfileState> {
static const String webFallbackUrl = 'https://github.com/canopas/khelo';

final AuthService _authService;
final DeviceService _deviceService;
final UserService _userService;
Expand Down Expand Up @@ -104,6 +109,30 @@ class ProfileViewNotifier extends StateNotifier<ProfileState> {
state = state.copyWith(shouldShowNotificationBanner: false);
}
}

Future<void> onRateUs() async {
try {
final packageName = await _deviceService.packageName;
final targetUrl = (!kIsWeb && Platform.isAndroid)
? "market://details?id=$packageName"
: (!kIsWeb && Platform.isIOS)
? "itms-apps://itunes.apple.com/app/6480175424"
: webFallbackUrl;
await launchUrl(Uri.parse(targetUrl));
} catch (e) {
state = state.copyWith(actionError: e);
debugPrint("ProfileViewNotifier: error while rate us -> $e");
}
}

Future<void> onShareApp(String shareString) async {
try {
await Share.share(shareString);
} catch (e) {
state = state.copyWith(actionError: e);
debugPrint("ProfileViewNotifier: error while share app -> $e");
}
}
}

@freezed
Expand Down
18 changes: 16 additions & 2 deletions khelo/lib/ui/flow/profile/profile_view_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class __$$ProfileStateImplCopyWithImpl<$Res>

/// @nodoc
class _$ProfileStateImpl implements _ProfileState {
class _$ProfileStateImpl with DiagnosticableTreeMixin implements _ProfileState {
const _$ProfileStateImpl(
{this.actionError,
this.currentUser,
Expand All @@ -186,10 +186,24 @@ class _$ProfileStateImpl implements _ProfileState {
final bool shouldShowNotificationBanner;

@override
String toString() {
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'ProfileState(actionError: $actionError, currentUser: $currentUser, appVersion: $appVersion, enableUserNotification: $enableUserNotification, shouldShowNotificationBanner: $shouldShowNotificationBanner)';
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('type', 'ProfileState'))
..add(DiagnosticsProperty('actionError', actionError))
..add(DiagnosticsProperty('currentUser', currentUser))
..add(DiagnosticsProperty('appVersion', appVersion))
..add(
DiagnosticsProperty('enableUserNotification', enableUserNotification))
..add(DiagnosticsProperty(
'shouldShowNotificationBanner', shouldShowNotificationBanner));
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
Expand Down
2 changes: 2 additions & 0 deletions khelo/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import flutter_local_notifications
import flutter_timezone
import package_info_plus
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import sqflite
import url_launcher_macos
Expand All @@ -36,6 +37,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
Expand Down
16 changes: 16 additions & 0 deletions khelo/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.28.0"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: "9c9bafd4060728d7cdb2464c341743adbd79d327cb067ec7afb64583540b47c8"
url: "https://pub.dev"
source: hosted
version: "10.1.2"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: c57c0bbfec7142e3a0f55633be504b796af72e60e3c791b44d5a017b985f7a48
url: "https://pub.dev"
source: hosted
version: "5.0.1"
shared_preferences:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions khelo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies:

shared_preferences: ^2.3.2
collection: any
share_plus: ^10.1.2

# UI
cupertino_icons: ^1.0.8
Expand Down
3 changes: 3 additions & 0 deletions khelo/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <firebase_storage/firebase_storage_plugin_c_api.h>
#include <flutter_timezone/flutter_timezone_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
Expand All @@ -30,6 +31,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FlutterTimezonePluginCApi"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions khelo/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
firebase_storage
flutter_timezone
permission_handler_windows
share_plus
url_launcher_windows
)

Expand Down

0 comments on commit 17048f5

Please sign in to comment.