From 24b074ff4c48d47a67b230fb0b43b32f74eb89eb Mon Sep 17 00:00:00 2001 From: JiWoong Sul Date: Thu, 29 Jan 2026 20:02:30 +0900 Subject: [PATCH] =?UTF-8?q?fix(stats):=20=EB=B0=A9=EB=AC=B8=20=ED=86=B5?= =?UTF-8?q?=EA=B3=84=20Provider=20=EC=9E=90=EB=8F=99=20=EA=B0=B1=EC=8B=A0?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - monthlyVisitStatsProvider: visitRecordsProvider watch 추가 - monthlyCategoryVisitStatsProvider: visitRecordsProvider watch로 변경 - 방문 기록 추가/확인 시 통계가 실시간으로 갱신됨 --- .../providers/visit_provider.dart | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/presentation/providers/visit_provider.dart b/lib/presentation/providers/visit_provider.dart index b413b0b..d1e8192 100644 --- a/lib/presentation/providers/visit_provider.dart +++ b/lib/presentation/providers/visit_provider.dart @@ -31,6 +31,9 @@ final monthlyVisitStatsProvider = ref, params, ) async { + // visitRecordsProvider를 watch하여 방문 기록 변경 시 자동 갱신 + await ref.watch(visitRecordsProvider.future); + final repository = ref.watch(visitRepositoryProvider); return repository.getMonthlyVisitStats(params.year, params.month); }); @@ -41,13 +44,19 @@ final monthlyCategoryVisitStatsProvider = ref, params, ) async { - final repository = ref.watch(visitRepositoryProvider); + // visitRecordsProvider를 watch하여 방문 기록 변경 시 자동 갱신 + final allRecords = await ref.watch(visitRecordsProvider.future); final restaurants = await ref.watch(restaurantListProvider.future); - final records = await repository.getVisitRecordsByDateRange( - startDate: DateTime(params.year, params.month, 1), - endDate: DateTime(params.year, params.month + 1, 0), - ); + // 해당 월의 기록만 필터링 + final startDate = DateTime(params.year, params.month, 1); + final endDate = DateTime(params.year, params.month + 1, 0); + final records = allRecords.where((record) { + return record.visitDate.isAfter( + startDate.subtract(const Duration(days: 1)), + ) && + record.visitDate.isBefore(endDate.add(const Duration(days: 1))); + }).toList(); final categoryCount = {}; for (final record in records) {