Skip to content

Commit

Permalink
💾 Feat(Permissions): Request notification related permissions at ever…
Browse files Browse the repository at this point in the history
…y startup

I'd like to create a permission management page and display it at first startup
  • Loading branch information
Dynesshely committed Jul 23, 2024
1 parent 673f31d commit f742c53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kitx_mobile/lib/services/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:get/get.dart';
import 'package:kitx_mobile/instances.dart';
import 'package:kitx_mobile/services/public/service_status.dart';
import 'package:kitx_mobile/utils/extensions/service_status_to_string.dart';
import 'package:kitx_mobile/utils/handlers/permissions_handlers.dart';

/// [NotificationService] class
class NotificationService {
Expand All @@ -18,7 +19,8 @@ class NotificationService {

/// Initialize the notification service
Future<void> initAsync() async {
// TODO: adapt to iOS
if (await requestNotificationPermission() == false) return;

if (GetPlatform.isAndroid) {
AwesomeNotifications().initialize(
'resource://drawable/app_icon',
Expand All @@ -35,6 +37,8 @@ class NotificationService {
],
);
AwesomeNotifications().setListeners(onActionReceivedMethod: onActionReceivedMethod);
} else if (GetPlatform.isIOS) {
// TODO: Adapt to iOS
}
}

Expand Down
7 changes: 7 additions & 0 deletions kitx_mobile/lib/utils/handlers/permissions_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ Future<bool> requestNetworkRelatedPermissions() async {
return false;
}
}

/// Request Notification Permission
Future<bool> requestNotificationPermission() async {
var result = await requestPermission(Permission.notification);

return result;
}

0 comments on commit f742c53

Please sign in to comment.