fix(apps): 修复通知点击不显示ReminderOverlay和日历编辑后不刷新问题
- AppDelegate: 只存储payload字段而非整个userInfo字典 - LocalNotificationService: 移除旧的取消/稍后提醒action按钮配置 - ReminderNotificationCallbacks: 添加onNotificationPayloadReceived静态回调 - IOSNotificationPayloadBridge: 添加setPendingPayload方法 - main.dart: 设置onNotificationPayloadReceived触发ReminderOverlay显示,添加WidgetsBindingObserver处理后台恢复 - CalendarEventDetailScreen: 编辑保存后正确传递刷新信号给日视图
This commit is contained in:
+43
-12
@@ -18,7 +18,6 @@ import 'features/auth/presentation/bloc/auth_event.dart';
|
||||
import 'features/auth/presentation/bloc/auth_state.dart';
|
||||
import 'features/calendar/data/services/calendar_service.dart';
|
||||
import 'features/calendar/data/services/calendar_repository.dart';
|
||||
import 'features/calendar/reminders/reminder_action_executor.dart';
|
||||
import 'features/calendar/reminders/reminder_queue_manager.dart';
|
||||
import 'features/calendar/reminders/ui/reminder_overlay.dart';
|
||||
import 'features/calendar/ui/calendar_state_manager.dart';
|
||||
@@ -32,15 +31,6 @@ void main() async {
|
||||
await AppConstants.init();
|
||||
|
||||
final rootNavigatorKey = GlobalKey<NavigatorState>();
|
||||
sl<LocalNotificationService>().bindActionHandler(({
|
||||
required action,
|
||||
required payload,
|
||||
}) {
|
||||
return sl<ReminderActionExecutor>().handleAction(
|
||||
action: action,
|
||||
payload: payload,
|
||||
);
|
||||
});
|
||||
await sl<LocalNotificationService>().initialize();
|
||||
|
||||
final authBloc = sl<AuthBloc>();
|
||||
@@ -74,8 +64,23 @@ void main() async {
|
||||
await payloadBridge.clearPendingPayload();
|
||||
}
|
||||
|
||||
final linksyAppKey = GlobalKey();
|
||||
|
||||
ReminderNotificationCallbacks.onNotificationPayloadReceived =
|
||||
(payload) async {
|
||||
await payloadBridge.setPendingPayload(payload);
|
||||
queueManager.enqueueFromClick(payload);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final state = linksyAppKey.currentState;
|
||||
if (state != null && state is _LinksyAppState) {
|
||||
state.showReminderOverlayFromNotification();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
runApp(
|
||||
LinksyApp(
|
||||
key: linksyAppKey,
|
||||
authBloc: authBloc,
|
||||
rootNavigatorKey: rootNavigatorKey,
|
||||
sessionBootstrapper: AuthSessionBootstrapper(
|
||||
@@ -116,18 +121,39 @@ class LinksyApp extends StatefulWidget {
|
||||
State<LinksyApp> createState() => _LinksyAppState();
|
||||
}
|
||||
|
||||
class _LinksyAppState extends State<LinksyApp> {
|
||||
class _LinksyAppState extends State<LinksyApp> with WidgetsBindingObserver {
|
||||
OverlayEntry? _reminderOverlay;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_checkAndShowReminderOverlay();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_checkAndShowReminderOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _checkAndShowReminderOverlay() async {
|
||||
if (widget.queueManager.currentPayload != null) {
|
||||
_showReminderOverlay();
|
||||
return;
|
||||
}
|
||||
final pendingPayload = await widget.payloadBridge.getPendingPayload();
|
||||
if (pendingPayload != null) {
|
||||
widget.queueManager.enqueueFromClick(pendingPayload);
|
||||
await widget.payloadBridge.clearPendingPayload();
|
||||
_showReminderOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,10 +173,15 @@ class _LinksyAppState extends State<LinksyApp> {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Overlay.of(context).insert(_reminderOverlay!);
|
||||
}
|
||||
|
||||
void showReminderOverlayFromNotification() {
|
||||
if (widget.queueManager.currentPayload != null) {
|
||||
_showReminderOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
void _onReminderComplete() {
|
||||
_reminderOverlay?.remove();
|
||||
_reminderOverlay = null;
|
||||
|
||||
Reference in New Issue
Block a user