feat(app): add manual entry and sharing flows

This commit is contained in:
JiWoong Sul
2025-11-19 16:36:39 +09:00
parent 5ade584370
commit 947fe59486
110 changed files with 5937 additions and 3781 deletions

View File

@@ -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 {
],
);
}
}
}