多语言支持
This commit is contained in:
@@ -91,6 +91,8 @@ class NotificationService {
|
||||
Future<void> showFocusCompletedNotification({
|
||||
required int minutes,
|
||||
required int distractionCount,
|
||||
String? title,
|
||||
String? body,
|
||||
}) async {
|
||||
if (kIsWeb || !_initialized) return;
|
||||
|
||||
@@ -116,22 +118,23 @@ class NotificationService {
|
||||
iOS: iosDetails,
|
||||
);
|
||||
|
||||
// Create notification message
|
||||
final title = '🎉 Focus session complete!';
|
||||
final body = distractionCount == 0
|
||||
? 'You focused for $minutes ${minutes == 1 ? 'minute' : 'minutes'} without distractions!'
|
||||
: 'You focused for $minutes ${minutes == 1 ? 'minute' : 'minutes'}. Great effort!';
|
||||
// Use provided title/body or fall back to English
|
||||
final notificationTitle = title ?? '🎉 Focus session complete!';
|
||||
final notificationBody = body ??
|
||||
(distractionCount == 0
|
||||
? 'You focused for $minutes ${minutes == 1 ? 'minute' : 'minutes'} without distractions!'
|
||||
: 'You focused for $minutes ${minutes == 1 ? 'minute' : 'minutes'}. Great effort!');
|
||||
|
||||
await _notifications.show(
|
||||
0, // Notification ID
|
||||
title,
|
||||
body,
|
||||
notificationTitle,
|
||||
notificationBody,
|
||||
notificationDetails,
|
||||
payload: 'focus_completed',
|
||||
);
|
||||
|
||||
if (kDebugMode) {
|
||||
print('Notification shown: $title - $body');
|
||||
print('Notification shown: $notificationTitle - $notificationBody');
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
@@ -207,11 +210,13 @@ class NotificationService {
|
||||
Future<void> showOngoingFocusNotification({
|
||||
required int remainingMinutes,
|
||||
required int remainingSeconds,
|
||||
String? title,
|
||||
String? timeRemainingText,
|
||||
}) async {
|
||||
if (kIsWeb || !_initialized) return;
|
||||
|
||||
try {
|
||||
// Format time display
|
||||
// Format time display for fallback
|
||||
final timeStr = '${remainingMinutes.toString().padLeft(2, '0')}:${(remainingSeconds % 60).toString().padLeft(2, '0')}';
|
||||
|
||||
const androidDetails = AndroidNotificationDetails(
|
||||
@@ -240,10 +245,14 @@ class NotificationService {
|
||||
iOS: iosDetails,
|
||||
);
|
||||
|
||||
// Use provided text or fall back to English
|
||||
final notificationTitle = title ?? '⏱️ Focus session in progress';
|
||||
final notificationBody = timeRemainingText ?? '$timeStr remaining';
|
||||
|
||||
await _notifications.show(
|
||||
2, // Use ID 2 for ongoing notifications
|
||||
'⏱️ Focus session in progress',
|
||||
'$timeStr remaining',
|
||||
notificationTitle,
|
||||
notificationBody,
|
||||
notificationDetails,
|
||||
payload: 'focus_ongoing',
|
||||
);
|
||||
@@ -258,11 +267,15 @@ class NotificationService {
|
||||
Future<void> updateOngoingFocusNotification({
|
||||
required int remainingMinutes,
|
||||
required int remainingSeconds,
|
||||
String? title,
|
||||
String? timeRemainingText,
|
||||
}) async {
|
||||
// On Android, showing the same notification ID updates it
|
||||
await showOngoingFocusNotification(
|
||||
remainingMinutes: remainingMinutes,
|
||||
remainingSeconds: remainingSeconds,
|
||||
title: title,
|
||||
timeRemainingText: timeRemainingText,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user