feat(app): add manual entry and sharing flows
This commit is contained in:
@@ -15,13 +15,14 @@ class CalendarScreen extends ConsumerStatefulWidget {
|
||||
ConsumerState<CalendarScreen> createState() => _CalendarScreenState();
|
||||
}
|
||||
|
||||
class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTickerProviderStateMixin {
|
||||
class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late DateTime _selectedDay;
|
||||
late DateTime _focusedDay;
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
late TabController _tabController;
|
||||
Map<DateTime, List<VisitRecord>> _visitRecordEvents = {};
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -29,27 +30,31 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
_focusedDay = DateTime.now();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
List<VisitRecord> _getEventsForDay(DateTime day) {
|
||||
final normalizedDay = DateTime(day.year, day.month, day.day);
|
||||
return _visitRecordEvents[normalizedDay] ?? [];
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('방문 기록'),
|
||||
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
bottom: TabBar(
|
||||
@@ -73,12 +78,12 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildCalendarTab(bool isDark) {
|
||||
return Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final visitRecordsAsync = ref.watch(visitRecordsProvider);
|
||||
|
||||
|
||||
// 방문 기록을 날짜별로 그룹화
|
||||
visitRecordsAsync.whenData((records) {
|
||||
_visitRecordEvents = {};
|
||||
@@ -94,148 +99,147 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// 캘린더
|
||||
Card(
|
||||
margin: const EdgeInsets.all(16),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.utc(2025, 1, 1),
|
||||
lastDay: DateTime.utc(2030, 12, 31),
|
||||
focusedDay: _focusedDay,
|
||||
calendarFormat: _calendarFormat,
|
||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
});
|
||||
},
|
||||
onFormatChanged: (format) {
|
||||
setState(() {
|
||||
_calendarFormat = format;
|
||||
});
|
||||
},
|
||||
eventLoader: _getEventsForDay,
|
||||
calendarBuilders: CalendarBuilders(
|
||||
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;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (confirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (unconfirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.orange,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
margin: const EdgeInsets.all(16),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.utc(2025, 1, 1),
|
||||
lastDay: DateTime.utc(2030, 12, 31),
|
||||
focusedDay: _focusedDay,
|
||||
calendarFormat: _calendarFormat,
|
||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
});
|
||||
},
|
||||
),
|
||||
calendarStyle: CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
onFormatChanged: (format) {
|
||||
setState(() {
|
||||
_calendarFormat = format;
|
||||
});
|
||||
},
|
||||
eventLoader: _getEventsForDay,
|
||||
calendarBuilders: CalendarBuilders(
|
||||
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;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (confirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (unconfirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.orange,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
todayDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.5),
|
||||
shape: BoxShape.circle,
|
||||
calendarStyle: CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
todayDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.5),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
markersMaxCount: 2,
|
||||
markerDecoration: const BoxDecoration(
|
||||
color: AppColors.lightSecondary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
weekendTextStyle: const TextStyle(
|
||||
color: AppColors.lightError,
|
||||
),
|
||||
),
|
||||
markersMaxCount: 2,
|
||||
markerDecoration: const BoxDecoration(
|
||||
color: AppColors.lightSecondary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
weekendTextStyle: const TextStyle(
|
||||
color: AppColors.lightError,
|
||||
),
|
||||
),
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonVisible: true,
|
||||
titleCentered: true,
|
||||
formatButtonShowsNext: false,
|
||||
formatButtonDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
formatButtonTextStyle: const TextStyle(
|
||||
color: AppColors.lightPrimary,
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonVisible: true,
|
||||
titleCentered: true,
|
||||
formatButtonShowsNext: false,
|
||||
formatButtonDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
formatButtonTextStyle: const TextStyle(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 범례
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildLegend('추천받음', Colors.orange, isDark),
|
||||
const SizedBox(width: 24),
|
||||
_buildLegend('방문완료', Colors.green, isDark),
|
||||
],
|
||||
|
||||
// 범례
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildLegend('추천받음', Colors.orange, isDark),
|
||||
const SizedBox(width: 24),
|
||||
_buildLegend('방문완료', Colors.green, isDark),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 선택된 날짜의 기록
|
||||
Expanded(
|
||||
child: _buildDayRecords(_selectedDay, isDark),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 선택된 날짜의 기록
|
||||
Expanded(child: _buildDayRecords(_selectedDay, isDark)),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildLegend(String label, Color color, bool isDark) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 14,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(label, style: AppTypography.body2(isDark)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildDayRecords(DateTime day, bool isDark) {
|
||||
final events = _getEventsForDay(day);
|
||||
|
||||
|
||||
if (events.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
@@ -244,18 +248,17 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
Icon(
|
||||
Icons.event_available,
|
||||
size: 48,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'이날의 기록이 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
Text('이날의 기록이 없습니다', style: AppTypography.body2(isDark)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
@@ -265,14 +268,16 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
Icon(
|
||||
Icons.calendar_today,
|
||||
size: 20,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${day.month}월 ${day.day}일 방문 기록',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
@@ -289,7 +294,8 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
child: ListView.builder(
|
||||
itemCount: events.length,
|
||||
itemBuilder: (context, index) {
|
||||
final sortedEvents = events..sort((a, b) => b.visitDate.compareTo(a.visitDate));
|
||||
final sortedEvents = events
|
||||
..sort((a, b) => b.visitDate.compareTo(a.visitDate));
|
||||
return VisitRecordCard(
|
||||
visitRecord: sortedEvents[index],
|
||||
onTap: () {
|
||||
@@ -302,4 +308,4 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,19 +19,13 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return AlertDialog(
|
||||
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.restaurant,
|
||||
size: 48,
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
Icon(Icons.restaurant, size: 48, color: AppColors.lightPrimary),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'다녀왔음? 🍴',
|
||||
@@ -45,9 +39,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
children: [
|
||||
Text(
|
||||
restaurantName,
|
||||
style: AppTypography.heading2(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
style: AppTypography.heading2(
|
||||
isDark,
|
||||
).copyWith(color: AppColors.lightPrimary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -60,7 +54,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: (isDark ? AppColors.darkBackground : AppColors.lightBackground),
|
||||
color: (isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
@@ -69,7 +65,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 16,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
@@ -93,7 +91,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
child: Text(
|
||||
'안 갔어요',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -103,15 +103,17 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
// 방문 기록 추가
|
||||
await ref.read(visitNotifierProvider.notifier).addVisitRecord(
|
||||
restaurantId: restaurantId,
|
||||
visitDate: DateTime.now(),
|
||||
isConfirmed: true,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.addVisitRecord(
|
||||
restaurantId: restaurantId,
|
||||
visitDate: DateTime.now(),
|
||||
isConfirmed: true,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop(true);
|
||||
|
||||
|
||||
// 성공 메시지 표시
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -164,4 +166,4 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,7 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
final VisitRecord visitRecord;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const VisitRecordCard({
|
||||
super.key,
|
||||
required this.visitRecord,
|
||||
this.onTap,
|
||||
});
|
||||
const VisitRecordCard({super.key, required this.visitRecord, this.onTap});
|
||||
|
||||
String _formatTime(DateTime dateTime) {
|
||||
final hour = dateTime.hour.toString().padLeft(2, '0');
|
||||
@@ -27,7 +23,7 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: isConfirmed
|
||||
color: isConfirmed
|
||||
? AppColors.lightPrimary.withValues(alpha: 0.1)
|
||||
: Colors.orange.withValues(alpha: 0.1),
|
||||
shape: BoxShape.circle,
|
||||
@@ -43,7 +39,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final restaurantAsync = ref.watch(restaurantProvider(visitRecord.restaurantId));
|
||||
final restaurantAsync = ref.watch(
|
||||
restaurantProvider(visitRecord.restaurantId),
|
||||
);
|
||||
|
||||
return restaurantAsync.when(
|
||||
data: (restaurant) {
|
||||
@@ -73,9 +71,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
children: [
|
||||
Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -85,7 +83,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.category_outlined,
|
||||
size: 14,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
@@ -96,7 +96,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 14,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
@@ -121,15 +123,21 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
PopupMenuButton<String>(
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
color: isDark
|
||||
? AppColors.darkSurface
|
||||
: AppColors.lightSurface,
|
||||
onSelected: (value) async {
|
||||
if (value == 'confirm' && !visitRecord.isConfirmed) {
|
||||
await ref.read(visitNotifierProvider.notifier).confirmVisit(visitRecord.id);
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.confirmVisit(visitRecord.id);
|
||||
} else if (value == 'delete') {
|
||||
// 삭제 확인 다이얼로그 표시
|
||||
final confirmed = await showDialog<bool>(
|
||||
@@ -139,11 +147,13 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
content: const Text('이 방문 기록을 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(true),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.lightError,
|
||||
),
|
||||
@@ -152,9 +162,11 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
if (confirmed == true) {
|
||||
await ref.read(visitNotifierProvider.notifier).deleteVisitRecord(visitRecord.id);
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.deleteVisitRecord(visitRecord.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -164,7 +176,11 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
value: 'confirm',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.check, color: AppColors.lightPrimary, size: 20),
|
||||
const Icon(
|
||||
Icons.check,
|
||||
color: AppColors.lightPrimary,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('방문 확인', style: AppTypography.body2(isDark)),
|
||||
],
|
||||
@@ -174,11 +190,18 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete_outline, color: AppColors.lightError, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text('삭제', style: AppTypography.body2(isDark).copyWith(
|
||||
Icon(
|
||||
Icons.delete_outline,
|
||||
color: AppColors.lightError,
|
||||
)),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'삭제',
|
||||
style: AppTypography.body2(
|
||||
isDark,
|
||||
).copyWith(color: AppColors.lightError),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -194,12 +217,10 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
error: (error, stack) => const SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,24 +8,23 @@ import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
|
||||
class VisitStatistics extends ConsumerWidget {
|
||||
final DateTime selectedMonth;
|
||||
|
||||
const VisitStatistics({
|
||||
super.key,
|
||||
required this.selectedMonth,
|
||||
});
|
||||
const VisitStatistics({super.key, required this.selectedMonth});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
// 월별 통계
|
||||
final monthlyStatsAsync = ref.watch(monthlyVisitStatsProvider((
|
||||
year: selectedMonth.year,
|
||||
month: selectedMonth.month,
|
||||
)));
|
||||
|
||||
final monthlyStatsAsync = ref.watch(
|
||||
monthlyVisitStatsProvider((
|
||||
year: selectedMonth.year,
|
||||
month: selectedMonth.month,
|
||||
)),
|
||||
);
|
||||
|
||||
// 자주 방문한 맛집
|
||||
final frequentRestaurantsAsync = ref.watch(frequentRestaurantsProvider);
|
||||
|
||||
|
||||
// 주간 통계
|
||||
final weeklyStatsAsync = ref.watch(weeklyVisitStatsProvider);
|
||||
|
||||
@@ -36,11 +35,11 @@ class VisitStatistics extends ConsumerWidget {
|
||||
// 이번 달 통계
|
||||
_buildMonthlyStats(monthlyStatsAsync, isDark),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 주간 통계 차트
|
||||
_buildWeeklyChart(weeklyStatsAsync, isDark),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 자주 방문한 맛집 TOP 3
|
||||
_buildFrequentRestaurants(frequentRestaurantsAsync, ref, isDark),
|
||||
],
|
||||
@@ -48,13 +47,14 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMonthlyStats(AsyncValue<Map<String, int>> statsAsync, bool isDark) {
|
||||
Widget _buildMonthlyStats(
|
||||
AsyncValue<Map<String, int>> statsAsync,
|
||||
bool isDark,
|
||||
) {
|
||||
return Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -67,12 +67,14 @@ class VisitStatistics extends ConsumerWidget {
|
||||
const SizedBox(height: 16),
|
||||
statsAsync.when(
|
||||
data: (stats) {
|
||||
final totalVisits = stats.values.fold(0, (sum, count) => sum + count);
|
||||
final categoryCounts = stats.entries
|
||||
.where((e) => !e.key.contains('/'))
|
||||
.toList()
|
||||
..sort((a, b) => b.value.compareTo(a.value));
|
||||
|
||||
final totalVisits = stats.values.fold(
|
||||
0,
|
||||
(sum, count) => sum + count,
|
||||
);
|
||||
final categoryCounts =
|
||||
stats.entries.where((e) => !e.key.contains('/')).toList()
|
||||
..sort((a, b) => b.value.compareTo(a.value));
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildStatItem(
|
||||
@@ -87,7 +89,8 @@ class VisitStatistics extends ConsumerWidget {
|
||||
_buildStatItem(
|
||||
icon: Icons.favorite,
|
||||
label: '가장 많이 간 카테고리',
|
||||
value: '${categoryCounts.first.key} (${categoryCounts.first.value}회)',
|
||||
value:
|
||||
'${categoryCounts.first.key} (${categoryCounts.first.value}회)',
|
||||
color: AppColors.lightSecondary,
|
||||
isDark: isDark,
|
||||
),
|
||||
@@ -96,10 +99,8 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Text(
|
||||
'통계를 불러올 수 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
error: (error, stack) =>
|
||||
Text('통계를 불러올 수 없습니다', style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -107,35 +108,37 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeeklyChart(AsyncValue<Map<String, int>> statsAsync, bool isDark) {
|
||||
Widget _buildWeeklyChart(
|
||||
AsyncValue<Map<String, int>> statsAsync,
|
||||
bool isDark,
|
||||
) {
|
||||
return Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'최근 7일 방문 현황',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('최근 7일 방문 현황', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 16),
|
||||
statsAsync.when(
|
||||
data: (stats) {
|
||||
final maxCount = stats.values.isEmpty ? 1 : stats.values.reduce((a, b) => a > b ? a : b);
|
||||
|
||||
final maxCount = stats.values.isEmpty
|
||||
? 1
|
||||
: stats.values.reduce((a, b) => a > b ? a : b);
|
||||
|
||||
return SizedBox(
|
||||
height: 120,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: stats.entries.map((entry) {
|
||||
final height = maxCount == 0 ? 0.0 : (entry.value / maxCount) * 80;
|
||||
|
||||
final height = maxCount == 0
|
||||
? 0.0
|
||||
: (entry.value / maxCount) * 80;
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
@@ -153,10 +156,7 @@ class VisitStatistics extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
entry.key,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
Text(entry.key, style: AppTypography.caption(isDark)),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
@@ -164,10 +164,8 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Text(
|
||||
'차트를 불러올 수 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
error: (error, stack) =>
|
||||
Text('차트를 불러올 수 없습니다', style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -183,18 +181,13 @@ class VisitStatistics extends ConsumerWidget {
|
||||
return Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'자주 방문한 맛집 TOP 3',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('자주 방문한 맛집 TOP 3', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 16),
|
||||
frequentAsync.when(
|
||||
data: (frequentList) {
|
||||
@@ -206,78 +199,89 @@ class VisitStatistics extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Column(
|
||||
children: frequentList.take(3).map((item) {
|
||||
final restaurantAsync = ref.watch(restaurantProvider(item.restaurantId));
|
||||
|
||||
return restaurantAsync.when(
|
||||
data: (restaurant) {
|
||||
if (restaurant == null) return const SizedBox.shrink();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${frequentList.indexOf(item) + 1}',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
children:
|
||||
frequentList.take(3).map((item) {
|
||||
final restaurantAsync = ref.watch(
|
||||
restaurantProvider(item.restaurantId),
|
||||
);
|
||||
|
||||
return restaurantAsync.when(
|
||||
data: (restaurant) {
|
||||
if (restaurant == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary
|
||||
.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${frequentList.indexOf(item) + 1}',
|
||||
style: AppTypography.body1(isDark)
|
||||
.copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
restaurant.category,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${item.visitCount}회',
|
||||
style: AppTypography.body2(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox(height: 44),
|
||||
error: (error, stack) => const SizedBox.shrink(),
|
||||
);
|
||||
}).toList() as List<Widget>,
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(isDark)
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
restaurant.category,
|
||||
style: AppTypography.caption(
|
||||
isDark,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${item.visitCount}회',
|
||||
style: AppTypography.body2(isDark)
|
||||
.copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox(height: 44),
|
||||
error: (error, stack) => const SizedBox.shrink(),
|
||||
);
|
||||
}).toList()
|
||||
as List<Widget>,
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Text(
|
||||
'데이터를 불러올 수 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
error: (error, stack) =>
|
||||
Text('데이터를 불러올 수 없습니다', style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -301,26 +305,19 @@ class VisitStatistics extends ConsumerWidget {
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 20,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
Text(label, style: AppTypography.caption(isDark)),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -328,4 +325,4 @@ class VisitStatistics extends ConsumerWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user