Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ void _handleNotificationPayload(String payload) {
? List<String>.from(data['categories'] as List)
: const [];
final String sound = data['sound'] as String? ?? 'default';
final String label = data['label'] as String? ?? '';
final String? alarmId = data['alarmId'] as String?;
_router.push(
'/alarm/ring',
extra: {
'difficulty': difficulty,
'categories': categories,
'sound': sound,
'label': label,
'usesNativeAlarmAudio': true,
if (alarmId != null) 'alarmId': alarmId,
},
Expand Down
2 changes: 2 additions & 0 deletions lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GoRouter buildRouter({String initialLocation = '/'}) {
final List<String> categories =
extras['categories'] as List<String>? ?? const [];
final String sound = extras['sound'] as String? ?? 'default';
final String label = extras['label'] as String? ?? '';
final bool usesNativeAlarmAudio =
extras['usesNativeAlarmAudio'] as bool? ?? false;
final bool isTestMode = extras['isTestMode'] as bool? ?? false;
Expand All @@ -64,6 +65,7 @@ GoRouter buildRouter({String initialLocation = '/'}) {
difficulty: difficulty,
categories: categories,
sound: sound,
label: label,
usesNativeAlarmAudio: usesNativeAlarmAudio,
isTestMode: isTestMode,
alarmId: alarmId,
Expand Down
15 changes: 13 additions & 2 deletions lib/screens/alarm_ring/alarm_ring_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:math';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -29,6 +30,7 @@ class AlarmRingScreen extends ConsumerStatefulWidget {
final Difficulty difficulty;
final List<String> categories;
final String sound;
final String label;
final bool usesNativeAlarmAudio;
final bool isTestMode;
final String? alarmId;
Expand All @@ -38,6 +40,7 @@ class AlarmRingScreen extends ConsumerStatefulWidget {
required this.difficulty,
this.categories = const [],
this.sound = 'default',
this.label = '',
this.usesNativeAlarmAudio = false,
this.isTestMode = false,
this.alarmId,
Expand Down Expand Up @@ -308,11 +311,19 @@ class _AlarmRingScreenState extends ConsumerState<AlarmRingScreen> {
final DateTime snoozeTime = DateTime.now().add(
Duration(minutes: snoozeMinutes),
);
final String payload = '{"difficulty":${widget.difficulty.index}}';
final Map<String, Object> payloadData = <String, Object>{
'difficulty': widget.difficulty.index,
'categories': widget.categories,
'sound': widget.sound,
'label': widget.label,
if (widget.alarmId != null) 'alarmId': widget.alarmId!,
};
final String payload = jsonEncode(payloadData);
final String title = widget.label.isNotEmpty ? widget.label : 'DrawBell';

await NotificationService().scheduleAlarm(
id: snoozeTime.hashCode & 0x7FFFFFFF,
title: 'DrawBell',
title: title,
body: 'Snoozed alarm — draw to dismiss!',
scheduledTime: snoozeTime,
payload: payload,
Expand Down
1 change: 1 addition & 0 deletions lib/services/alarm_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AlarmService {
'difficulty': alarm.difficulty.index,
'categories': alarm.categories,
'sound': alarm.sound,
'label': alarm.label,
});

final String title = alarm.label.isNotEmpty ? alarm.label : 'DrawBell';
Expand Down
Loading