Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mobile-app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ Future<void> main({bool testing = false}) async {

runApp(const FreeCodeCampMobileApp());

WidgetsBinding.instance.addPostFrameCallback((_) async {
await NotificationService().requestPermission();
await DailyChallengeNotificationService().setupNotifications();
});

await QuickActionsService().init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,11 @@ class DailyChallengeNotificationService {
initializationSettings,
onDidReceiveNotificationResponse: _onNotificationResponse,
);
}

bool permissionGranted = false;
if (Platform.isAndroid) {
permissionGranted = await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission() ??
false;
} else {
// For iOS, we assume permission is granted after init
permissionGranted = true;
}
Future<void> setupNotifications() async {
final permissionGranted = await areSystemNotificationsEnabled();

// Auto-enable daily notifications if system permission is granted
// and user hasn't explicitly disabled them
if (permissionGranted) {
final prefs = await SharedPreferences.getInstance();
final hasSetPreference =
Expand Down
12 changes: 8 additions & 4 deletions mobile-app/lib/service/podcast/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class NotificationService {
);

await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
}

Future<bool> requestPermission() async {
if (Platform.isAndroid) {
await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission();
return await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission() ??
false;
}
return true;
}

Future<void> showNotification(String title, String body) async {
Expand Down
Loading