feat: 实现日历提醒 in-app fallback 机制及通知服务重构
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz_data;
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
import 'reminder_notification_callbacks.dart';
|
||||
import '../../features/calendar/data/models/schedule_item_model.dart';
|
||||
import '../../features/calendar/reminders/models/reminder_action.dart';
|
||||
import '../../features/calendar/reminders/models/reminder_payload.dart';
|
||||
import '../../features/calendar/reminders/reminder_action_dedupe_store.dart';
|
||||
import '../../features/calendar/reminders/reminder_overlap_policy.dart';
|
||||
|
||||
typedef ReminderNotificationActionHandler =
|
||||
@@ -16,26 +21,51 @@ typedef ReminderNotificationActionHandler =
|
||||
required ReminderPayload payload,
|
||||
});
|
||||
|
||||
typedef ReminderPermissionFallbackTracker =
|
||||
void Function({
|
||||
required String actionExecutionId,
|
||||
required String permissionState,
|
||||
required String appLifecycleState,
|
||||
required String platform,
|
||||
});
|
||||
|
||||
typedef ReminderInAppReminderHandler =
|
||||
Future<void> Function(ReminderPayload payload);
|
||||
|
||||
class LocalNotificationService {
|
||||
static const String _iosCategoryId = 'calendar_reminder_actions_v1';
|
||||
static const String _iosCategoryId = 'calendar_reminder_v2';
|
||||
static const String _actionCancel = 'cancel';
|
||||
static const String _actionSnooze = 'snooze_10m';
|
||||
static const String _actionSnooze = 'snooze10m';
|
||||
|
||||
final FlutterLocalNotificationsPlugin _plugin;
|
||||
final ReminderOverlapPolicy _overlapPolicy;
|
||||
final ReminderPermissionFallbackTracker? _permissionFallbackTracker;
|
||||
ReminderActionDedupeStore? _dedupeStore;
|
||||
bool _initialized = false;
|
||||
bool _canDeliverSystemNotification = true;
|
||||
ReminderNotificationActionHandler? _actionHandler;
|
||||
ReminderInAppReminderHandler? _inAppReminderHandler;
|
||||
final Map<String, List<Timer>> _inAppFallbackTimersByEventId =
|
||||
<String, List<Timer>>{};
|
||||
|
||||
LocalNotificationService({
|
||||
FlutterLocalNotificationsPlugin? plugin,
|
||||
ReminderOverlapPolicy? overlapPolicy,
|
||||
ReminderActionDedupeStore? dedupeStore,
|
||||
ReminderPermissionFallbackTracker? permissionFallbackTracker,
|
||||
}) : _plugin = plugin ?? FlutterLocalNotificationsPlugin(),
|
||||
_overlapPolicy = overlapPolicy ?? const ReminderOverlapPolicy();
|
||||
_overlapPolicy = overlapPolicy ?? const ReminderOverlapPolicy(),
|
||||
_dedupeStore = dedupeStore,
|
||||
_permissionFallbackTracker = permissionFallbackTracker;
|
||||
|
||||
void bindActionHandler(ReminderNotificationActionHandler handler) {
|
||||
_actionHandler = handler;
|
||||
}
|
||||
|
||||
void bindInAppReminderHandler(ReminderInAppReminderHandler handler) {
|
||||
_inAppReminderHandler = handler;
|
||||
}
|
||||
|
||||
Future<void> initialize() async {
|
||||
if (_initialized) {
|
||||
return;
|
||||
@@ -67,14 +97,28 @@ class LocalNotificationService {
|
||||
|
||||
await _plugin.initialize(
|
||||
settings,
|
||||
onDidReceiveNotificationResponse: _onNotificationResponse,
|
||||
onDidReceiveNotificationResponse:
|
||||
ReminderNotificationCallbacks.onForegroundResponse,
|
||||
onDidReceiveBackgroundNotificationResponse:
|
||||
reminderNotificationTapBackground,
|
||||
);
|
||||
|
||||
final androidImpl = _plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
await androidImpl?.requestNotificationsPermission();
|
||||
final androidPermissionGranted = await androidImpl
|
||||
?.requestNotificationsPermission();
|
||||
if (defaultTargetPlatform == TargetPlatform.android &&
|
||||
androidPermissionGranted == false) {
|
||||
_canDeliverSystemNotification = false;
|
||||
_permissionFallbackTracker?.call(
|
||||
actionExecutionId: 'permission_check',
|
||||
permissionState: 'denied',
|
||||
appLifecycleState: 'unknown',
|
||||
platform: 'android',
|
||||
);
|
||||
}
|
||||
await androidImpl?.requestExactAlarmsPermission();
|
||||
await androidImpl?.requestFullScreenIntentPermission();
|
||||
|
||||
@@ -84,11 +128,37 @@ class LocalNotificationService {
|
||||
>();
|
||||
await iosImpl?.requestPermissions(alert: true, badge: true, sound: true);
|
||||
|
||||
await _ensureDedupeStore();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
Future<void> _ensureDedupeStore() async {
|
||||
if (_dedupeStore != null) {
|
||||
return;
|
||||
}
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_dedupeStore = ReminderActionDedupeStore(prefs);
|
||||
}
|
||||
|
||||
Future<void> _refreshAndroidNotificationAvailability() async {
|
||||
if (defaultTargetPlatform != TargetPlatform.android) {
|
||||
return;
|
||||
}
|
||||
final androidImpl = _plugin
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
final enabled = await androidImpl?.areNotificationsEnabled();
|
||||
if (enabled == null) {
|
||||
return;
|
||||
}
|
||||
_canDeliverSystemNotification = enabled;
|
||||
}
|
||||
|
||||
Future<void> upsertEventReminder(ScheduleItemModel event) async {
|
||||
await initialize();
|
||||
await _refreshAndroidNotificationAvailability();
|
||||
if (event.status != ScheduleStatus.active ||
|
||||
event.metadata?.reminderMinutes == null) {
|
||||
await cancelEventReminder(event.id);
|
||||
@@ -102,6 +172,14 @@ class LocalNotificationService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_canDeliverSystemNotification) {
|
||||
await _scheduleInAppFallbackRemindersFrom(
|
||||
event: event,
|
||||
firstFireAt: fireAt,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await cancelEventReminder(event.id);
|
||||
await _scheduleRemindersFrom(event: event, firstFireAt: fireAt);
|
||||
}
|
||||
@@ -111,12 +189,22 @@ class LocalNotificationService {
|
||||
DateTime fireAt,
|
||||
) async {
|
||||
await initialize();
|
||||
await _refreshAndroidNotificationAvailability();
|
||||
if (!_canDeliverSystemNotification) {
|
||||
await _scheduleInAppFallbackRemindersFrom(
|
||||
event: event,
|
||||
firstFireAt: fireAt,
|
||||
);
|
||||
return;
|
||||
}
|
||||
await cancelEventReminder(event.id);
|
||||
await _scheduleRemindersFrom(event: event, firstFireAt: fireAt);
|
||||
}
|
||||
|
||||
Future<void> cancelEventReminder(String eventId) async {
|
||||
await initialize();
|
||||
_cancelInAppFallbackTimers(eventId);
|
||||
|
||||
final pending = await _plugin.pendingNotificationRequests();
|
||||
for (final request in pending) {
|
||||
final payload = _decodePayload(request.payload);
|
||||
@@ -136,6 +224,23 @@ class LocalNotificationService {
|
||||
Iterable<ScheduleItemModel> events,
|
||||
) async {
|
||||
await initialize();
|
||||
await _refreshAndroidNotificationAvailability();
|
||||
if (!_canDeliverSystemNotification) {
|
||||
_clearAllInAppFallbackTimers();
|
||||
final now = DateTime.now();
|
||||
final groups = _overlapPolicy.groupByMinute(events, now: now);
|
||||
for (final group in groups) {
|
||||
if (group.isAggregate) {
|
||||
await _scheduleInAppAggregateFallback(group.events, group.fireAt);
|
||||
continue;
|
||||
}
|
||||
await _scheduleInAppFallbackRemindersFrom(
|
||||
event: group.events.first,
|
||||
firstFireAt: group.fireAt,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final now = DateTime.now();
|
||||
final groups = _overlapPolicy.groupByMinute(events, now: now);
|
||||
@@ -236,6 +341,9 @@ class LocalNotificationService {
|
||||
notes: event.metadata?.notes,
|
||||
color: event.metadata?.color,
|
||||
mode: ReminderPayloadMode.single,
|
||||
fireTimeBucket:
|
||||
fireAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds,
|
||||
version: 1,
|
||||
);
|
||||
|
||||
@@ -270,6 +378,185 @@ class LocalNotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _scheduleInAppAggregateFallback(
|
||||
List<ScheduleItemModel> events,
|
||||
DateTime fireAt,
|
||||
) async {
|
||||
if (events.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
final aggregateIds = events.map((event) => event.id).toList();
|
||||
for (final eventId in aggregateIds) {
|
||||
_cancelInAppFallbackTimers(eventId);
|
||||
}
|
||||
|
||||
final first = events.first;
|
||||
final payload = ReminderPayload(
|
||||
eventId: first.id,
|
||||
title: '你有${events.length}个日程提醒',
|
||||
startAt: first.startAt,
|
||||
endAt: first.endAt,
|
||||
timezone: first.timezone,
|
||||
mode: ReminderPayloadMode.aggregate,
|
||||
aggregateIds: aggregateIds,
|
||||
fireTimeBucket:
|
||||
fireAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds,
|
||||
version: 1,
|
||||
);
|
||||
await _scheduleInAppFallbackPayload(
|
||||
eventId: first.id,
|
||||
fireAt: fireAt,
|
||||
payload: payload,
|
||||
relatedEventIds: aggregateIds,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _scheduleInAppFallbackRemindersFrom({
|
||||
required ScheduleItemModel event,
|
||||
required DateTime firstFireAt,
|
||||
}) async {
|
||||
_cancelInAppFallbackTimers(event.id);
|
||||
|
||||
final endAt = event.endAt;
|
||||
var cursor = firstFireAt;
|
||||
Future<void> scheduleAt(DateTime fireAt) async {
|
||||
final payload = ReminderPayload(
|
||||
eventId: event.id,
|
||||
title: event.title,
|
||||
startAt: event.startAt,
|
||||
endAt: event.endAt,
|
||||
timezone: event.timezone,
|
||||
location: event.metadata?.location,
|
||||
notes: event.metadata?.notes,
|
||||
color: event.metadata?.color,
|
||||
mode: ReminderPayloadMode.single,
|
||||
fireTimeBucket:
|
||||
fireAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds,
|
||||
version: 1,
|
||||
);
|
||||
await _scheduleInAppFallbackPayload(
|
||||
eventId: event.id,
|
||||
fireAt: fireAt,
|
||||
payload: payload,
|
||||
relatedEventIds: <String>[event.id],
|
||||
);
|
||||
}
|
||||
|
||||
if (endAt == null) {
|
||||
await scheduleAt(cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
while (cursor.isBefore(endAt)) {
|
||||
await scheduleAt(cursor);
|
||||
cursor = cursor.add(const Duration(minutes: 10));
|
||||
}
|
||||
}
|
||||
|
||||
Future<Timer?> _scheduleInAppFallbackPayload({
|
||||
required String eventId,
|
||||
required DateTime fireAt,
|
||||
required ReminderPayload payload,
|
||||
required List<String> relatedEventIds,
|
||||
}) async {
|
||||
final handler = _inAppReminderHandler;
|
||||
final bucket =
|
||||
fireAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds;
|
||||
final actionExecutionId = '$eventId|fallback|$bucket';
|
||||
_trackFallback(
|
||||
actionExecutionId: actionExecutionId,
|
||||
permissionState: 'denied',
|
||||
);
|
||||
|
||||
if (handler == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final now = DateTime.now();
|
||||
final delay = fireAt.isAfter(now) ? fireAt.difference(now) : Duration.zero;
|
||||
late final Timer timer;
|
||||
timer = Timer(delay, () {
|
||||
final activeHandler = _inAppReminderHandler;
|
||||
if (activeHandler == null) {
|
||||
_unregisterInAppFallbackTimer(relatedEventIds, timer);
|
||||
return;
|
||||
}
|
||||
activeHandler(payload);
|
||||
_unregisterInAppFallbackTimer(relatedEventIds, timer);
|
||||
});
|
||||
_registerInAppFallbackTimer(relatedEventIds, timer);
|
||||
return timer;
|
||||
}
|
||||
|
||||
void _registerInAppFallbackTimer(List<String> eventIds, Timer timer) {
|
||||
for (final eventId in eventIds) {
|
||||
final timers = _inAppFallbackTimersByEventId.putIfAbsent(
|
||||
eventId,
|
||||
() => <Timer>[],
|
||||
);
|
||||
timers.add(timer);
|
||||
}
|
||||
}
|
||||
|
||||
void _unregisterInAppFallbackTimer(List<String> eventIds, Timer timer) {
|
||||
for (final eventId in eventIds) {
|
||||
final timers = _inAppFallbackTimersByEventId[eventId];
|
||||
if (timers == null) {
|
||||
continue;
|
||||
}
|
||||
timers.remove(timer);
|
||||
if (timers.isEmpty) {
|
||||
_inAppFallbackTimersByEventId.remove(eventId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _cancelInAppFallbackTimers(String eventId) {
|
||||
final timers = _inAppFallbackTimersByEventId.remove(eventId);
|
||||
if (timers == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final timer in timers.toSet()) {
|
||||
for (final entry in _inAppFallbackTimersByEventId.entries) {
|
||||
entry.value.remove(timer);
|
||||
}
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
_inAppFallbackTimersByEventId.removeWhere((_, value) => value.isEmpty);
|
||||
}
|
||||
|
||||
void _clearAllInAppFallbackTimers() {
|
||||
final allTimers = <Timer>{};
|
||||
for (final timers in _inAppFallbackTimersByEventId.values) {
|
||||
allTimers.addAll(timers);
|
||||
}
|
||||
_inAppFallbackTimersByEventId.clear();
|
||||
|
||||
for (final timer in allTimers) {
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void _trackFallback({
|
||||
required String actionExecutionId,
|
||||
required String permissionState,
|
||||
}) {
|
||||
final lifecycleState =
|
||||
WidgetsBinding.instance.lifecycleState?.name ?? 'unknown';
|
||||
_permissionFallbackTracker?.call(
|
||||
actionExecutionId: actionExecutionId,
|
||||
permissionState: permissionState,
|
||||
appLifecycleState: lifecycleState,
|
||||
platform: 'android',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _scheduleRemindersFrom({
|
||||
required ScheduleItemModel event,
|
||||
required DateTime firstFireAt,
|
||||
@@ -309,6 +596,9 @@ class LocalNotificationService {
|
||||
timezone: first.timezone,
|
||||
mode: ReminderPayloadMode.aggregate,
|
||||
aggregateIds: aggregateIds,
|
||||
fireTimeBucket:
|
||||
fireAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds,
|
||||
version: 1,
|
||||
);
|
||||
|
||||
@@ -364,31 +654,60 @@ class LocalNotificationService {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
Future<void> _onNotificationResponse(NotificationResponse response) async {
|
||||
Future<void> handleNotificationResponse(NotificationResponse response) async {
|
||||
final payloadRaw = response.payload;
|
||||
if (payloadRaw == null || payloadRaw.isEmpty) {
|
||||
return;
|
||||
}
|
||||
ReminderPayload payload;
|
||||
try {
|
||||
payload = ReminderPayload.fromJson(
|
||||
Map<String, dynamic>.from(jsonDecode(payloadRaw) as Map),
|
||||
);
|
||||
} catch (_) {
|
||||
debugPrint('failed to handle reminder notification response');
|
||||
return;
|
||||
}
|
||||
|
||||
final actionId = response.actionId;
|
||||
ReminderAction? action;
|
||||
if (actionId == _actionCancel) {
|
||||
action = ReminderAction.archive;
|
||||
} else if (actionId == _actionSnooze) {
|
||||
action = ReminderAction.snooze10m;
|
||||
}
|
||||
|
||||
if (action == null) {
|
||||
if (response.notificationResponseType ==
|
||||
NotificationResponseType.selectedNotification) {
|
||||
final presenter = _inAppReminderHandler;
|
||||
if (presenter != null) {
|
||||
await presenter(payload);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final handler = _actionHandler;
|
||||
if (handler == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final payload = ReminderPayload.fromJson(
|
||||
Map<String, dynamic>.from(jsonDecode(payloadRaw) as Map),
|
||||
);
|
||||
final actionId = response.actionId;
|
||||
if (actionId == _actionCancel) {
|
||||
await handler(action: ReminderAction.cancel, payload: payload);
|
||||
final dedupeStore = _dedupeStore;
|
||||
if (dedupeStore != null) {
|
||||
final notificationId = response.id?.toString() ?? payload.eventId;
|
||||
final fireTimeBucket =
|
||||
payload.fireTimeBucket ??
|
||||
(payload.startAt.millisecondsSinceEpoch ~/
|
||||
const Duration(minutes: 1).inMilliseconds);
|
||||
final actionExecutionId =
|
||||
'$notificationId|${action.value}|$fireTimeBucket';
|
||||
final isNew = await dedupeStore.markIfNew(actionExecutionId);
|
||||
if (!isNew) {
|
||||
return;
|
||||
}
|
||||
if (actionId == _actionSnooze) {
|
||||
await handler(action: ReminderAction.snooze10m, payload: payload);
|
||||
}
|
||||
} catch (_) {
|
||||
debugPrint('failed to handle reminder notification response');
|
||||
return;
|
||||
}
|
||||
|
||||
await handler(action: action, payload: payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../features/calendar/reminders/reminder_cold_start_queue.dart';
|
||||
|
||||
typedef ReminderNotificationResponseHandler =
|
||||
Future<void> Function(NotificationResponse response);
|
||||
|
||||
class ReminderNotificationCallbacks {
|
||||
static const String _pendingKey =
|
||||
'calendar_reminder_pending_notification_responses_v1';
|
||||
static ReminderNotificationResponseHandler? _responseHandler;
|
||||
static Future<void> _pendingStorageLock = Future<void>.value();
|
||||
static final ReminderColdStartQueue _coldStartQueue =
|
||||
ReminderColdStartQueue();
|
||||
|
||||
@visibleForTesting
|
||||
static Future<void> resetForTest() async {
|
||||
_responseHandler = null;
|
||||
_pendingStorageLock = Future<void>.value();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_pendingKey);
|
||||
}
|
||||
|
||||
static Future<void> bindResponseHandler(
|
||||
ReminderNotificationResponseHandler handler,
|
||||
) async {
|
||||
_responseHandler = handler;
|
||||
await _drainPendingResponses();
|
||||
}
|
||||
|
||||
static Future<void> onForegroundResponse(
|
||||
NotificationResponse response,
|
||||
) async {
|
||||
final handler = _responseHandler;
|
||||
if (handler == null) {
|
||||
await _enqueuePendingResponse(response);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await handler(response);
|
||||
} catch (_) {
|
||||
await _enqueuePendingResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> onBackgroundResponse(
|
||||
NotificationResponse response,
|
||||
) async {
|
||||
final handler = _responseHandler;
|
||||
if (handler == null) {
|
||||
await _enqueuePendingResponse(response);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await handler(response);
|
||||
} catch (_) {
|
||||
await _enqueuePendingResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<T> _withPendingStorageLock<T>(Future<T> Function() operation) {
|
||||
final completer = Completer<void>();
|
||||
final waitForTurn = _pendingStorageLock;
|
||||
_pendingStorageLock = waitForTurn.then((_) => completer.future);
|
||||
|
||||
return waitForTurn.then((_) => operation()).whenComplete(() {
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> _enqueuePendingResponse(
|
||||
NotificationResponse response,
|
||||
) async {
|
||||
await _withPendingStorageLock(() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final current = prefs.getStringList(_pendingKey) ?? const <String>[];
|
||||
final encoded = jsonEncode({
|
||||
'id': response.id,
|
||||
'actionId': response.actionId,
|
||||
'payload': response.payload,
|
||||
'type': response.notificationResponseType.index,
|
||||
'input': response.input,
|
||||
});
|
||||
await prefs.setStringList(_pendingKey, <String>[...current, encoded]);
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> _drainPendingResponses() async {
|
||||
final handler = _responseHandler;
|
||||
if (handler == null) {
|
||||
return;
|
||||
}
|
||||
await _withPendingStorageLock(() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final pending = prefs.getStringList(_pendingKey) ?? const <String>[];
|
||||
if (pending.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
final remaining = <String>[];
|
||||
for (final raw in pending) {
|
||||
_coldStartQueue.enqueue(() async {
|
||||
Map<String, dynamic> parsed;
|
||||
try {
|
||||
parsed = Map<String, dynamic>.from(jsonDecode(raw) as Map);
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
|
||||
final id = parsed['id'] as int?;
|
||||
final actionId = parsed['actionId'] as String?;
|
||||
final payload = parsed['payload'] as String?;
|
||||
final typeIndex = (parsed['type'] as int?) ?? 0;
|
||||
final input = parsed['input'] as String?;
|
||||
final type = NotificationResponseType.values[typeIndex.clamp(0, 1)];
|
||||
|
||||
try {
|
||||
await handler(
|
||||
NotificationResponse(
|
||||
id: id,
|
||||
actionId: actionId,
|
||||
payload: payload,
|
||||
input: input,
|
||||
notificationResponseType: type,
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
remaining.add(raw);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await _coldStartQueue.replay();
|
||||
if (remaining.isEmpty) {
|
||||
await prefs.remove(_pendingKey);
|
||||
return;
|
||||
}
|
||||
|
||||
await prefs.setStringList(_pendingKey, remaining);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> reminderNotificationTapBackground(
|
||||
NotificationResponse response,
|
||||
) async {
|
||||
await ReminderNotificationCallbacks.onBackgroundResponse(response);
|
||||
}
|
||||
Reference in New Issue
Block a user