Fix notification delivery and settings flows
This commit is contained in:
@@ -54,6 +54,19 @@
|
||||
<action android:name="android.intent.action.MEDIA_BUTTON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver"
|
||||
android:exported="false" />
|
||||
<receiver
|
||||
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility and
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:geocoding/geocoding.dart' as geocoding;
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'myquran_sholat_service.dart';
|
||||
import '../local/hive_boxes.dart';
|
||||
import '../local/models/app_settings.dart';
|
||||
|
||||
@@ -39,14 +40,13 @@ class LocationService {
|
||||
}
|
||||
|
||||
/// Get last known location from Hive settings.
|
||||
({double lat, double lng, String? cityName})? getLastKnownLocation() {
|
||||
({double lat, double lng})? getLastKnownLocation() {
|
||||
final settingsBox = Hive.box<AppSettings>(HiveBoxes.settings);
|
||||
final settings = settingsBox.get('default');
|
||||
if (settings?.lastLat != null && settings?.lastLng != null) {
|
||||
return (
|
||||
lat: settings!.lastLat!,
|
||||
lng: settings.lastLng!,
|
||||
cityName: settings.lastCityName,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
@@ -68,6 +68,93 @@ class LocationService {
|
||||
return '${lat.toStringAsFixed(2)}, ${lng.toStringAsFixed(2)}';
|
||||
}
|
||||
|
||||
Future<({String id, String name})?> resolveMyQuranCityFromPosition(
|
||||
Position position) async {
|
||||
return resolveMyQuranCityFromCoordinates(
|
||||
lat: position.latitude,
|
||||
lng: position.longitude,
|
||||
);
|
||||
}
|
||||
|
||||
Future<({String id, String name})?> resolveMyQuranCityFromCoordinates({
|
||||
required double lat,
|
||||
required double lng,
|
||||
}) async {
|
||||
try {
|
||||
final placemarks = await geocoding.placemarkFromCoordinates(
|
||||
lat,
|
||||
lng,
|
||||
);
|
||||
final place = placemarks.isNotEmpty ? placemarks.first : null;
|
||||
|
||||
final candidates = <String>{
|
||||
if (place?.locality?.trim().isNotEmpty == true) place!.locality!.trim(),
|
||||
if (place?.subAdministrativeArea?.trim().isNotEmpty == true)
|
||||
place!.subAdministrativeArea!.trim(),
|
||||
if (place?.administrativeArea?.trim().isNotEmpty == true)
|
||||
place!.administrativeArea!.trim(),
|
||||
};
|
||||
|
||||
if (candidates.isEmpty) {
|
||||
final label = await getCityName(lat, lng);
|
||||
final fallback = label.split(',').first.trim();
|
||||
if (fallback.isNotEmpty) candidates.add(fallback);
|
||||
}
|
||||
|
||||
Map<String, dynamic>? best;
|
||||
var bestScore = -1;
|
||||
|
||||
for (final raw in candidates) {
|
||||
final normalizedQuery = _normalizeCityToken(raw);
|
||||
if (normalizedQuery.isEmpty) continue;
|
||||
final found = await MyQuranSholatService.instance.searchCity(raw);
|
||||
for (final entry in found) {
|
||||
final id = (entry['id'] ?? '').toString().trim();
|
||||
final name = (entry['lokasi'] ?? '').toString().trim();
|
||||
if (id.isEmpty || name.isEmpty) continue;
|
||||
final score = _cityMatchScore(normalizedQuery, name);
|
||||
if (score > bestScore) {
|
||||
bestScore = score;
|
||||
best = {'id': id, 'name': name};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (best != null && bestScore >= 40) {
|
||||
return (id: best['id'] as String, name: best['name'] as String);
|
||||
}
|
||||
return null;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String _normalizeCityToken(String input) {
|
||||
var value = input.toLowerCase().trim();
|
||||
value = value.replaceAll(RegExp(r'[^a-z0-9\s]'), ' ');
|
||||
value = value.replaceAll(RegExp(r'\b(kota|kabupaten|city|regency)\b'), ' ');
|
||||
value = value.replaceAll(RegExp(r'\s+'), ' ').trim();
|
||||
return value;
|
||||
}
|
||||
|
||||
int _cityMatchScore(String normalizedQuery, String candidateName) {
|
||||
final normalizedCandidate = _normalizeCityToken(candidateName);
|
||||
if (normalizedCandidate.isEmpty) return 0;
|
||||
if (normalizedCandidate == normalizedQuery) return 100;
|
||||
if (normalizedCandidate.startsWith(normalizedQuery)) return 85;
|
||||
if (normalizedCandidate.contains(normalizedQuery)) return 70;
|
||||
|
||||
final queryWords = normalizedQuery.split(' ').where((w) => w.isNotEmpty);
|
||||
var matchCount = 0;
|
||||
for (final word in queryWords) {
|
||||
if (normalizedCandidate.contains(word)) {
|
||||
matchCount++;
|
||||
}
|
||||
}
|
||||
if (matchCount == 0) return 0;
|
||||
return (40 + (matchCount * 10)).clamp(0, 69);
|
||||
}
|
||||
|
||||
/// Save last known position to Hive.
|
||||
Future<void> _saveLastKnown(double lat, double lng) async {
|
||||
final settingsBox = Hive.box<AppSettings>(HiveBoxes.settings);
|
||||
@@ -75,11 +162,6 @@ class LocationService {
|
||||
if (settings != null) {
|
||||
settings.lastLat = lat;
|
||||
settings.lastLng = lng;
|
||||
try {
|
||||
settings.lastCityName = await getCityName(lat, lng);
|
||||
} catch (_) {
|
||||
// Ignore geocoding errors
|
||||
}
|
||||
await settings.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ class NotificationInboxItem {
|
||||
class NotificationInboxService {
|
||||
NotificationInboxService._();
|
||||
static final NotificationInboxService instance = NotificationInboxService._();
|
||||
static const Duration _nonCriticalReadRetention = Duration(days: 7);
|
||||
static const int _maxVisibleItems = 120;
|
||||
|
||||
Box get _box => Hive.box(HiveBoxes.notificationInbox);
|
||||
|
||||
@@ -86,16 +88,26 @@ class NotificationInboxService {
|
||||
List<NotificationInboxItem> allItems({
|
||||
String filter = 'all',
|
||||
}) {
|
||||
final now = DateTime.now();
|
||||
final items = _box.values
|
||||
.whereType<Map>()
|
||||
.map((raw) => NotificationInboxItem.fromMap(raw))
|
||||
.where((item) => !item.isExpired)
|
||||
// Curated mode: hide stale read noise while keeping pinned/important.
|
||||
.where((item) {
|
||||
if (item.isPinned) return true;
|
||||
if (_isCriticalType(item.type)) return true;
|
||||
if (!item.isRead) return true;
|
||||
final age = now.difference(item.createdAt);
|
||||
return age <= _nonCriticalReadRetention;
|
||||
}).where((item) {
|
||||
switch (filter) {
|
||||
case 'unread':
|
||||
return !item.isRead;
|
||||
case 'system':
|
||||
return item.type == 'system';
|
||||
case 'critical':
|
||||
return _isCriticalType(item.type);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@@ -106,7 +118,8 @@ class NotificationInboxService {
|
||||
}
|
||||
return b.createdAt.compareTo(a.createdAt);
|
||||
});
|
||||
return items;
|
||||
// Keep list bounded in UI to avoid overwhelming long histories.
|
||||
return items.take(_maxVisibleItems).toList();
|
||||
}
|
||||
|
||||
int unreadCount() => allItems().where((e) => !e.isRead).length;
|
||||
@@ -122,6 +135,20 @@ class NotificationInboxService {
|
||||
bool isPinned = false,
|
||||
Map<String, dynamic> meta = const <String, dynamic>{},
|
||||
}) async {
|
||||
await _upsertGroupedIfNeeded(
|
||||
title: title,
|
||||
body: body,
|
||||
type: type,
|
||||
source: source,
|
||||
isPinned: isPinned,
|
||||
expiresAt: expiresAt,
|
||||
meta: meta,
|
||||
);
|
||||
if (_shouldAggregate(type: type, source: source, isPinned: isPinned)) {
|
||||
await pruneNoise();
|
||||
return;
|
||||
}
|
||||
|
||||
final key = dedupeKey ?? _defaultKey(type, title, body);
|
||||
if (_box.containsKey(key)) {
|
||||
final existingRaw = _box.get(key);
|
||||
@@ -160,6 +187,7 @@ class NotificationInboxService {
|
||||
meta: meta,
|
||||
);
|
||||
await _box.put(key, item.toMap());
|
||||
await pruneNoise();
|
||||
await NotificationAnalyticsService.instance.track(
|
||||
'notif_inbox_created',
|
||||
dimensions: <String, dynamic>{
|
||||
@@ -255,6 +283,119 @@ class NotificationInboxService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearNonCritical() async {
|
||||
final keys = <dynamic>[];
|
||||
for (final key in _box.keys) {
|
||||
final raw = _box.get(key);
|
||||
if (raw is! Map) continue;
|
||||
final item = NotificationInboxItem.fromMap(raw);
|
||||
if (item.isPinned) continue;
|
||||
if (_isCriticalType(item.type)) continue;
|
||||
keys.add(key);
|
||||
}
|
||||
if (keys.isNotEmpty) {
|
||||
await _box.deleteAll(keys);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pruneNoise() async {
|
||||
final now = DateTime.now();
|
||||
final keys = <dynamic>[];
|
||||
for (final key in _box.keys) {
|
||||
final raw = _box.get(key);
|
||||
if (raw is! Map) continue;
|
||||
final item = NotificationInboxItem.fromMap(raw);
|
||||
if (item.isPinned || _isCriticalType(item.type)) continue;
|
||||
if (item.isRead &&
|
||||
now.difference(item.createdAt) > _nonCriticalReadRetention) {
|
||||
keys.add(key);
|
||||
}
|
||||
}
|
||||
if (keys.isNotEmpty) {
|
||||
await _box.deleteAll(keys);
|
||||
}
|
||||
}
|
||||
|
||||
bool _shouldAggregate({
|
||||
required String type,
|
||||
required String source,
|
||||
required bool isPinned,
|
||||
}) {
|
||||
if (isPinned) return false;
|
||||
if (_isCriticalType(type)) return false;
|
||||
return source == 'remote' || type == 'content' || type == 'system';
|
||||
}
|
||||
|
||||
bool _isCriticalType(String type) {
|
||||
return type == 'streak_risk' || type == 'summary' || type == 'prayer';
|
||||
}
|
||||
|
||||
Future<void> _upsertGroupedIfNeeded({
|
||||
required String title,
|
||||
required String body,
|
||||
required String type,
|
||||
required String source,
|
||||
required bool isPinned,
|
||||
required DateTime? expiresAt,
|
||||
required Map<String, dynamic> meta,
|
||||
}) async {
|
||||
if (!_shouldAggregate(type: type, source: source, isPinned: isPinned)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final dayKey = _dateKey(DateTime.now());
|
||||
final groupKey = 'group.$source.$type.$dayKey';
|
||||
final currentRaw = _box.get(groupKey);
|
||||
final currentCount = (currentRaw is Map
|
||||
? (NotificationInboxItem.fromMap(currentRaw).meta['groupCount']
|
||||
as num?)
|
||||
: null)
|
||||
?.toInt();
|
||||
final nextCount = (currentCount ?? 0) + 1;
|
||||
final groupedTitle = _groupTitle(type);
|
||||
final groupedBody = nextCount <= 1
|
||||
? body
|
||||
: '$nextCount notifikasi serupa hari ini. Terbaru: $body';
|
||||
final nextMeta = <String, dynamic>{
|
||||
...meta,
|
||||
'groupCount': nextCount,
|
||||
'isGrouped': true,
|
||||
'lastTitle': title,
|
||||
};
|
||||
|
||||
final item = NotificationInboxItem(
|
||||
id: groupKey,
|
||||
title: groupedTitle,
|
||||
body: groupedBody,
|
||||
type: type,
|
||||
createdAt: DateTime.now(),
|
||||
expiresAt: expiresAt,
|
||||
readAt: null,
|
||||
isPinned: false,
|
||||
source: source,
|
||||
deeplink: null,
|
||||
meta: nextMeta,
|
||||
);
|
||||
await _box.put(groupKey, item.toMap());
|
||||
}
|
||||
|
||||
String _groupTitle(String type) {
|
||||
switch (type) {
|
||||
case 'content':
|
||||
return 'Update Konten';
|
||||
case 'system':
|
||||
return 'Update Sistem';
|
||||
default:
|
||||
return 'Notifikasi';
|
||||
}
|
||||
}
|
||||
|
||||
String _dateKey(DateTime value) {
|
||||
final mm = value.month.toString().padLeft(2, '0');
|
||||
final dd = value.day.toString().padLeft(2, '0');
|
||||
return '${value.year}$mm$dd';
|
||||
}
|
||||
|
||||
String _defaultKey(String type, String title, String body) {
|
||||
final seed = '$type|$title|$body';
|
||||
var hash = 17;
|
||||
|
||||
@@ -4,10 +4,36 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:timezone/data/latest.dart' as tz_data;
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
import '../../app/router.dart';
|
||||
import '../local/models/app_settings.dart';
|
||||
import 'notification_analytics_service.dart';
|
||||
import 'notification_runtime_service.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void notificationTapBackgroundHandler(NotificationResponse response) {
|
||||
// Background isolates cannot safely drive GoRouter. Foreground/cold-start
|
||||
// taps are handled by NotificationService after the app is initialized.
|
||||
}
|
||||
|
||||
String? routeForNotificationPayload(String? payload) {
|
||||
final type = (payload ?? '').split('|').first.trim().toLowerCase();
|
||||
switch (type) {
|
||||
case 'report':
|
||||
case 'checklist':
|
||||
return '/checklist';
|
||||
case 'adhan':
|
||||
case 'iqamah':
|
||||
return '/';
|
||||
case 'remote':
|
||||
case 'content':
|
||||
case 'streak_risk':
|
||||
case 'system':
|
||||
return '/notifications';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class NotificationPermissionStatus {
|
||||
const NotificationPermissionStatus({
|
||||
required this.notificationsAllowed,
|
||||
@@ -148,11 +174,37 @@ class NotificationService {
|
||||
macOS: darwinSettings,
|
||||
);
|
||||
|
||||
await _plugin.initialize(settings: settings);
|
||||
await _plugin.initialize(
|
||||
settings: settings,
|
||||
onDidReceiveNotificationResponse: _handleNotificationResponse,
|
||||
onDidReceiveBackgroundNotificationResponse:
|
||||
notificationTapBackgroundHandler,
|
||||
);
|
||||
await _requestPermissions();
|
||||
await _handleLaunchNotification();
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
Future<void> _handleLaunchNotification() async {
|
||||
final details = await _plugin.getNotificationAppLaunchDetails();
|
||||
final response = details?.notificationResponse;
|
||||
if (response == null) return;
|
||||
_routeFromPayload(response.payload);
|
||||
}
|
||||
|
||||
void _handleNotificationResponse(NotificationResponse response) {
|
||||
_routeFromPayload(response.payload);
|
||||
}
|
||||
|
||||
void _routeFromPayload(String? payload) {
|
||||
final route = routeForNotificationPayload(payload);
|
||||
if (route == null) return;
|
||||
|
||||
Future<void>.delayed(Duration.zero, () {
|
||||
appRouter.go(route);
|
||||
});
|
||||
}
|
||||
|
||||
void _configureLocalTimeZone() {
|
||||
final tzId = _resolveTimeZoneIdByOffset(DateTime.now().timeZoneOffset);
|
||||
try {
|
||||
@@ -532,7 +584,10 @@ class NotificationService {
|
||||
final pending = await _plugin.pendingNotificationRequests();
|
||||
for (final request in pending) {
|
||||
final id = request.id;
|
||||
final isPrayerSchedule = id >= 100000 && id < 900000;
|
||||
// Adhan IDs: 100000..799999
|
||||
// Iqamah IDs: 800000..1499999
|
||||
// Report IDs: 700000..789999
|
||||
final isPrayerSchedule = id >= 100000 && id < 1500000;
|
||||
if (isPrayerSchedule) {
|
||||
await _plugin.cancel(id: id);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -16,6 +16,8 @@ import '../../../data/local/hive_boxes.dart';
|
||||
import '../../../data/local/models/app_settings.dart';
|
||||
import '../../../data/local/models/daily_worship_log.dart';
|
||||
import '../../../data/local/models/quran_bookmark.dart';
|
||||
import '../../../data/services/location_service.dart';
|
||||
import '../../../data/services/myquran_sholat_service.dart';
|
||||
import '../../../data/services/notification_service.dart';
|
||||
import '../data/prayer_times_provider.dart';
|
||||
|
||||
@@ -75,6 +77,307 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void _showAdhanControlInfo() {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Tombol Sound mengatur notifikasi adzan semua waktu shalat (Subuh, Dzuhur, Ashar, Maghrib, Isya).',
|
||||
),
|
||||
duration: Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showQuickLocationDialog(BuildContext context) {
|
||||
final searchCtrl = TextEditingController();
|
||||
bool isSearching = false;
|
||||
bool isDetecting = false;
|
||||
String? currentCityLabel;
|
||||
String? currentCityId;
|
||||
String? currentCityError;
|
||||
List<Map<String, dynamic>> results = [];
|
||||
Timer? debounce;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => StatefulBuilder(
|
||||
builder: (ctx, setDialogState) => AlertDialog(
|
||||
insetPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 24),
|
||||
title: const Text('Ganti Kota'),
|
||||
content: SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.85,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withValues(alpha: 0.08),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
LucideIcons.mapPin,
|
||||
size: 16,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
currentCityLabel == null
|
||||
? 'Deteksi lokasi saat ini'
|
||||
: 'Anda di $currentCityLabel',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isDetecting)
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (currentCityError != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
currentCityError!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: isDetecting
|
||||
? null
|
||||
: () async {
|
||||
setDialogState(() {
|
||||
isDetecting = true;
|
||||
currentCityError = null;
|
||||
});
|
||||
try {
|
||||
final pos = await LocationService.instance
|
||||
.getCurrentLocation();
|
||||
final fallbackLocation = pos == null
|
||||
? LocationService.instance
|
||||
.getLastKnownLocation()
|
||||
: null;
|
||||
final lat = pos?.latitude ??
|
||||
fallbackLocation?.lat;
|
||||
final lng = pos?.longitude ??
|
||||
fallbackLocation?.lng;
|
||||
if (lat == null || lng == null) {
|
||||
setDialogState(() {
|
||||
currentCityError =
|
||||
'Lokasi tidak tersedia. Pastikan izin lokasi aktif.';
|
||||
currentCityLabel = null;
|
||||
currentCityId = null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
final detectedLabel =
|
||||
(await LocationService.instance
|
||||
.getCityName(lat, lng))
|
||||
.split(',')
|
||||
.first
|
||||
.trim();
|
||||
|
||||
final resolved = await LocationService
|
||||
.instance
|
||||
.resolveMyQuranCityFromCoordinates(
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
);
|
||||
if (resolved == null) {
|
||||
setDialogState(() {
|
||||
final fallbackCity =
|
||||
detectedLabel.isEmpty
|
||||
? 'lokasi saat ini'
|
||||
: detectedLabel;
|
||||
currentCityError =
|
||||
'Lokasi Anda terdeteksi di $fallbackCity. Kami belum menemukan ID kota yang cocok di data jadwal. Silakan cari manual kota terdekat.';
|
||||
currentCityLabel = null;
|
||||
currentCityId = null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setDialogState(() {
|
||||
currentCityId = resolved.id;
|
||||
currentCityLabel = resolved.name;
|
||||
currentCityError = null;
|
||||
});
|
||||
} catch (_) {
|
||||
setDialogState(() {
|
||||
currentCityError =
|
||||
'Deteksi lokasi gagal. Coba lagi.';
|
||||
currentCityLabel = null;
|
||||
currentCityId = null;
|
||||
});
|
||||
} finally {
|
||||
if (ctx.mounted) {
|
||||
setDialogState(() {
|
||||
isDetecting = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('Deteksi Lokasi'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (currentCityId != null && currentCityLabel != null)
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
final cityName = currentCityLabel!;
|
||||
final cityId = currentCityId!;
|
||||
final box =
|
||||
Hive.box<AppSettings>(HiveBoxes.settings);
|
||||
final settings =
|
||||
box.get('default') ?? AppSettings();
|
||||
settings.lastCityName = '$cityName|$cityId';
|
||||
unawaited(settings.save());
|
||||
ref.invalidate(cityNameProvider);
|
||||
ref.invalidate(prayerTimesProvider);
|
||||
unawaited(ref.read(prayerTimesProvider.future));
|
||||
Navigator.pop(ctx);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Lokasi diubah ke $cityName'),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Gunakan Lokasi Ini'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
controller: searchCtrl,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Cari kota/kabupaten...',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
autofocus: true,
|
||||
onChanged: (q) {
|
||||
debounce?.cancel();
|
||||
debounce =
|
||||
Timer(const Duration(milliseconds: 350), () async {
|
||||
final query = q.trim();
|
||||
if (query.length < 2) {
|
||||
setDialogState(() {
|
||||
results = [];
|
||||
});
|
||||
return;
|
||||
}
|
||||
setDialogState(() {
|
||||
isSearching = true;
|
||||
});
|
||||
try {
|
||||
final found =
|
||||
await MyQuranSholatService.instance.searchCity(
|
||||
query,
|
||||
);
|
||||
if (!ctx.mounted) return;
|
||||
setDialogState(() {
|
||||
results = found;
|
||||
isSearching = false;
|
||||
});
|
||||
} catch (_) {
|
||||
if (!ctx.mounted) return;
|
||||
setDialogState(() {
|
||||
results = [];
|
||||
isSearching = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (isSearching)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
else if (results.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text(
|
||||
'Ketik minimal 2 huruf untuk mencari kota.',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
height: 260,
|
||||
child: ListView.separated(
|
||||
itemCount: results.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (_, i) {
|
||||
final city = results[i];
|
||||
final cityName = city['lokasi']?.toString() ?? '';
|
||||
final cityId = city['id']?.toString() ?? '';
|
||||
return ListTile(
|
||||
dense: true,
|
||||
title: Text(cityName),
|
||||
onTap: () {
|
||||
if (cityName.isEmpty || cityId.isEmpty) return;
|
||||
final box =
|
||||
Hive.box<AppSettings>(HiveBoxes.settings);
|
||||
final settings =
|
||||
box.get('default') ?? AppSettings();
|
||||
settings.lastCityName = '$cityName|$cityId';
|
||||
unawaited(settings.save());
|
||||
ref.invalidate(cityNameProvider);
|
||||
ref.invalidate(prayerTimesProvider);
|
||||
unawaited(ref.read(prayerTimesProvider.future));
|
||||
Navigator.pop(ctx);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Lokasi diubah ke $cityName'),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Tutup'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
).whenComplete(() {
|
||||
debounce?.cancel();
|
||||
searchCtrl.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_countdownTimer?.cancel();
|
||||
@@ -620,8 +923,26 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => _showQuickLocationDialog(context),
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
LucideIcons.mapPin,
|
||||
color: AppColors.onPrimary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: _toggleAdhanFromHero,
|
||||
onLongPress: _showAdhanControlInfo,
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
|
||||
@@ -124,6 +124,14 @@ class _DzikirScreenState extends ConsumerState<DzikirScreen>
|
||||
return _todayKey;
|
||||
}
|
||||
|
||||
bool _isFocusMode(String mode) {
|
||||
return mode == 'focus' || mode == 'slide';
|
||||
}
|
||||
|
||||
bool _useCircleCounterButton(String position) {
|
||||
return position == 'fabCircle' || position == 'circle';
|
||||
}
|
||||
|
||||
Future<void> _loadData() async {
|
||||
_refreshTodayScope();
|
||||
setState(() {
|
||||
@@ -658,7 +666,7 @@ class _DzikirScreenState extends ConsumerState<DzikirScreen>
|
||||
.listenable(keys: ['default']),
|
||||
builder: (_, settingsBox, __) {
|
||||
final settings = settingsBox.get('default') ?? AppSettings();
|
||||
final isFocusMode = settings.dzikirDisplayMode == 'focus';
|
||||
final isFocusMode = _isFocusMode(settings.dzikirDisplayMode);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -1172,7 +1180,9 @@ class _DzikirScreenState extends ConsumerState<DzikirScreen>
|
||||
);
|
||||
},
|
||||
),
|
||||
if (settings.dzikirCounterButtonPosition == 'fabCircle')
|
||||
if (_useCircleCounterButton(
|
||||
settings.dzikirCounterButtonPosition,
|
||||
))
|
||||
Positioned(
|
||||
right: 8,
|
||||
bottom: 12,
|
||||
|
||||
@@ -10,6 +10,19 @@ import '../../../data/services/notification_analytics_service.dart';
|
||||
import '../../../data/services/notification_inbox_service.dart';
|
||||
import '../../../data/services/notification_service.dart';
|
||||
|
||||
int _todayUpcomingAlarmCount(List<NotificationPendingAlert> alarms) {
|
||||
final now = DateTime.now();
|
||||
final todayStart = DateTime(now.year, now.month, now.day);
|
||||
final todayEnd = todayStart.add(const Duration(days: 1));
|
||||
return alarms.where((alarm) {
|
||||
final when = alarm.scheduledAt;
|
||||
if (when == null) return false;
|
||||
return !when.isBefore(now) &&
|
||||
!when.isBefore(todayStart) &&
|
||||
when.isBefore(todayEnd);
|
||||
}).length;
|
||||
}
|
||||
|
||||
class NotificationCenterScreen extends StatefulWidget {
|
||||
const NotificationCenterScreen({super.key});
|
||||
|
||||
@@ -56,6 +69,14 @@ class _NotificationCenterScreenState extends State<NotificationCenterScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _clearNonCritical() async {
|
||||
await NotificationInboxService.instance.clearNonCritical();
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Notifikasi non-kritis dibersihkan.')),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
@@ -91,10 +112,19 @@ class _NotificationCenterScreenState extends State<NotificationCenterScreen>
|
||||
builder: (context, _, __) {
|
||||
final unread =
|
||||
NotificationInboxService.instance.unreadCount();
|
||||
if (unread <= 0) return const SizedBox.shrink();
|
||||
return TextButton(
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: _clearNonCritical,
|
||||
child: const Text('Bersihkan'),
|
||||
),
|
||||
if (unread > 0)
|
||||
TextButton(
|
||||
onPressed: _markAllRead,
|
||||
child: const Text('Tandai semua'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -113,7 +143,9 @@ class _NotificationCenterScreenState extends State<NotificationCenterScreen>
|
||||
FutureBuilder<List<NotificationPendingAlert>>(
|
||||
future: _alarmsFuture,
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data?.length ?? 0;
|
||||
final count = _todayUpcomingAlarmCount(
|
||||
snapshot.data ?? const <NotificationPendingAlert>[],
|
||||
);
|
||||
return Tab(text: count > 0 ? 'Alarm ($count)' : 'Alarm');
|
||||
},
|
||||
),
|
||||
@@ -170,13 +202,21 @@ class _AlarmTabState extends State<_AlarmTab> {
|
||||
|
||||
final alarms = snapshot.data ?? const <NotificationPendingAlert>[];
|
||||
final now = DateTime.now();
|
||||
final upcoming = alarms
|
||||
.where((alarm) =>
|
||||
alarm.scheduledAt == null || !alarm.scheduledAt!.isBefore(now))
|
||||
.toList();
|
||||
final todayStart = DateTime(now.year, now.month, now.day);
|
||||
final todayEnd = todayStart.add(const Duration(days: 1));
|
||||
final upcoming = alarms.where((alarm) {
|
||||
final when = alarm.scheduledAt;
|
||||
if (when == null) return false;
|
||||
return !when.isBefore(now) &&
|
||||
!when.isBefore(todayStart) &&
|
||||
when.isBefore(todayEnd);
|
||||
}).toList();
|
||||
final passed = alarms
|
||||
.where((alarm) =>
|
||||
alarm.scheduledAt != null && alarm.scheduledAt!.isBefore(now))
|
||||
alarm.scheduledAt != null &&
|
||||
alarm.scheduledAt!.isBefore(now) &&
|
||||
!alarm.scheduledAt!.isBefore(todayStart) &&
|
||||
alarm.scheduledAt!.isBefore(todayEnd))
|
||||
.toList();
|
||||
final visible = _alarmFilter == 'past' ? passed : upcoming;
|
||||
|
||||
@@ -254,7 +294,7 @@ class _AlarmTabState extends State<_AlarmTab> {
|
||||
),
|
||||
child: Text(
|
||||
_alarmFilter == 'upcoming'
|
||||
? 'Tidak ada alarm akan datang.'
|
||||
? 'Tidak ada alarm tersisa untuk hari ini.'
|
||||
: 'Belum ada alarm sudah lewat.',
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
@@ -368,9 +408,7 @@ class _AlarmTabState extends State<_AlarmTab> {
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_FilterChip(
|
||||
label: upcomingCount > 0
|
||||
? 'Akan Datang ($upcomingCount)'
|
||||
: 'Akan Datang',
|
||||
label: upcomingCount > 0 ? 'Hari Ini ($upcomingCount)' : 'Hari Ini',
|
||||
selected: _alarmFilter == 'upcoming',
|
||||
isDark: isDark,
|
||||
onTap: () => setState(() => _alarmFilter = 'upcoming'),
|
||||
@@ -627,6 +665,16 @@ class _InboxTabState extends State<_InboxTab> {
|
||||
label: _inboxLabel(item.type),
|
||||
color: accent,
|
||||
),
|
||||
if ((item.meta['isGrouped'] == true) &&
|
||||
(item.meta['groupCount'] is num))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8),
|
||||
child: _TypeBadge(
|
||||
label:
|
||||
'${(item.meta['groupCount'] as num).toInt()} item',
|
||||
color: AppColors.sage,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_formatInboxTime(item.createdAt),
|
||||
@@ -694,6 +742,12 @@ class _InboxTabState extends State<_InboxTab> {
|
||||
isDark: isDark,
|
||||
onTap: () => setState(() => _filter = 'system'),
|
||||
),
|
||||
_FilterChip(
|
||||
label: 'Kritis',
|
||||
selected: _filter == 'critical',
|
||||
isDark: isDark,
|
||||
onTap: () => setState(() => _filter = 'critical'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../../../core/providers/theme_provider.dart';
|
||||
import '../../../core/widgets/ios_toggle.dart';
|
||||
import '../../../data/local/hive_boxes.dart';
|
||||
import '../../../data/local/models/app_settings.dart';
|
||||
import '../../../data/services/location_service.dart';
|
||||
import '../../../data/services/myquran_sholat_service.dart';
|
||||
import '../../../data/services/notification_service.dart';
|
||||
import '../../dashboard/data/prayer_times_provider.dart';
|
||||
@@ -106,6 +107,17 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
unawaited(ref.read(prayerTimesProvider.future));
|
||||
}
|
||||
|
||||
String _normalizeDzikirDisplayMode(String raw) {
|
||||
if (raw == 'slide') return 'focus';
|
||||
return raw;
|
||||
}
|
||||
|
||||
String _normalizeDzikirCounterButtonPosition(String raw) {
|
||||
if (raw == 'fullwidth') return 'bottomPill';
|
||||
if (raw == 'circle') return 'fabCircle';
|
||||
return raw;
|
||||
}
|
||||
|
||||
Future<void> _showQuietHoursDialog(BuildContext context) async {
|
||||
final startController =
|
||||
TextEditingController(text: _settings.quietHoursStart);
|
||||
@@ -332,10 +344,10 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final forceTilawahAutoSync = !_settings.simpleMode;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -347,7 +359,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
// ── Profile Card ──
|
||||
// ── Top-level items ──
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
@@ -361,7 +373,6 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
@@ -421,10 +432,6 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── PREFERENCES ──
|
||||
_sectionLabel('PREFERENSI'),
|
||||
const SizedBox(height: 12),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.layoutDashboard,
|
||||
@@ -456,6 +463,148 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
onChanged: _toggleDarkMode,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
_sectionLabel('GRUP PENGATURAN'),
|
||||
const SizedBox(height: 12),
|
||||
_buildGroupEntry(
|
||||
isDark,
|
||||
icon: LucideIcons.clock3,
|
||||
iconColor: const Color(0xFF0984E3),
|
||||
title: 'Shalat & Waktu',
|
||||
subtitle: 'Kota, alarm shalat, iqamah, metode',
|
||||
onTap: () => _openSettingsGroup(
|
||||
context,
|
||||
title: 'Shalat & Waktu',
|
||||
childrenBuilder: _buildShalatGroupItems,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildGroupEntry(
|
||||
isDark,
|
||||
icon: LucideIcons.bell,
|
||||
iconColor: const Color(0xFFE17055),
|
||||
title: 'Notifikasi',
|
||||
subtitle: 'Reminder, quiet hours, inbox, ringkasan',
|
||||
onTap: () => _openSettingsGroup(
|
||||
context,
|
||||
title: 'Notifikasi',
|
||||
childrenBuilder: _buildNotificationGroupItems,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildGroupEntry(
|
||||
isDark,
|
||||
icon: LucideIcons.bookOpen,
|
||||
iconColor: Colors.amber,
|
||||
title: 'Tilawah',
|
||||
subtitle: 'Target, auto-sync, auto lanjut surah',
|
||||
onTap: () => _openSettingsGroup(
|
||||
context,
|
||||
title: 'Tilawah',
|
||||
childrenBuilder: _buildTilawahGroupItems,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildGroupEntry(
|
||||
isDark,
|
||||
icon: LucideIcons.sparkles,
|
||||
iconColor: Colors.indigo,
|
||||
title: 'Dzikir',
|
||||
subtitle: 'Mode tampilan, tombol, haptic',
|
||||
onTap: () => _openSettingsGroup(
|
||||
context,
|
||||
title: 'Dzikir',
|
||||
childrenBuilder: _buildDzikirGroupItems,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildGroupEntry(
|
||||
isDark,
|
||||
icon: LucideIcons.palette,
|
||||
iconColor: const Color(0xFF6C5CE7),
|
||||
title: 'Tampilan',
|
||||
subtitle: 'Mode gelap dan ukuran font arab',
|
||||
onTap: () => _openSettingsGroup(
|
||||
context,
|
||||
title: 'Tampilan',
|
||||
childrenBuilder: _buildDisplayGroupItems,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_buildGroupEntry(
|
||||
isDark,
|
||||
icon: LucideIcons.shieldAlert,
|
||||
iconColor: Colors.red,
|
||||
title: 'Akun & Data',
|
||||
subtitle: 'Profil, versi aplikasi, reset data',
|
||||
onTap: () => _openSettingsGroup(
|
||||
context,
|
||||
title: 'Akun & Data',
|
||||
childrenBuilder: _buildAccountDataGroupItems,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openSettingsGroup(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required List<Widget> Function(bool isDark) childrenBuilder,
|
||||
}) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (ctx) {
|
||||
final isDark = Theme.of(ctx).brightness == Brightness.dark;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: ValueListenableBuilder<Box<AppSettings>>(
|
||||
valueListenable: Hive.box<AppSettings>(HiveBoxes.settings)
|
||||
.listenable(keys: ['default']),
|
||||
builder: (_, settingsBox, __) {
|
||||
_settings = settingsBox.get('default') ?? AppSettings();
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
...childrenBuilder(isDark),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Tips: Pengaturan difokuskan per kategori agar lebih mudah dicari.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isDark
|
||||
? AppColors.textSecondaryDark
|
||||
: AppColors.textSecondaryLight,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildShalatGroupItems(bool isDark) {
|
||||
return [
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.mapPin,
|
||||
iconColor: const Color(0xFF00B894),
|
||||
title: 'Kota',
|
||||
subtitle: _displayCityName,
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showLocationDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
@@ -467,16 +616,47 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
onChanged: _toggleNotifications,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.timer,
|
||||
iconColor: const Color(0xFF0984E3),
|
||||
title: 'Jeda Iqamah',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showIqamahDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.compass,
|
||||
iconColor: AppColors.sage,
|
||||
title: 'Metode Perhitungan',
|
||||
subtitle: 'Kemenag (myQuran)',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showMethodDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.building,
|
||||
iconColor: Colors.teal,
|
||||
title: 'Tingkat Sholat Rawatib',
|
||||
subtitle: _settings.rawatibLevel == 0
|
||||
? 'Mati'
|
||||
: (_settings.rawatibLevel == 1 ? 'Muakkad Saja' : 'Lengkap'),
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showRawatibDialog(context),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
_sectionLabel('PEMBERITAHUAN'),
|
||||
const SizedBox(height: 12),
|
||||
List<Widget> _buildNotificationGroupItems(bool isDark) {
|
||||
return [
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.alertCircle,
|
||||
iconColor: const Color(0xFF00B894),
|
||||
title: 'Peringatan Non-Sholat',
|
||||
subtitle: 'Streak, sistem, dan konten terbaru',
|
||||
trailing: IosToggle(
|
||||
value: _settings.alertsEnabled,
|
||||
onChanged: _toggleGlobalAlerts,
|
||||
@@ -488,48 +668,18 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
icon: LucideIcons.inbox,
|
||||
iconColor: const Color(0xFF6C5CE7),
|
||||
title: 'Kotak Masuk Pesan',
|
||||
subtitle: 'Simpan pesan untuk dibaca nanti',
|
||||
trailing: IosToggle(
|
||||
value: _settings.inboxEnabled,
|
||||
onChanged: _toggleInbox,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.activity,
|
||||
iconColor: const Color(0xFF0984E3),
|
||||
title: 'Peringatan Risiko Streak',
|
||||
trailing: IosToggle(
|
||||
value: _settings.streakRiskEnabled,
|
||||
onChanged: (v) {
|
||||
_settings.streakRiskEnabled = v;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.barChart3,
|
||||
iconColor: const Color(0xFF6C5CE7),
|
||||
title: 'Ringkasan Mingguan',
|
||||
trailing: IosToggle(
|
||||
value: _settings.weeklySummaryEnabled,
|
||||
onChanged: (v) {
|
||||
_settings.weeklySummaryEnabled = v;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.checkSquare,
|
||||
iconColor: const Color(0xFF2D98DA),
|
||||
title: 'Pengingat Checklist Harian',
|
||||
subtitle: _settings.checklistReminderTime,
|
||||
onTap: () => _showChecklistReminderTimeDialog(context),
|
||||
trailing: IosToggle(
|
||||
value: _settings.dailyChecklistReminderEnabled,
|
||||
onChanged: (v) {
|
||||
@@ -540,6 +690,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
));
|
||||
},
|
||||
),
|
||||
onTap: () => _showChecklistReminderTimeDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
@@ -547,9 +698,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
icon: LucideIcons.siren,
|
||||
iconColor: const Color(0xFFC0392B),
|
||||
title: 'Pengingat Lapor Shalat',
|
||||
subtitle: _settings.shalatReportReminderEnabled
|
||||
? 'Aktif • ${_settings.shalatReportReminderDelayMinutes} menit setelah adzan'
|
||||
: 'Nonaktif',
|
||||
subtitle: _settings.shalatReportReminderEnabled ? 'Aktif' : 'Nonaktif',
|
||||
trailing: IosToggle(
|
||||
value: _settings.shalatReportReminderEnabled,
|
||||
onChanged: (v) {
|
||||
@@ -565,8 +714,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
icon: LucideIcons.clock3,
|
||||
iconColor: const Color(0xFF16A085),
|
||||
title: 'Jeda Pengingat Lapor',
|
||||
subtitle:
|
||||
'${_settings.shalatReportReminderDelayMinutes} menit setelah waktu shalat',
|
||||
subtitle: '${_settings.shalatReportReminderDelayMinutes} menit',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showShalatReportDelayDialog(context),
|
||||
),
|
||||
@@ -577,7 +725,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
iconColor: const Color(0xFF8E44AD),
|
||||
title: 'Ulangi Pengingat Lapor',
|
||||
subtitle:
|
||||
'${_settings.shalatReportReminderRepeatCount}x • tiap ${_settings.shalatReportReminderRepeatIntervalMinutes} menit',
|
||||
'${_settings.shalatReportReminderRepeatCount}x • ${_settings.shalatReportReminderRepeatIntervalMinutes} menit',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showShalatReportRepeatDialog(context),
|
||||
),
|
||||
@@ -587,8 +735,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
icon: LucideIcons.moonStar,
|
||||
iconColor: const Color(0xFF636E72),
|
||||
title: 'Jam Tenang',
|
||||
subtitle:
|
||||
'${_settings.quietHoursStart} - ${_settings.quietHoursEnd}',
|
||||
subtitle: '${_settings.quietHoursStart} - ${_settings.quietHoursEnd}',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showQuietHoursDialog(context),
|
||||
),
|
||||
@@ -602,25 +749,12 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showPushCapDialog(context),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
];
|
||||
}
|
||||
|
||||
// ── CHECKLIST IBADAH (always visible, even in Simple Mode per user request) ──
|
||||
_sectionLabel('CHECKLIST IBADAH'),
|
||||
const SizedBox(height: 12),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.building,
|
||||
iconColor: Colors.teal,
|
||||
title: 'Tingkat Sholat Rawatib',
|
||||
subtitle: _settings.rawatibLevel == 0
|
||||
? 'Mati'
|
||||
: (_settings.rawatibLevel == 1
|
||||
? 'Muakkad Saja'
|
||||
: 'Lengkap (Semua)'),
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showRawatibDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
List<Widget> _buildTilawahGroupItems(bool isDark) {
|
||||
final forceTilawahAutoSync = !_settings.simpleMode;
|
||||
return [
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.bookOpen,
|
||||
@@ -645,8 +779,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
child: Opacity(
|
||||
opacity: forceTilawahAutoSync ? 0.78 : 1,
|
||||
child: IosToggle(
|
||||
value:
|
||||
forceTilawahAutoSync ? true : _settings.tilawahAutoSync,
|
||||
value: forceTilawahAutoSync ? true : _settings.tilawahAutoSync,
|
||||
onChanged: (v) {
|
||||
_settings.tilawahAutoSync = v;
|
||||
_saveSettings();
|
||||
@@ -662,7 +795,6 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
icon: LucideIcons.arrowRightCircle,
|
||||
iconColor: Colors.green,
|
||||
title: 'Lanjut Surah Otomatis',
|
||||
subtitle: 'Saat simpan sesi di ayat terakhir',
|
||||
trailing: IosToggle(
|
||||
value: _settings.tilawahAutoContinueNextSurah,
|
||||
onChanged: (v) {
|
||||
@@ -671,132 +803,132 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
List<Widget> _buildDzikirGroupItems(bool isDark) {
|
||||
final displayMode =
|
||||
_normalizeDzikirDisplayMode(_settings.dzikirDisplayMode);
|
||||
final counterButtonPosition = _normalizeDzikirCounterButtonPosition(
|
||||
_settings.dzikirCounterButtonPosition,
|
||||
);
|
||||
return [
|
||||
_buildSegmentSettingCard(
|
||||
isDark,
|
||||
title: 'Mode Tampilan Dzikir',
|
||||
subtitle: 'Pilih tampilan dzikir: daftar atau slide fokus',
|
||||
value: displayMode,
|
||||
options: const {'list': 'Daftar', 'focus': 'Slide'},
|
||||
onChanged: (value) {
|
||||
_settings.dzikirDisplayMode = value;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
if (displayMode == 'focus') ...[
|
||||
const SizedBox(height: 10),
|
||||
_buildSegmentSettingCard(
|
||||
isDark,
|
||||
title: 'Posisi Tombol Hitung',
|
||||
subtitle: 'Pilih letak tombol hitung pada mode slide',
|
||||
value: counterButtonPosition,
|
||||
options: const {
|
||||
'bottomPill': 'Pill Bawah',
|
||||
'fabCircle': 'Lingkaran Kanan',
|
||||
},
|
||||
onChanged: (value) {
|
||||
_settings.dzikirCounterButtonPosition = value;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.vibrate,
|
||||
iconColor: const Color(0xFF8E44AD),
|
||||
title: 'Haptic Saat Hitung',
|
||||
subtitle: 'Aktifkan getaran kecil saat tombol hitung ditekan',
|
||||
trailing: IosToggle(
|
||||
value: _settings.dzikirHapticOnCount,
|
||||
onChanged: (v) {
|
||||
_settings.dzikirHapticOnCount = v;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.skipForward,
|
||||
iconColor: const Color(0xFF16A085),
|
||||
title: 'Auto-Advance Dzikir',
|
||||
subtitle: 'Aktifkan lanjut otomatis saat hitungan dzikir selesai',
|
||||
trailing: IosToggle(
|
||||
value: _settings.dzikirAutoAdvance,
|
||||
onChanged: (v) {
|
||||
_settings.dzikirAutoAdvance = v;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.listChecks,
|
||||
iconColor: Colors.indigo,
|
||||
title: 'Amalan Tambahan',
|
||||
subtitle: 'Dzikir & Puasa Sunnah',
|
||||
subtitle: 'Kelola dzikir tambahan dan puasa sunnah',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showAmalanDialog(context),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
];
|
||||
}
|
||||
|
||||
// ── DZIKIR DISPLAY ──
|
||||
_sectionLabel('TAMPILAN DZIKIR'),
|
||||
const SizedBox(height: 12),
|
||||
_buildSegmentSettingCard(
|
||||
isDark,
|
||||
title: 'Mode Tampilan Dzikir',
|
||||
subtitle: 'Pilih daftar baris atau fokus per slide',
|
||||
value: _settings.dzikirDisplayMode,
|
||||
options: const {
|
||||
'list': 'Daftar (Baris)',
|
||||
'focus': 'Fokus (Slide)',
|
||||
},
|
||||
onChanged: (value) {
|
||||
_settings.dzikirDisplayMode = value;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
if (_settings.dzikirDisplayMode == 'focus') ...[
|
||||
const SizedBox(height: 10),
|
||||
_buildSegmentSettingCard(
|
||||
isDark,
|
||||
title: 'Posisi Tombol Hitung',
|
||||
subtitle: 'Atur posisi tombol pada mode fokus',
|
||||
value: _settings.dzikirCounterButtonPosition,
|
||||
options: const {
|
||||
'bottomPill': 'Pill Bawah',
|
||||
'fabCircle': 'Bulat Kanan Bawah',
|
||||
},
|
||||
onChanged: (value) {
|
||||
_settings.dzikirCounterButtonPosition = value;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
List<Widget> _buildDisplayGroupItems(bool isDark) {
|
||||
return [
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.arrowRight,
|
||||
iconColor: const Color(0xFF00B894),
|
||||
title: 'Lanjut Otomatis Saat Target Tercapai',
|
||||
trailing: IosToggle(
|
||||
value: _settings.dzikirAutoAdvance,
|
||||
onChanged: (v) {
|
||||
_settings.dzikirAutoAdvance = v;
|
||||
_saveSettings();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.vibrate,
|
||||
icon: LucideIcons.moon,
|
||||
iconColor: const Color(0xFF6C5CE7),
|
||||
title: 'Getaran Saat Hitung',
|
||||
title: 'Mode Gelap',
|
||||
trailing: IosToggle(
|
||||
value: _settings.dzikirHapticOnCount,
|
||||
onChanged: (v) {
|
||||
_settings.dzikirHapticOnCount = v;
|
||||
_saveSettings();
|
||||
},
|
||||
value: _isDarkMode,
|
||||
onChanged: _toggleDarkMode,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── PRAYER SETTINGS ──
|
||||
_sectionLabel('WAKTU SHOLAT'),
|
||||
const SizedBox(height: 12),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.building,
|
||||
iconColor: AppColors.primary,
|
||||
title: 'Metode Perhitungan',
|
||||
subtitle: 'Kemenag RI',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showMethodDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.mapPin,
|
||||
iconColor: const Color(0xFF00B894),
|
||||
title: 'Lokasi',
|
||||
subtitle: _displayCityName,
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showLocationDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.timer,
|
||||
iconColor: const Color(0xFFFDAA5E),
|
||||
title: 'Waktu Iqamah',
|
||||
subtitle: 'Atur per waktu sholat',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showIqamahDialog(context),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── DISPLAY ──
|
||||
_sectionLabel('TAMPILAN'),
|
||||
const SizedBox(height: 12),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.type,
|
||||
iconColor: const Color(0xFF636E72),
|
||||
title: 'Ukuran Font Arab',
|
||||
subtitle: '${_settings.arabicFontSize.round()}pt',
|
||||
trailing: SizedBox(
|
||||
width: 120,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? AppColors.surfaceDark : AppColors.surfaceLight,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: isDark
|
||||
? AppColors.primary.withValues(alpha: 0.08)
|
||||
: AppColors.cream,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'18',
|
||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
|
||||
),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: _settings.arabicFontSize,
|
||||
min: 16,
|
||||
min: 18,
|
||||
max: 40,
|
||||
divisions: 12,
|
||||
divisions: 22,
|
||||
label: '${_settings.arabicFontSize.round()}',
|
||||
activeColor: AppColors.primary,
|
||||
onChanged: (v) {
|
||||
_settings.arabicFontSize = v;
|
||||
@@ -804,64 +936,64 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
const Text(
|
||||
'40',
|
||||
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
// ── ABOUT ──
|
||||
_sectionLabel('TENTANG'),
|
||||
const SizedBox(height: 12),
|
||||
List<Widget> _buildAccountDataGroupItems(bool isDark) {
|
||||
return [
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.user,
|
||||
iconColor: AppColors.primary,
|
||||
title: 'Profil',
|
||||
subtitle: _settings.userName,
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () => _showEditProfileDialog(context),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.info,
|
||||
iconColor: AppColors.sage,
|
||||
title: 'Versi Aplikasi',
|
||||
subtitle: '1.0.0',
|
||||
subtitle: '1.0.8',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_settingRow(
|
||||
isDark,
|
||||
icon: LucideIcons.heart,
|
||||
icon: LucideIcons.trash2,
|
||||
iconColor: Colors.red,
|
||||
title: 'Beri Nilai Kami',
|
||||
title: 'Reset Semua Data',
|
||||
subtitle: 'Hapus riwayat dan reset pengaturan',
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: () {},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ── Reset Button ──
|
||||
GestureDetector(
|
||||
onTap: () => _showResetDialog(context),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: Colors.red.withValues(alpha: 0.3),
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
child: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(LucideIcons.logOut, color: Colors.red, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Hapus Semua Data',
|
||||
style: TextStyle(
|
||||
color: Colors.red,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildGroupEntry(
|
||||
bool isDark, {
|
||||
required IconData icon,
|
||||
required Color iconColor,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return _settingRow(
|
||||
isDark,
|
||||
icon: icon,
|
||||
iconColor: iconColor,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
trailing: const Icon(LucideIcons.chevronRight, size: 20),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1062,6 +1194,10 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
void _showLocationDialog(BuildContext context) {
|
||||
final searchCtrl = TextEditingController();
|
||||
bool isSearching = false;
|
||||
bool isDetecting = false;
|
||||
String? currentCityLabel;
|
||||
String? currentCityId;
|
||||
String? currentCityError;
|
||||
List<Map<String, dynamic>> results = [];
|
||||
Timer? debounce;
|
||||
|
||||
@@ -1077,6 +1213,146 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withValues(alpha: 0.08),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withValues(alpha: 0.2),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
LucideIcons.mapPin,
|
||||
size: 16,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
currentCityLabel == null
|
||||
? 'Deteksi lokasi saat ini'
|
||||
: 'Anda di $currentCityLabel',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isDetecting)
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (currentCityError != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
currentCityError!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: isDetecting
|
||||
? null
|
||||
: () async {
|
||||
setDialogState(() {
|
||||
isDetecting = true;
|
||||
currentCityError = null;
|
||||
});
|
||||
try {
|
||||
final pos = await LocationService.instance
|
||||
.getCurrentLocation();
|
||||
final fallbackLocation = pos == null
|
||||
? LocationService.instance
|
||||
.getLastKnownLocation()
|
||||
: null;
|
||||
final lat = pos?.latitude ??
|
||||
fallbackLocation?.lat;
|
||||
final lng = pos?.longitude ??
|
||||
fallbackLocation?.lng;
|
||||
if (lat == null || lng == null) {
|
||||
setDialogState(() {
|
||||
currentCityError =
|
||||
'Lokasi tidak tersedia. Pastikan izin lokasi aktif.';
|
||||
isDetecting = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
final detectedLabel =
|
||||
(await LocationService.instance
|
||||
.getCityName(lat, lng))
|
||||
.split(',')
|
||||
.first
|
||||
.trim();
|
||||
final resolved = await LocationService
|
||||
.instance
|
||||
.resolveMyQuranCityFromCoordinates(
|
||||
lat: lat,
|
||||
lng: lng,
|
||||
);
|
||||
if (resolved == null) {
|
||||
setDialogState(() {
|
||||
final fallbackCity =
|
||||
detectedLabel.isEmpty
|
||||
? 'lokasi saat ini'
|
||||
: detectedLabel;
|
||||
currentCityError =
|
||||
'Lokasi Anda terdeteksi di $fallbackCity. Kami belum menemukan ID kota yang cocok di data jadwal. Silakan cari manual kota terdekat.';
|
||||
isDetecting = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
setDialogState(() {
|
||||
currentCityId = resolved.id;
|
||||
currentCityLabel = resolved.name;
|
||||
isDetecting = false;
|
||||
});
|
||||
} catch (_) {
|
||||
setDialogState(() {
|
||||
currentCityError =
|
||||
'Deteksi lokasi gagal. Coba lagi.';
|
||||
isDetecting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: const Text('Deteksi Lokasi'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (currentCityId != null && currentCityLabel != null)
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
_settings.lastCityName =
|
||||
'$currentCityLabel|$currentCityId';
|
||||
_saveSettings();
|
||||
ref.invalidate(selectedCityIdProvider);
|
||||
ref.invalidate(cityNameProvider);
|
||||
ref.invalidate(prayerTimesProvider);
|
||||
unawaited(ref.read(prayerTimesProvider.future));
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
child: const Text('Gunakan Lokasi Ini'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: searchCtrl,
|
||||
autofocus: true,
|
||||
@@ -1167,6 +1443,8 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
// Update providers to refresh data
|
||||
ref.invalidate(selectedCityIdProvider);
|
||||
ref.invalidate(cityNameProvider);
|
||||
ref.invalidate(prayerTimesProvider);
|
||||
unawaited(ref.read(prayerTimesProvider.future));
|
||||
|
||||
Navigator.pop(ctx);
|
||||
}
|
||||
|
||||
@@ -273,6 +273,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: cupertino_icons
|
||||
sha256: "41e005c33bd814be4d3096aff55b1908d419fde52ca656c8c47719ec745873cd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.9"
|
||||
custom_lint:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: jamshalat_diary
|
||||
description: Islamic worship companion app
|
||||
publish_to: 'none'
|
||||
version: 1.0.0+1
|
||||
version: 1.0.8+9
|
||||
|
||||
environment:
|
||||
sdk: '>=3.0.0 <4.0.0'
|
||||
@@ -36,6 +36,7 @@ dependencies:
|
||||
workmanager: ^0.9.0+3
|
||||
firebase_core: ^4.1.1
|
||||
firebase_messaging: ^16.0.1
|
||||
cupertino_icons: ^1.0.8
|
||||
|
||||
# Audio
|
||||
just_audio: ^0.10.5
|
||||
|
||||
@@ -1,30 +1,15 @@
|
||||
// This is a basic Flutter widget test.
|
||||
//
|
||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||
// tree, read text, and verify that the values of widget properties are correct.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:jamshalat_diary/main.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:jamshalat_diary/app/app.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
testWidgets('App smoke test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const ProviderScope(
|
||||
child: App(),
|
||||
),
|
||||
);
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
expect(find.text('1'), findsNothing);
|
||||
|
||||
// Tap the '+' icon and trigger a frame.
|
||||
await tester.tap(find.byIcon(Icons.add));
|
||||
await tester.pump();
|
||||
|
||||
// Verify that our counter has incremented.
|
||||
expect(find.text('0'), findsNothing);
|
||||
expect(find.text('1'), findsOneWidget);
|
||||
expect(find.byType(App), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user