feat: Implement snooze functionality for notifications

- Added snooze duration setting in SettingsScreen.
- Created DebugNotificationsScreen to view pending notifications and logs.
- Integrated notification logging with NotificationDebugStore.
- Enhanced SimpleNotificationService to handle snooze actions and log notifications.
- Removed ProfileSetupScreen as it is no longer needed.
- Updated NotificationRouter to manage snooze actions without UI.
- Refactored settings provider to include snooze duration management.
This commit is contained in:
2025-08-30 01:51:38 +02:00
parent 811c1f3d6a
commit f7966ce587
8 changed files with 940 additions and 183 deletions

View File

@@ -1,20 +1,37 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; // Import this
import 'package:provider/provider.dart';
import 'package:supplements/logging.dart';
import 'providers/settings_provider.dart';
import 'providers/simple_sync_provider.dart';
import 'providers/supplement_provider.dart';
import 'screens/home_screen.dart';
import 'screens/profile_setup_screen.dart';
import 'services/notification_router.dart';
import 'services/simple_notification_service.dart';
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
// Top-level function to handle notification responses in the background
@pragma('vm:entry-point')
void notificationTapBackground(NotificationResponse notificationResponse) {
// handle action here
printLog('Background notification action tapped: ${notificationResponse.actionId}');
NotificationRouter.instance.handleNotificationResponse(notificationResponse);
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize SimpleNotificationService early
await SimpleNotificationService.instance.initialize(
onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
);
final settingsProvider = SettingsProvider();
await settingsProvider.initialize();
@@ -48,9 +65,11 @@ class MyApp extends StatelessWidget {
final supplementProvider = context.read<SupplementProvider>();
// Initialize notification router with the app's navigator
// This is done here because navigatorKey is only available after MaterialApp is built
NotificationRouter.instance.initialize(navigatorKey);
// If the app was launched via a notification, route to the proper dialog
// This needs to be called after the router is initialized with the navigatorKey
SimpleNotificationService.instance.getLaunchDetails().then((details) {
NotificationRouter.instance.handleAppLaunchDetails(details);
});
@@ -94,9 +113,7 @@ class MyApp extends StatelessWidget {
useMaterial3: true,
),
themeMode: settingsProvider.themeMode,
home: (settingsProvider.age == null || settingsProvider.gender == null)
? const ProfileSetupScreen()
: const HomeScreen(),
home: const HomeScreen(),
debugShowCheckedModeBanner: false,
);
},