Add notification permission flow in settings
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:relationship_saver/core/config/app_config.dart';
|
||||
import 'package:relationship_saver/core/config/app_theme.dart';
|
||||
import 'package:relationship_saver/features/auth/session_controller.dart';
|
||||
import 'package:relationship_saver/features/reminders/scheduling/reminder_scheduler_provider.dart';
|
||||
import 'package:relationship_saver/features/shared/frosted_card.dart';
|
||||
import 'package:relationship_saver/integrations/backend/models/backend_models.dart';
|
||||
|
||||
@@ -74,6 +75,14 @@ class SettingsView extends ConsumerWidget {
|
||||
label: 'Realtime',
|
||||
value: 'Planned later (SSE/WebSocket)',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_SettingRow(
|
||||
compact: compact,
|
||||
label: 'Local notifications',
|
||||
value: AppConfig.enableLocalNotifications
|
||||
? 'Enabled'
|
||||
: 'Disabled',
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
@@ -99,6 +108,18 @@ class SettingsView extends ConsumerWidget {
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
label: const Text('Refresh Profile'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: AppConfig.enableLocalNotifications
|
||||
? () => _requestNotificationPermissions(
|
||||
context,
|
||||
ref,
|
||||
)
|
||||
: null,
|
||||
icon: const Icon(
|
||||
Icons.notifications_active_rounded,
|
||||
),
|
||||
label: const Text('Request Notification Access'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -127,6 +148,27 @@ class SettingsView extends ConsumerWidget {
|
||||
).showSnackBar(const SnackBar(content: Text('Signed out.')));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _requestNotificationPermissions(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
) async {
|
||||
final bool granted = await ref
|
||||
.read(reminderSchedulerProvider)
|
||||
.requestPermissions();
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
granted
|
||||
? 'Notification access granted.'
|
||||
: 'Notification access not granted.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingRow extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user