feat(app): finalize ad gated flows and weather
- add AppLogger and replace scattered print logging\n- implement ad-gated recommendation flow with reminder handling and calendar link\n- complete Bluetooth share pipeline with ad gate and merge\n- integrate KMA weather API with caching and dart-define decoding\n- add NaverUrlProcessor refactor and restore restaurant repository tests
This commit is contained in:
@@ -3,9 +3,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import '../../../core/constants/app_colors.dart';
|
||||
import '../../../core/constants/app_typography.dart';
|
||||
import '../../../domain/entities/recommendation_record.dart';
|
||||
import '../../../domain/entities/visit_record.dart';
|
||||
import '../../providers/recommendation_provider.dart';
|
||||
import '../../providers/visit_provider.dart';
|
||||
import 'widgets/visit_record_card.dart';
|
||||
import 'widgets/recommendation_record_card.dart';
|
||||
import 'widgets/visit_statistics.dart';
|
||||
|
||||
class CalendarScreen extends ConsumerStatefulWidget {
|
||||
@@ -21,7 +24,7 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
late DateTime _focusedDay;
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
late TabController _tabController;
|
||||
Map<DateTime, List<VisitRecord>> _visitRecordEvents = {};
|
||||
Map<DateTime, List<_CalendarEvent>> _events = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -37,9 +40,9 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
List<VisitRecord> _getEventsForDay(DateTime day) {
|
||||
List<_CalendarEvent> _getEventsForDay(DateTime day) {
|
||||
final normalizedDay = DateTime(day.year, day.month, day.day);
|
||||
return _visitRecordEvents[normalizedDay] ?? [];
|
||||
return _events[normalizedDay] ?? [];
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -83,22 +86,17 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
return Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final visitRecordsAsync = ref.watch(visitRecordsProvider);
|
||||
final recommendationRecordsAsync = ref.watch(
|
||||
recommendationRecordsProvider,
|
||||
);
|
||||
|
||||
// 방문 기록을 날짜별로 그룹화
|
||||
visitRecordsAsync.whenData((records) {
|
||||
_visitRecordEvents = {};
|
||||
for (final record in records) {
|
||||
final normalizedDate = DateTime(
|
||||
record.visitDate.year,
|
||||
record.visitDate.month,
|
||||
record.visitDate.day,
|
||||
);
|
||||
_visitRecordEvents[normalizedDate] = [
|
||||
...(_visitRecordEvents[normalizedDate] ?? []),
|
||||
record,
|
||||
];
|
||||
}
|
||||
});
|
||||
if (visitRecordsAsync.hasValue && recommendationRecordsAsync.hasValue) {
|
||||
final visits = visitRecordsAsync.value ?? [];
|
||||
final recommendations =
|
||||
recommendationRecordsAsync.valueOrNull ??
|
||||
<RecommendationRecord>[];
|
||||
_events = _buildEvents(visits, recommendations);
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -132,17 +130,18 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
markerBuilder: (context, day, events) {
|
||||
if (events.isEmpty) return null;
|
||||
|
||||
final visitRecords = events.cast<VisitRecord>();
|
||||
final confirmedCount = visitRecords
|
||||
.where((r) => r.isConfirmed)
|
||||
.length;
|
||||
final unconfirmedCount =
|
||||
visitRecords.length - confirmedCount;
|
||||
final calendarEvents = events.cast<_CalendarEvent>();
|
||||
final confirmedVisits = calendarEvents.where(
|
||||
(e) => e.visitRecord?.isConfirmed == true,
|
||||
);
|
||||
final recommendedOnly = calendarEvents.where(
|
||||
(e) => e.recommendationRecord != null,
|
||||
);
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (confirmedCount > 0)
|
||||
if (confirmedVisits.isNotEmpty)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
@@ -152,7 +151,7 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (unconfirmedCount > 0)
|
||||
if (recommendedOnly.isNotEmpty)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
@@ -239,6 +238,7 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
|
||||
Widget _buildDayRecords(DateTime day, bool isDark) {
|
||||
final events = _getEventsForDay(day);
|
||||
events.sort((a, b) => b.sortDate.compareTo(a.sortDate));
|
||||
|
||||
if (events.isEmpty) {
|
||||
return Center(
|
||||
@@ -294,18 +294,71 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
child: ListView.builder(
|
||||
itemCount: events.length,
|
||||
itemBuilder: (context, index) {
|
||||
final sortedEvents = events
|
||||
..sort((a, b) => b.visitDate.compareTo(a.visitDate));
|
||||
return VisitRecordCard(
|
||||
visitRecord: sortedEvents[index],
|
||||
onTap: () {
|
||||
// TODO: 맛집 상세 페이지로 이동
|
||||
},
|
||||
);
|
||||
final event = events[index];
|
||||
if (event.visitRecord != null) {
|
||||
return VisitRecordCard(
|
||||
visitRecord: event.visitRecord!,
|
||||
onTap: () {},
|
||||
);
|
||||
}
|
||||
if (event.recommendationRecord != null) {
|
||||
return RecommendationRecordCard(
|
||||
recommendation: event.recommendationRecord!,
|
||||
onConfirmVisit: () async {
|
||||
await ref
|
||||
.read(recommendationNotifierProvider.notifier)
|
||||
.confirmVisit(event.recommendationRecord!.id);
|
||||
},
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Map<DateTime, List<_CalendarEvent>> _buildEvents(
|
||||
List<VisitRecord> visits,
|
||||
List<RecommendationRecord> recommendations,
|
||||
) {
|
||||
final Map<DateTime, List<_CalendarEvent>> events = {};
|
||||
|
||||
for (final visit in visits) {
|
||||
final day = DateTime(
|
||||
visit.visitDate.year,
|
||||
visit.visitDate.month,
|
||||
visit.visitDate.day,
|
||||
);
|
||||
events[day] = [
|
||||
...(events[day] ?? []),
|
||||
_CalendarEvent(visitRecord: visit),
|
||||
];
|
||||
}
|
||||
|
||||
for (final reco in recommendations.where((r) => !r.visited)) {
|
||||
final day = DateTime(
|
||||
reco.recommendationDate.year,
|
||||
reco.recommendationDate.month,
|
||||
reco.recommendationDate.day,
|
||||
);
|
||||
events[day] = [
|
||||
...(events[day] ?? []),
|
||||
_CalendarEvent(recommendationRecord: reco),
|
||||
];
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
}
|
||||
|
||||
class _CalendarEvent {
|
||||
final VisitRecord? visitRecord;
|
||||
final RecommendationRecord? recommendationRecord;
|
||||
|
||||
_CalendarEvent({this.visitRecord, this.recommendationRecord});
|
||||
|
||||
DateTime get sortDate =>
|
||||
visitRecord?.visitDate ?? recommendationRecord!.recommendationDate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user