Improve notifications, tilawah flow, and dzikir structure

This commit is contained in:
Dwindi Ramadhana
2026-05-20 19:52:15 +07:00
parent c32b56c00e
commit 5195ba19ad
19 changed files with 1056 additions and 318 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hive_flutter/hive_flutter.dart';
@@ -14,6 +16,7 @@ import '../../../data/local/models/shalat_log.dart';
import '../../../data/local/models/tilawah_log.dart';
import '../../../data/local/models/dzikir_log.dart';
import '../../../data/local/models/puasa_log.dart';
import '../../../data/services/notification_service.dart';
class ChecklistScreen extends ConsumerStatefulWidget {
const ChecklistScreen({super.key});
@@ -72,6 +75,47 @@ class _ChecklistScreenState extends ConsumerState<ChecklistScreen> {
DailyWorshipLog get _todayLog => _logBox.get(_todayKey)!;
Future<void> _cancelShalatReportReminderIfCompleted(String prayerKey) async {
final sLog = _todayLog.shalatLogs[prayerKey];
if (sLog == null || !sLog.completed) return;
final cityId = _resolveCityId();
final canonical = _canonicalPrayerKey(prayerKey);
if (canonical == null) return;
await NotificationService.instance.cancelShalatReportReminders(
cityId: cityId,
dateKey: _todayKey,
canonicalPrayer: canonical,
repeatCount: _settings.shalatReportReminderRepeatCount,
);
}
String _resolveCityId() {
final stored = _settings.lastCityName ?? '';
if (stored.contains('|')) return stored.split('|').last;
return '58a2fc6ed39fd083f55d4182bf88826d';
}
String? _canonicalPrayerKey(String key) {
switch (key) {
case 'subuh':
case 'fajr':
return 'fajr';
case 'dzuhur':
case 'dhuhr':
return 'dhuhr';
case 'ashar':
case 'asr':
return 'asr';
case 'maghrib':
return 'maghrib';
case 'isya':
case 'isha':
return 'isha';
default:
return null;
}
}
void _recalculateProgress() {
final log = _todayLog;
@@ -386,6 +430,9 @@ class _ChecklistScreenState extends ConsumerState<ChecklistScreen> {
onChanged: (v) {
log.completed = v ?? false;
_recalculateProgress();
if (log.completed) {
unawaited(_cancelShalatReportReminderIfCompleted(pKey));
}
},
),
childrenPadding:
@@ -404,12 +451,14 @@ class _ChecklistScreenState extends ConsumerState<ChecklistScreen> {
log.location = 'Masjid';
log.completed = true; // Auto-check parent
_recalculateProgress();
unawaited(_cancelShalatReportReminderIfCompleted(pKey));
}),
const SizedBox(width: 16),
_radioOption('Rumah', log, () {
log.location = 'Rumah';
log.completed = true; // Auto-check parent
_recalculateProgress();
unawaited(_cancelShalatReportReminderIfCompleted(pKey));
}),
],
),