isNotificationsEnabled method
Returns whether notifications are enabled at the app level.
This is the app-level preference flag (default: true). Use this to gate notification surfaces in your UI.
Note: This is separate from OS permission status. A user could have notifications enabled at the app level but denied at the OS level.
Example:
final enabled = await notificationService.isNotificationsEnabled();
if (enabled) {
showNotificationBadge();
}
Implementation
Future<bool> isNotificationsEnabled() async {
try {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool(_keyNotificationsEnabled) ?? true; // Default to true
} catch (e) {
loge(e, 'Error checking notifications enabled status');
return true; // Default to true on error
}
}