Fix notification delivery and settings flows
This commit is contained in:
@@ -117,7 +117,7 @@ final selectedCityIdProvider = StateProvider<String>((ref) {
|
||||
|
||||
/// Provider for today's prayer times using myQuran API.
|
||||
final prayerTimesProvider = FutureProvider<DaySchedule?>((ref) async {
|
||||
final cityId = ref.watch(selectedCityIdProvider);
|
||||
final cityId = await _resolveCityIdWithAutoDetect(ref);
|
||||
final today = DateFormat('yyyy-MM-dd').format(DateTime.now());
|
||||
|
||||
DaySchedule? schedule;
|
||||
@@ -202,6 +202,42 @@ final prayerTimesProvider = FutureProvider<DaySchedule?>((ref) async {
|
||||
return fallbackSchedule;
|
||||
});
|
||||
|
||||
Future<String> _resolveCityIdWithAutoDetect(Ref ref) async {
|
||||
final settingsBox = Hive.box<AppSettings>(HiveBoxes.settings);
|
||||
final settings = settingsBox.get('default') ?? AppSettings();
|
||||
final stored = settings.lastCityName ?? '';
|
||||
if (stored.contains('|')) {
|
||||
return stored.split('|').last;
|
||||
}
|
||||
|
||||
final position = await LocationService.instance.getCurrentLocation();
|
||||
final fallbackLocation =
|
||||
position == null ? LocationService.instance.getLastKnownLocation() : null;
|
||||
final lat = position?.latitude ?? fallbackLocation?.lat;
|
||||
final lng = position?.longitude ?? fallbackLocation?.lng;
|
||||
|
||||
if (lat != null && lng != null) {
|
||||
try {
|
||||
final resolved = await LocationService.instance
|
||||
.resolveMyQuranCityFromCoordinates(lat: lat, lng: lng);
|
||||
if (resolved != null) {
|
||||
settings.lastCityName = '${resolved.name}|${resolved.id}';
|
||||
if (settings.isInBox) {
|
||||
await settings.save();
|
||||
} else {
|
||||
await settingsBox.put('default', settings);
|
||||
}
|
||||
ref.read(selectedCityIdProvider.notifier).state = resolved.id;
|
||||
return resolved.id;
|
||||
}
|
||||
} catch (_) {
|
||||
// Non-fatal: fallback to default city id.
|
||||
}
|
||||
}
|
||||
|
||||
return _defaultCityId;
|
||||
}
|
||||
|
||||
Future<void> _syncAdhanNotifications(
|
||||
String cityId, DaySchedule schedule) async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user