feat: 초기 프로젝트 설정 및 LunchPick 앱 구현

LunchPick(오늘 뭐 먹Z?) Flutter 앱의 초기 구현입니다.

주요 기능:
- 네이버 지도 연동 맛집 추가
- 랜덤 메뉴 추천 시스템
- 날씨 기반 거리 조정
- 방문 기록 관리
- Bluetooth 맛집 공유
- 다크모드 지원

기술 스택:
- Flutter 3.8.1+
- Riverpod 상태 관리
- Hive 로컬 DB
- Clean Architecture

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
JiWoong Sul
2025-07-30 19:03:28 +09:00
commit 85fde36157
237 changed files with 30953 additions and 0 deletions

View File

@@ -0,0 +1,305 @@
import 'package:flutter/material.dart';
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/visit_record.dart';
import '../../providers/visit_provider.dart';
import 'widgets/visit_record_card.dart';
import 'widgets/visit_statistics.dart';
class CalendarScreen extends ConsumerStatefulWidget {
const CalendarScreen({super.key});
@override
ConsumerState<CalendarScreen> createState() => _CalendarScreenState();
}
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();
_selectedDay = DateTime.now();
_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,
appBar: AppBar(
title: const Text('방문 기록'),
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
foregroundColor: Colors.white,
elevation: 0,
bottom: TabBar(
controller: _tabController,
indicatorColor: Colors.white,
indicatorWeight: 3,
tabs: const [
Tab(text: '캘린더'),
Tab(text: '통계'),
],
),
),
body: TabBarView(
controller: _tabController,
children: [
// 캘린더 탭
_buildCalendarTab(isDark),
// 통계 탭
VisitStatistics(selectedMonth: _focusedDay),
],
),
);
}
Widget _buildCalendarTab(bool isDark) {
return Consumer(
builder: (context, ref, child) {
final visitRecordsAsync = ref.watch(visitRecordsProvider);
// 방문 기록을 날짜별로 그룹화
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,
];
}
});
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,
),
),
],
);
},
),
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,
),
),
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),
],
),
),
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,
),
),
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(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.event_available,
size: 48,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(height: 16),
Text(
'이날의 기록이 없습니다',
style: AppTypography.body2(isDark),
),
],
),
);
}
return Column(
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Icon(
Icons.calendar_today,
size: 20,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 8),
Text(
'${day.month}${day.day}일 방문 기록',
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
),
const Spacer(),
Text(
'${events.length}',
style: AppTypography.body2(isDark).copyWith(
color: AppColors.lightPrimary,
fontWeight: FontWeight.bold,
),
),
],
),
),
Expanded(
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: 맛집 상세 페이지로 이동
},
);
},
),
),
],
);
}
}

View File

@@ -0,0 +1,167 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/constants/app_typography.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';
class VisitConfirmationDialog extends ConsumerWidget {
final String restaurantId;
final String restaurantName;
final DateTime recommendationTime;
const VisitConfirmationDialog({
super.key,
required this.restaurantId,
required this.restaurantName,
required this.recommendationTime,
});
@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),
),
title: Column(
children: [
Icon(
Icons.restaurant,
size: 48,
color: AppColors.lightPrimary,
),
const SizedBox(height: 8),
Text(
'다녀왔음? 🍴',
style: AppTypography.heading2(isDark),
textAlign: TextAlign.center,
),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
restaurantName,
style: AppTypography.heading2(isDark).copyWith(
color: AppColors.lightPrimary,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'어땠어요? 방문 기록을 남겨주세요!',
style: AppTypography.body2(isDark),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: (isDark ? AppColors.darkBackground : AppColors.lightBackground),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.access_time,
size: 16,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 4),
Text(
'추천 시간: ${_formatTime(recommendationTime)}',
style: AppTypography.caption(isDark),
),
],
),
),
],
),
actions: [
Row(
children: [
Expanded(
child: TextButton(
onPressed: () => Navigator.of(context).pop(false),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
),
child: Text(
'안 갔어요',
style: AppTypography.body1(isDark).copyWith(
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
),
),
),
const SizedBox(width: 8),
Expanded(
child: ElevatedButton(
onPressed: () async {
// 방문 기록 추가
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(
content: const Text('방문 기록이 저장되었습니다! 👍'),
backgroundColor: AppColors.lightPrimary,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text('갔다왔어요!'),
),
),
],
),
],
);
}
String _formatTime(DateTime dateTime) {
final hour = dateTime.hour.toString().padLeft(2, '0');
final minute = dateTime.minute.toString().padLeft(2, '0');
return '$hour:$minute';
}
static Future<bool?> show({
required BuildContext context,
required String restaurantId,
required String restaurantName,
required DateTime recommendationTime,
}) {
return showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (context) => VisitConfirmationDialog(
restaurantId: restaurantId,
restaurantName: restaurantName,
recommendationTime: recommendationTime,
),
);
}
}

View File

@@ -0,0 +1,205 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/constants/app_typography.dart';
import 'package:lunchpick/domain/entities/visit_record.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';
class VisitRecordCard extends ConsumerWidget {
final VisitRecord visitRecord;
final VoidCallback? onTap;
const VisitRecordCard({
super.key,
required this.visitRecord,
this.onTap,
});
String _formatTime(DateTime dateTime) {
final hour = dateTime.hour.toString().padLeft(2, '0');
final minute = dateTime.minute.toString().padLeft(2, '0');
return '$hour:$minute';
}
Widget _buildVisitIcon(bool isConfirmed, bool isDark) {
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: isConfirmed
? AppColors.lightPrimary.withValues(alpha: 0.1)
: Colors.orange.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: Icon(
isConfirmed ? Icons.check_circle : Icons.schedule,
color: isConfirmed ? AppColors.lightPrimary : Colors.orange,
size: 24,
),
);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final restaurantAsync = ref.watch(restaurantProvider(visitRecord.restaurantId));
return restaurantAsync.when(
data: (restaurant) {
if (restaurant == null) {
return const SizedBox.shrink();
}
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
_buildVisitIcon(visitRecord.isConfirmed, isDark),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
restaurant.name,
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Row(
children: [
Icon(
Icons.category_outlined,
size: 14,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 4),
Text(
restaurant.category,
style: AppTypography.caption(isDark),
),
const SizedBox(width: 8),
Icon(
Icons.access_time,
size: 14,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 4),
Text(
_formatTime(visitRecord.visitDate),
style: AppTypography.caption(isDark),
),
],
),
if (!visitRecord.isConfirmed) ...[
const SizedBox(height: 8),
Text(
'방문 확인이 필요합니다',
style: AppTypography.caption(isDark).copyWith(
color: Colors.orange,
fontWeight: FontWeight.w500,
),
),
],
],
),
),
PopupMenuButton<String>(
icon: Icon(
Icons.more_vert,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
onSelected: (value) async {
if (value == 'confirm' && !visitRecord.isConfirmed) {
await ref.read(visitNotifierProvider.notifier).confirmVisit(visitRecord.id);
} else if (value == 'delete') {
// 삭제 확인 다이얼로그 표시
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('방문 기록 삭제'),
content: const Text('이 방문 기록을 삭제하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('취소'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
style: TextButton.styleFrom(
foregroundColor: AppColors.lightError,
),
child: const Text('삭제'),
),
],
),
);
if (confirmed == true) {
await ref.read(visitNotifierProvider.notifier).deleteVisitRecord(visitRecord.id);
}
}
},
itemBuilder: (context) => [
if (!visitRecord.isConfirmed)
PopupMenuItem(
value: 'confirm',
child: Row(
children: [
const Icon(Icons.check, color: AppColors.lightPrimary, size: 20),
const SizedBox(width: 8),
Text('방문 확인', style: AppTypography.body2(isDark)),
],
),
),
PopupMenuItem(
value: 'delete',
child: Row(
children: [
Icon(Icons.delete_outline, color: AppColors.lightError, size: 20),
const SizedBox(width: 8),
Text('삭제', style: AppTypography.body2(isDark).copyWith(
color: AppColors.lightError,
)),
],
),
),
],
),
],
),
),
),
);
},
loading: () => const Card(
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Padding(
padding: EdgeInsets.all(16),
child: Center(
child: CircularProgressIndicator(),
),
),
),
error: (error, stack) => const SizedBox.shrink(),
);
}
}

View File

@@ -0,0 +1,331 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/constants/app_typography.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
class VisitStatistics extends ConsumerWidget {
final DateTime 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 frequentRestaurantsAsync = ref.watch(frequentRestaurantsProvider);
// 주간 통계
final weeklyStatsAsync = ref.watch(weeklyVisitStatsProvider);
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
// 이번 달 통계
_buildMonthlyStats(monthlyStatsAsync, isDark),
const SizedBox(height: 16),
// 주간 통계 차트
_buildWeeklyChart(weeklyStatsAsync, isDark),
const SizedBox(height: 16),
// 자주 방문한 맛집 TOP 3
_buildFrequentRestaurants(frequentRestaurantsAsync, ref, 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),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${selectedMonth.month}월 방문 통계',
style: AppTypography.heading2(isDark),
),
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));
return Column(
children: [
_buildStatItem(
icon: Icons.restaurant,
label: '총 방문 횟수',
value: '$totalVisits회',
color: AppColors.lightPrimary,
isDark: isDark,
),
const SizedBox(height: 12),
if (categoryCounts.isNotEmpty) ...[
_buildStatItem(
icon: Icons.favorite,
label: '가장 많이 간 카테고리',
value: '${categoryCounts.first.key} (${categoryCounts.first.value}회)',
color: AppColors.lightSecondary,
isDark: isDark,
),
],
],
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Text(
'통계를 불러올 수 없습니다',
style: AppTypography.body2(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),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
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);
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;
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
entry.value.toString(),
style: AppTypography.caption(isDark),
),
const SizedBox(height: 4),
Container(
width: 30,
height: height,
decoration: BoxDecoration(
color: AppColors.lightPrimary,
borderRadius: BorderRadius.circular(4),
),
),
const SizedBox(height: 4),
Text(
entry.key,
style: AppTypography.caption(isDark),
),
],
);
}).toList(),
),
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Text(
'차트를 불러올 수 없습니다',
style: AppTypography.body2(isDark),
),
),
],
),
),
);
}
Widget _buildFrequentRestaurants(
AsyncValue<List<({String restaurantId, int visitCount})>> frequentAsync,
WidgetRef ref,
bool isDark,
) {
return Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
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),
),
const SizedBox(height: 16),
frequentAsync.when(
data: (frequentList) {
if (frequentList.isEmpty) {
return Center(
child: Text(
'아직 방문 기록이 없습니다',
style: AppTypography.body2(isDark),
),
);
}
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,
),
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),
),
),
],
),
),
);
}
Widget _buildStatItem({
required IconData icon,
required String label,
required String value,
required Color color,
required bool isDark,
}) {
return Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: color.withOpacity(0.1),
shape: BoxShape.circle,
),
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(
value,
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
),
],
);
}
}

View File

@@ -0,0 +1,88 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import '../../../core/constants/app_colors.dart';
import '../../../core/services/notification_service.dart';
import '../../providers/notification_handler_provider.dart';
import '../share/share_screen.dart';
import '../restaurant_list/restaurant_list_screen.dart';
import '../random_selection/random_selection_screen.dart';
import '../calendar/calendar_screen.dart';
import '../settings/settings_screen.dart';
class MainScreen extends ConsumerStatefulWidget {
final int initialTab;
const MainScreen({super.key, this.initialTab = 2});
@override
ConsumerState<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends ConsumerState<MainScreen> {
late int _selectedIndex;
@override
void initState() {
super.initState();
_selectedIndex = widget.initialTab;
// 알림 핸들러 설정
WidgetsBinding.instance.addPostFrameCallback((_) {
NotificationService.onNotificationTap = (NotificationResponse response) {
if (mounted) {
ref.read(notificationHandlerProvider.notifier).handleNotificationTap(
context,
response.payload,
);
}
};
});
}
@override
void dispose() {
NotificationService.onNotificationTap = null;
super.dispose();
}
final List<({IconData icon, String label})> _navItems = [
(icon: Icons.share, label: '공유'),
(icon: Icons.restaurant, label: '맛집'),
(icon: Icons.casino, label: '뽑기'),
(icon: Icons.calendar_month, label: '기록'),
(icon: Icons.settings, label: '설정'),
];
final List<Widget> _screens = [
const ShareScreen(),
const RestaurantListScreen(),
const RandomSelectionScreen(),
const CalendarScreen(),
const SettingsScreen(),
];
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
body: IndexedStack(
index: _selectedIndex,
children: _screens,
),
bottomNavigationBar: NavigationBar(
selectedIndex: _selectedIndex,
onDestinationSelected: (index) {
setState(() => _selectedIndex = index);
},
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
destinations: _navItems.map((item) => NavigationDestination(
icon: Icon(item.icon),
label: item.label,
)).toList(),
indicatorColor: AppColors.lightPrimary.withOpacity(0.2),
),
);
}
}

View File

@@ -0,0 +1,450 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:geolocator/geolocator.dart';
import '../../../core/constants/app_colors.dart';
import '../../../core/constants/app_typography.dart';
import '../../../domain/entities/weather_info.dart';
import '../../../domain/entities/restaurant.dart';
import '../../providers/restaurant_provider.dart';
import '../../providers/weather_provider.dart';
import '../../providers/location_provider.dart';
import '../../providers/recommendation_provider.dart';
import 'widgets/recommendation_result_dialog.dart';
class RandomSelectionScreen extends ConsumerStatefulWidget {
const RandomSelectionScreen({super.key});
@override
ConsumerState<RandomSelectionScreen> createState() => _RandomSelectionScreenState();
}
class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
double _distanceValue = 500;
final List<String> _selectedCategories = [];
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
appBar: AppBar(
title: const Text('오늘 뭐 먹Z?'),
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
foregroundColor: Colors.white,
elevation: 0,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 맛집 리스트 현황 카드
Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
children: [
const Icon(
Icons.restaurant,
size: 48,
color: AppColors.lightPrimary,
),
const SizedBox(height: 12),
Consumer(
builder: (context, ref, child) {
final restaurantsAsync = ref.watch(restaurantListProvider);
return restaurantsAsync.when(
data: (restaurants) => Text(
'${restaurants.length}',
style: AppTypography.heading1(isDark).copyWith(
color: AppColors.lightPrimary,
),
),
loading: () => const CircularProgressIndicator(
color: AppColors.lightPrimary,
),
error: (_, __) => Text(
'0개',
style: AppTypography.heading1(isDark).copyWith(
color: AppColors.lightPrimary,
),
),
);
},
),
Text(
'등록된 맛집',
style: AppTypography.body2(isDark),
),
],
),
),
),
const SizedBox(height: 16),
// 날씨 정보 카드
Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Consumer(
builder: (context, ref, child) {
final weatherAsync = ref.watch(weatherProvider);
return weatherAsync.when(
data: (weather) => Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildWeatherData('지금', weather.current, isDark),
Container(
width: 1,
height: 50,
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
),
_buildWeatherData('1시간 후', weather.nextHour, isDark),
],
),
loading: () => const Center(
child: CircularProgressIndicator(
color: AppColors.lightPrimary,
),
),
error: (_, __) => Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildWeatherInfo('지금', Icons.wb_sunny, '맑음', 20, isDark),
Container(
width: 1,
height: 50,
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
),
_buildWeatherInfo('1시간 후', Icons.wb_sunny, '맑음', 22, isDark),
],
),
);
},
),
),
),
const SizedBox(height: 16),
// 거리 설정 카드
Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'최대 거리',
style: AppTypography.heading2(isDark),
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: SliderTheme(
data: SliderTheme.of(context).copyWith(
activeTrackColor: AppColors.lightPrimary,
inactiveTrackColor: AppColors.lightPrimary.withValues(alpha: 0.3),
thumbColor: AppColors.lightPrimary,
trackHeight: 4,
),
child: Slider(
value: _distanceValue,
min: 100,
max: 2000,
divisions: 19,
onChanged: (value) {
setState(() => _distanceValue = value);
},
),
),
),
const SizedBox(width: 12),
Text(
'${_distanceValue.toInt()}m',
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 8),
Consumer(
builder: (context, ref, child) {
final locationAsync = ref.watch(currentLocationProvider);
final restaurantsAsync = ref.watch(restaurantListProvider);
if (locationAsync.hasValue && restaurantsAsync.hasValue) {
final location = locationAsync.value;
final restaurants = restaurantsAsync.value;
if (location != null && restaurants != null) {
final count = _getRestaurantCountInRange(
restaurants,
location,
_distanceValue,
);
return Text(
'$count개 맛집 포함',
style: AppTypography.caption(isDark),
);
}
}
return Text(
'위치 정보를 가져오는 중...',
style: AppTypography.caption(isDark),
);
},
),
],
),
),
),
const SizedBox(height: 16),
// 카테고리 선택 카드
Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'카테고리',
style: AppTypography.heading2(isDark),
),
const SizedBox(height: 12),
Consumer(
builder: (context, ref, child) {
final categoriesAsync = ref.watch(categoriesProvider);
return categoriesAsync.when(
data: (categories) => Wrap(
spacing: 8,
runSpacing: 8,
children: categories.isEmpty
? [const Text('카테고리 없음')]
: categories.map((category) => _buildCategoryChip(category, isDark)).toList(),
),
loading: () => const CircularProgressIndicator(),
error: (_, __) => const Text('카테고리를 불러올 수 없습니다'),
);
},
),
],
),
),
),
const SizedBox(height: 24),
// 추천받기 버튼
ElevatedButton(
onPressed: _canRecommend() ? _startRecommendation : null,
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 20),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 3,
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.play_arrow, size: 28),
SizedBox(width: 8),
Text(
'광고보고 추천받기',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
),
);
}
Widget _buildWeatherData(String label, WeatherData weatherData, bool isDark) {
return Column(
children: [
Text(label, style: AppTypography.caption(isDark)),
const SizedBox(height: 8),
Icon(
weatherData.isRainy ? Icons.umbrella : Icons.wb_sunny,
color: weatherData.isRainy ? Colors.blue : Colors.orange,
size: 32,
),
const SizedBox(height: 4),
Text(
'${weatherData.temperature}°C',
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
weatherData.description,
style: AppTypography.caption(isDark),
),
],
);
}
Widget _buildWeatherInfo(String label, IconData icon, String description, int temperature, bool isDark) {
return Column(
children: [
Text(label, style: AppTypography.caption(isDark)),
const SizedBox(height: 8),
Icon(
icon,
color: Colors.orange,
size: 32,
),
const SizedBox(height: 4),
Text(
'$temperature°C',
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
description,
style: AppTypography.caption(isDark),
),
],
);
}
Widget _buildCategoryChip(String category, bool isDark) {
final isSelected = _selectedCategories.contains(category);
return FilterChip(
label: Text(category),
selected: isSelected,
onSelected: (selected) {
setState(() {
if (selected) {
_selectedCategories.add(category);
} else {
_selectedCategories.remove(category);
}
});
},
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightBackground,
selectedColor: AppColors.lightPrimary.withValues(alpha: 0.2),
checkmarkColor: AppColors.lightPrimary,
labelStyle: TextStyle(
color: isSelected ? AppColors.lightPrimary : (isDark ? AppColors.darkTextPrimary : AppColors.lightTextPrimary),
),
side: BorderSide(
color: isSelected ? AppColors.lightPrimary : (isDark ? AppColors.darkDivider : AppColors.lightDivider),
),
);
}
int _getRestaurantCountInRange(
List<Restaurant> restaurants,
Position location,
double maxDistance,
) {
return restaurants.where((restaurant) {
final distance = Geolocator.distanceBetween(
location.latitude,
location.longitude,
restaurant.latitude,
restaurant.longitude,
);
return distance <= maxDistance;
}).length;
}
bool _canRecommend() {
final locationAsync = ref.read(currentLocationProvider);
final restaurantsAsync = ref.read(restaurantListProvider);
if (!locationAsync.hasValue || !restaurantsAsync.hasValue) return false;
final location = locationAsync.value;
final restaurants = restaurantsAsync.value;
if (location == null || restaurants == null || restaurants.isEmpty) return false;
final count = _getRestaurantCountInRange(restaurants, location, _distanceValue);
return count > 0;
}
Future<void> _startRecommendation() async {
final notifier = ref.read(recommendationNotifierProvider.notifier);
await notifier.getRandomRecommendation(
maxDistance: _distanceValue,
selectedCategories: _selectedCategories,
);
final result = ref.read(recommendationNotifierProvider);
result.whenData((restaurant) {
if (restaurant != null && mounted) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => RecommendationResultDialog(
restaurant: restaurant,
onReroll: () {
Navigator.pop(context);
_startRecommendation();
},
onConfirmVisit: () {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('맛있게 드세요! 🍴'),
backgroundColor: AppColors.lightPrimary,
),
);
},
),
);
} else if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('조건에 맞는 맛집이 없습니다'),
backgroundColor: AppColors.lightError,
),
);
}
});
}
}

View File

@@ -0,0 +1,230 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/constants/app_typography.dart';
import 'package:lunchpick/core/services/notification_service.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
import 'package:lunchpick/presentation/providers/settings_provider.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';
class RecommendationResultDialog extends ConsumerWidget {
final Restaurant restaurant;
final VoidCallback onReroll;
final VoidCallback onConfirmVisit;
const RecommendationResultDialog({
super.key,
required this.restaurant,
required this.onReroll,
required this.onConfirmVisit,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Dialog(
backgroundColor: Colors.transparent,
child: Container(
decoration: BoxDecoration(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
borderRadius: BorderRadius.circular(20),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 상단 이미지 영역
Container(
height: 150,
decoration: BoxDecoration(
color: AppColors.lightPrimary,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(20),
),
),
child: Stack(
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.restaurant_menu,
size: 64,
color: Colors.white,
),
const SizedBox(height: 8),
Text(
'오늘의 추천!',
style: AppTypography.heading2(false).copyWith(
color: Colors.white,
),
),
],
),
),
Positioned(
top: 8,
right: 8,
child: IconButton(
icon: const Icon(Icons.close, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
),
],
),
),
// 맛집 정보
Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 가게 이름
Center(
child: Text(
restaurant.name,
style: AppTypography.heading1(isDark),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 8),
// 카테고리
Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
),
child: Text(
'${restaurant.category} > ${restaurant.subCategory}',
style: AppTypography.body2(isDark).copyWith(
color: AppColors.lightPrimary,
),
),
),
),
if (restaurant.description != null) ...[
const SizedBox(height: 16),
Text(
restaurant.description!,
style: AppTypography.body2(isDark),
textAlign: TextAlign.center,
),
],
const SizedBox(height: 16),
const Divider(),
const SizedBox(height: 16),
// 주소
Row(
children: [
Icon(
Icons.location_on,
size: 20,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 8),
Expanded(
child: Text(
restaurant.roadAddress,
style: AppTypography.body2(isDark),
),
),
],
),
if (restaurant.phoneNumber != null) ...[
const SizedBox(height: 8),
Row(
children: [
Icon(
Icons.phone,
size: 20,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 8),
Text(
restaurant.phoneNumber!,
style: AppTypography.body2(isDark),
),
],
),
],
const SizedBox(height: 24),
// 버튼들
Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: onReroll,
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
side: const BorderSide(color: AppColors.lightPrimary),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text(
'다시 뽑기',
style: TextStyle(color: AppColors.lightPrimary),
),
),
),
const SizedBox(width: 12),
Expanded(
child: ElevatedButton(
onPressed: () async {
final recommendationTime = DateTime.now();
// 알림 설정 확인
final notificationEnabled = await ref.read(notificationEnabledProvider.future);
if (notificationEnabled) {
// 알림 예약
final notificationService = NotificationService();
await notificationService.scheduleVisitReminder(
restaurantId: restaurant.id,
restaurantName: restaurant.name,
recommendationTime: recommendationTime,
);
}
// 방문 기록 자동 생성 (미확인 상태로)
await ref.read(visitNotifierProvider.notifier).createVisitFromRecommendation(
restaurantId: restaurant.id,
recommendationTime: recommendationTime,
);
// 기존 콜백 실행
onConfirmVisit();
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 12),
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text('여기로 갈게요!'),
),
),
],
),
],
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,183 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/constants/app_colors.dart';
import '../../../core/constants/app_typography.dart';
import '../../providers/restaurant_provider.dart';
import '../../widgets/category_selector.dart';
import 'widgets/restaurant_card.dart';
import 'widgets/add_restaurant_dialog.dart';
class RestaurantListScreen extends ConsumerStatefulWidget {
const RestaurantListScreen({super.key});
@override
ConsumerState<RestaurantListScreen> createState() => _RestaurantListScreenState();
}
class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
final _searchController = TextEditingController();
bool _isSearching = false;
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final searchQuery = ref.watch(searchQueryProvider);
final selectedCategory = ref.watch(selectedCategoryProvider);
final restaurantsAsync = ref.watch(
searchQuery.isNotEmpty || selectedCategory != null
? filteredRestaurantsProvider
: restaurantListProvider
);
return Scaffold(
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
appBar: AppBar(
title: _isSearching
? TextField(
controller: _searchController,
autofocus: true,
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
hintText: '맛집 검색...',
hintStyle: TextStyle(color: Colors.white70),
border: InputBorder.none,
),
onChanged: (value) {
ref.read(searchQueryProvider.notifier).state = value;
},
)
: const Text('내 맛집 리스트'),
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
foregroundColor: Colors.white,
elevation: 0,
actions: [
if (_isSearching) ...[
IconButton(
icon: const Icon(Icons.close),
onPressed: () {
setState(() {
_isSearching = false;
_searchController.clear();
ref.read(searchQueryProvider.notifier).state = '';
});
},
),
] else ...[
IconButton(
icon: const Icon(Icons.search),
onPressed: () {
setState(() {
_isSearching = true;
});
},
),
],
],
),
body: Column(
children: [
// 카테고리 선택기
Container(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
padding: const EdgeInsets.symmetric(vertical: 8),
child: CategorySelector(
selectedCategory: selectedCategory,
onCategorySelected: (category) {
ref.read(selectedCategoryProvider.notifier).state = category;
},
showAllOption: true,
),
),
// 맛집 목록
Expanded(
child: restaurantsAsync.when(
data: (restaurants) {
if (restaurants.isEmpty) {
return _buildEmptyState(isDark);
}
return ListView.builder(
itemCount: restaurants.length,
itemBuilder: (context, index) {
return RestaurantCard(restaurant: restaurants[index]);
},
);
},
loading: () => const Center(
child: CircularProgressIndicator(
color: AppColors.lightPrimary,
),
),
error: (error, stack) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error_outline,
size: 64,
color: isDark ? AppColors.darkError : AppColors.lightError,
),
const SizedBox(height: 16),
Text(
'오류가 발생했습니다',
style: AppTypography.heading2(isDark),
),
const SizedBox(height: 8),
Text(
error.toString(),
style: AppTypography.body2(isDark),
textAlign: TextAlign.center,
),
],
),
),
),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: _showAddOptions,
backgroundColor: AppColors.lightPrimary,
child: const Icon(Icons.add, color: Colors.white),
),
);
}
Widget _buildEmptyState(bool isDark) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.restaurant_menu,
size: 80,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(height: 16),
Text(
'아직 등록된 맛집이 없어요',
style: AppTypography.heading2(isDark),
),
const SizedBox(height: 8),
Text(
'+ 버튼을 눌러 맛집을 추가해보세요',
style: AppTypography.body2(isDark),
),
],
),
);
}
void _showAddOptions() {
showDialog(
context: context,
builder: (context) => const AddRestaurantDialog(initialTabIndex: 0),
);
}
}

View File

@@ -0,0 +1,330 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/constants/app_colors.dart';
import '../../../../core/constants/app_typography.dart';
import '../../../view_models/add_restaurant_view_model.dart';
import 'add_restaurant_form.dart';
import 'add_restaurant_url_tab.dart';
/// 식당 추가 다이얼로그
///
/// UI 렌더링만 담당하며, 비즈니스 로직은 ViewModel에 위임합니다.
class AddRestaurantDialog extends ConsumerStatefulWidget {
final int initialTabIndex;
const AddRestaurantDialog({
super.key,
this.initialTabIndex = 0,
});
@override
ConsumerState<AddRestaurantDialog> createState() => _AddRestaurantDialogState();
}
class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
with SingleTickerProviderStateMixin {
// Form 관련
final _formKey = GlobalKey<FormState>();
// TextEditingController들
late final TextEditingController _nameController;
late final TextEditingController _categoryController;
late final TextEditingController _subCategoryController;
late final TextEditingController _descriptionController;
late final TextEditingController _phoneController;
late final TextEditingController _roadAddressController;
late final TextEditingController _jibunAddressController;
late final TextEditingController _latitudeController;
late final TextEditingController _longitudeController;
late final TextEditingController _naverUrlController;
// UI 상태
late TabController _tabController;
@override
void initState() {
super.initState();
// TabController 초기화
_tabController = TabController(
length: 2,
vsync: this,
initialIndex: widget.initialTabIndex,
);
// TextEditingController 초기화
_nameController = TextEditingController();
_categoryController = TextEditingController();
_subCategoryController = TextEditingController();
_descriptionController = TextEditingController();
_phoneController = TextEditingController();
_roadAddressController = TextEditingController();
_jibunAddressController = TextEditingController();
_latitudeController = TextEditingController();
_longitudeController = TextEditingController();
_naverUrlController = TextEditingController();
}
@override
void dispose() {
// TabController 정리
_tabController.dispose();
// TextEditingController 정리
_nameController.dispose();
_categoryController.dispose();
_subCategoryController.dispose();
_descriptionController.dispose();
_phoneController.dispose();
_roadAddressController.dispose();
_jibunAddressController.dispose();
_latitudeController.dispose();
_longitudeController.dispose();
_naverUrlController.dispose();
super.dispose();
}
/// 폼 데이터가 변경될 때 ViewModel 업데이트
void _onFormDataChanged(String _) {
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
final formData = RestaurantFormData.fromControllers(
nameController: _nameController,
categoryController: _categoryController,
subCategoryController: _subCategoryController,
descriptionController: _descriptionController,
phoneController: _phoneController,
roadAddressController: _roadAddressController,
jibunAddressController: _jibunAddressController,
latitudeController: _latitudeController,
longitudeController: _longitudeController,
naverUrlController: _naverUrlController,
);
viewModel.updateFormData(formData);
}
/// 네이버 URL로부터 정보 가져오기
Future<void> _fetchFromNaverUrl() async {
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
await viewModel.fetchFromNaverUrl(_naverUrlController.text);
// 성공 시 폼에 데이터 채우기 및 자동 저장
final state = ref.read(addRestaurantViewModelProvider);
if (state.fetchedRestaurantData != null) {
_updateFormControllers(state.formData);
// 자동으로 저장 실행
final success = await viewModel.saveRestaurant();
if (success && mounted) {
// 다이얼로그 닫기
Navigator.of(context).pop();
// 성공 메시지 표시
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: Colors.white, size: 20),
SizedBox(width: 8),
Text('맛집이 추가되었습니다'),
],
),
backgroundColor: Colors.green,
),
);
}
}
}
/// 폼 컨트롤러 업데이트
void _updateFormControllers(RestaurantFormData formData) {
_nameController.text = formData.name;
_categoryController.text = formData.category;
_subCategoryController.text = formData.subCategory;
_descriptionController.text = formData.description;
_phoneController.text = formData.phoneNumber;
_roadAddressController.text = formData.roadAddress;
_jibunAddressController.text = formData.jibunAddress;
_latitudeController.text = formData.latitude;
_longitudeController.text = formData.longitude;
}
/// 식당 저장
Future<void> _saveRestaurant() async {
if (_formKey.currentState?.validate() != true) {
return;
}
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
final success = await viewModel.saveRestaurant();
if (success && mounted) {
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: Colors.white, size: 20),
SizedBox(width: 8),
Text('맛집이 추가되었습니다'),
],
),
backgroundColor: Colors.green,
),
);
}
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final state = ref.watch(addRestaurantViewModelProvider);
return Dialog(
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Container(
constraints: const BoxConstraints(maxWidth: 400),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 헤더
_buildHeader(isDark),
// 탭바
_buildTabBar(isDark),
// 탭 내용
Flexible(
child: Container(
padding: const EdgeInsets.all(24),
child: TabBarView(
controller: _tabController,
children: [
// URL 탭
SingleChildScrollView(
child: AddRestaurantUrlTab(
urlController: _naverUrlController,
isLoading: state.isLoading,
errorMessage: state.errorMessage,
onFetchPressed: _fetchFromNaverUrl,
),
),
// 직접 입력 탭
SingleChildScrollView(
child: AddRestaurantForm(
formKey: _formKey,
nameController: _nameController,
categoryController: _categoryController,
subCategoryController: _subCategoryController,
descriptionController: _descriptionController,
phoneController: _phoneController,
roadAddressController: _roadAddressController,
jibunAddressController: _jibunAddressController,
latitudeController: _latitudeController,
longitudeController: _longitudeController,
onFieldChanged: _onFormDataChanged,
),
),
],
),
),
),
// 버튼
_buildButtons(isDark, state),
],
),
),
);
}
/// 헤더 빌드
Widget _buildHeader(bool isDark) {
return Container(
padding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
child: Column(
children: [
Text(
'맛집 추가',
style: AppTypography.heading1(isDark),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
],
),
);
}
/// 탭바 빌드
Widget _buildTabBar(bool isDark) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 24),
decoration: BoxDecoration(
color: isDark ? AppColors.darkBackground : AppColors.lightBackground,
borderRadius: BorderRadius.circular(8),
),
child: TabBar(
controller: _tabController,
indicatorColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
labelColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
unselectedLabelColor: isDark ? Colors.grey[400] : Colors.grey[600],
tabs: const [
Tab(
icon: Icon(Icons.link),
text: 'URL로 가져오기',
),
Tab(
icon: Icon(Icons.edit),
text: '직접 입력',
),
],
),
);
}
/// 버튼 빌드
Widget _buildButtons(bool isDark, AddRestaurantState state) {
return Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: isDark ? AppColors.darkBackground : AppColors.lightBackground,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(16),
bottomRight: Radius.circular(16),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('취소'),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: state.isLoading
? null
: () {
// 현재 탭에 따라 다른 동작
if (_tabController.index == 0) {
// URL 탭
_fetchFromNaverUrl();
} else {
// 직접 입력 탭
_saveRestaurant();
}
},
child: Text(
_tabController.index == 0 ? '가져오기' : '저장',
),
),
],
),
);
}
}

View File

@@ -0,0 +1,925 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/constants/app_typography.dart';
import 'package:lunchpick/core/utils/validators.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
class AddRestaurantDialog extends ConsumerStatefulWidget {
final int initialTabIndex;
const AddRestaurantDialog({
super.key,
this.initialTabIndex = 0,
});
@override
ConsumerState<AddRestaurantDialog> createState() => _AddRestaurantDialogState();
}
class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog> with SingleTickerProviderStateMixin {
final _formKey = GlobalKey<FormState>();
final _nameController = TextEditingController();
final _categoryController = TextEditingController();
final _subCategoryController = TextEditingController();
final _descriptionController = TextEditingController();
final _phoneController = TextEditingController();
final _roadAddressController = TextEditingController();
final _jibunAddressController = TextEditingController();
final _latitudeController = TextEditingController();
final _longitudeController = TextEditingController();
final _naverUrlController = TextEditingController();
// 기본 좌표 (서울시청)
final double _defaultLatitude = 37.5665;
final double _defaultLongitude = 126.9780;
// UI 상태 관리
late TabController _tabController;
bool _isLoading = false;
String? _errorMessage;
Restaurant? _fetchedRestaurantData;
final _linkController = TextEditingController();
@override
void initState() {
super.initState();
_tabController = TabController(
length: 2,
vsync: this,
initialIndex: widget.initialTabIndex,
);
}
@override
void dispose() {
_nameController.dispose();
_categoryController.dispose();
_subCategoryController.dispose();
_descriptionController.dispose();
_phoneController.dispose();
_roadAddressController.dispose();
_jibunAddressController.dispose();
_latitudeController.dispose();
_longitudeController.dispose();
_naverUrlController.dispose();
_linkController.dispose();
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Dialog(
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Container(
constraints: const BoxConstraints(maxWidth: 400),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 제목과 탭바
Container(
padding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
child: Column(
children: [
Text(
'맛집 추가',
style: AppTypography.heading1(isDark),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
Container(
decoration: BoxDecoration(
color: isDark ? AppColors.darkBackground : AppColors.lightBackground,
borderRadius: BorderRadius.circular(12),
),
child: TabBar(
controller: _tabController,
indicator: BoxDecoration(
color: AppColors.lightPrimary,
borderRadius: BorderRadius.circular(12),
),
indicatorSize: TabBarIndicatorSize.tab,
labelColor: Colors.white,
unselectedLabelColor: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
labelStyle: AppTypography.body1(false).copyWith(fontWeight: FontWeight.w600),
tabs: const [
Tab(text: '직접 입력'),
Tab(text: '네이버 지도에서 가져오기'),
],
),
),
],
),
),
// 탭뷰 컨텐츠
Flexible(
child: TabBarView(
controller: _tabController,
physics: const NeverScrollableScrollPhysics(),
children: [
// 직접 입력 탭
SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 가게 이름
TextFormField(
controller: _nameController,
decoration: InputDecoration(
labelText: '가게 이름 *',
hintText: '예: 서울갈비',
prefixIcon: const Icon(Icons.store),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return '가게 이름을 입력해주세요';
}
return null;
},
),
const SizedBox(height: 16),
// 카테고리
Row(
children: [
Expanded(
child: TextFormField(
controller: _categoryController,
decoration: InputDecoration(
labelText: '카테고리 *',
hintText: '예: 한식',
prefixIcon: const Icon(Icons.category),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return '카테고리를 입력해주세요';
}
return null;
},
),
),
const SizedBox(width: 8),
Expanded(
child: TextFormField(
controller: _subCategoryController,
decoration: InputDecoration(
labelText: '세부 카테고리',
hintText: '예: 갈비',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
),
],
),
const SizedBox(height: 16),
// 설명
TextFormField(
controller: _descriptionController,
maxLines: 2,
decoration: InputDecoration(
labelText: '설명',
hintText: '맛집에 대한 간단한 설명',
prefixIcon: const Icon(Icons.description),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
const SizedBox(height: 16),
// 전화번호
TextFormField(
controller: _phoneController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: '전화번호',
hintText: '예: 02-1234-5678',
prefixIcon: const Icon(Icons.phone),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
const SizedBox(height: 16),
// 도로명 주소
TextFormField(
controller: _roadAddressController,
decoration: InputDecoration(
labelText: '도로명 주소 *',
hintText: '예: 서울시 중구 세종대로 110',
prefixIcon: const Icon(Icons.location_on),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return '도로명 주소를 입력해주세요';
}
return null;
},
),
const SizedBox(height: 16),
// 지번 주소
TextFormField(
controller: _jibunAddressController,
decoration: InputDecoration(
labelText: '지번 주소',
hintText: '예: 서울시 중구 태평로1가 31',
prefixIcon: const Icon(Icons.map),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
const SizedBox(height: 16),
// 위도/경도 입력
Row(
children: [
Expanded(
child: TextFormField(
controller: _latitudeController,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: '위도',
hintText: '37.5665',
prefixIcon: const Icon(Icons.explore),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
validator: Validators.validateLatitude,
),
),
const SizedBox(width: 8),
Expanded(
child: TextFormField(
controller: _longitudeController,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: '경도',
hintText: '126.9780',
prefixIcon: const Icon(Icons.explore),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
validator: Validators.validateLongitude,
),
),
],
),
const SizedBox(height: 8),
Text(
'* 위도/경도를 입력하지 않으면 서울시청 기준으로 저장됩니다',
style: TextStyle(
fontSize: 12,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
),
const SizedBox(height: 24),
// 버튼
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'취소',
style: TextStyle(
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: _saveRestaurant,
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
),
child: const Text('저장'),
),
],
),
],
),
),
),
// 네이버 지도 탭
_buildNaverMapTab(isDark),
],
),
),
],
),
),
);
}
// 네이버 지도 탭 빌드
Widget _buildNaverMapTab(bool isDark) {
return SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 안내 메시지
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppColors.lightPrimary.withOpacity(0.3),
),
),
child: Row(
children: [
Icon(
Icons.info_outline,
color: AppColors.lightPrimary,
size: 20,
),
const SizedBox(width: 12),
Expanded(
child: Text(
kIsWeb
? '네이버 지도에서 맛집 페이지 URL을 복사하여\n붙여넣어 주세요.\n\n웹 환경에서는 프록시 서버를 통해 정보를 가져옵니다.\n네트워크 상황에 따라 시간이 걸릴 수 있습니다.'
: '네이버 지도에서 맛집 페이지 URL을 복사하여\n붙여넣어 주세요.',
style: TextStyle(
fontSize: 14,
color: isDark ? AppColors.darkText : AppColors.lightText,
height: 1.5,
),
),
),
],
),
),
const SizedBox(height: 24),
// URL 입력 필드
TextFormField(
controller: _naverUrlController,
decoration: InputDecoration(
labelText: '네이버 지도 URL',
hintText: 'https://map.naver.com/... 또는 https://naver.me/...',
prefixIcon: Icon(
Icons.link,
color: AppColors.lightPrimary,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: AppColors.lightPrimary,
width: 2,
),
),
errorText: _errorMessage,
errorMaxLines: 2,
),
enabled: !_isLoading,
),
const SizedBox(height: 24),
// 가져온 정보 표시 (JSON 스타일)
if (_fetchedRestaurantData != null) ...[
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark
? AppColors.darkBackground
: AppColors.lightBackground.withOpacity(0.5),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isDark
? AppColors.darkDivider
: AppColors.lightDivider,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 타이틀
Row(
children: [
Icon(
Icons.code,
size: 20,
color: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
),
const SizedBox(width: 8),
Text(
'가져온 정보',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
),
),
],
),
const SizedBox(height: 12),
// JSON 스타일 정보 표시
_buildJsonField(
'이름',
_nameController,
isDark,
icon: Icons.store,
),
_buildJsonField(
'카테고리',
_categoryController,
isDark,
icon: Icons.category,
),
_buildJsonField(
'세부 카테고리',
_subCategoryController,
isDark,
icon: Icons.label_outline,
),
_buildJsonField(
'주소',
_roadAddressController,
isDark,
icon: Icons.location_on,
),
_buildJsonField(
'전화',
_phoneController,
isDark,
icon: Icons.phone,
),
_buildJsonField(
'설명',
_descriptionController,
isDark,
icon: Icons.description,
maxLines: 2,
),
_buildJsonField(
'좌표',
TextEditingController(
text: '${_latitudeController.text}, ${_longitudeController.text}'
),
isDark,
icon: Icons.my_location,
isCoordinate: true,
),
if (_linkController.text.isNotEmpty)
_buildJsonField(
'링크',
_linkController,
isDark,
icon: Icons.link,
isLink: true,
),
],
),
),
const SizedBox(height: 24),
],
// 버튼
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: _isLoading ? null : () => Navigator.pop(context),
child: Text(
'취소',
style: TextStyle(
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
),
),
const SizedBox(width: 8),
if (_fetchedRestaurantData == null)
ElevatedButton(
onPressed: _isLoading ? null : _fetchFromNaverUrl,
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
child: _isLoading
? SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.download, size: 18),
SizedBox(width: 8),
Text('가져오기'),
],
),
)
else ...[
OutlinedButton(
onPressed: () {
setState(() {
_fetchedRestaurantData = null;
_clearControllers();
});
},
style: OutlinedButton.styleFrom(
foregroundColor: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
side: BorderSide(
color: isDark
? AppColors.darkDivider
: AppColors.lightDivider,
),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
child: const Text('초기화'),
),
const SizedBox(width: 8),
ElevatedButton(
onPressed: _saveRestaurant,
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(Icons.save, size: 18),
SizedBox(width: 8),
Text('저장'),
],
),
),
],
],
),
],
),
);
}
// JSON 스타일 필드 빌드
Widget _buildJsonField(
String label,
TextEditingController controller,
bool isDark, {
IconData? icon,
int maxLines = 1,
bool isCoordinate = false,
bool isLink = false,
}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
if (icon != null) ...[
Icon(
icon,
size: 16,
color: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
),
const SizedBox(width: 8),
],
Text(
'$label:',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
),
),
],
),
const SizedBox(height: 4),
if (isCoordinate)
Row(
children: [
Expanded(
child: TextFormField(
controller: _latitudeController,
style: TextStyle(
fontSize: 14,
fontFamily: 'monospace',
color: isDark ? AppColors.darkText : AppColors.lightText,
),
decoration: InputDecoration(
hintText: '위도',
isDense: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
filled: true,
fillColor: isDark
? AppColors.darkSurface
: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: isDark
? AppColors.darkDivider
: AppColors.lightDivider,
),
),
),
),
),
const SizedBox(width: 8),
Text(
',',
style: TextStyle(
fontSize: 14,
fontFamily: 'monospace',
color: isDark ? AppColors.darkText : AppColors.lightText,
),
),
const SizedBox(width: 8),
Expanded(
child: TextFormField(
controller: _longitudeController,
style: TextStyle(
fontSize: 14,
fontFamily: 'monospace',
color: isDark ? AppColors.darkText : AppColors.lightText,
),
decoration: InputDecoration(
hintText: '경도',
isDense: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
filled: true,
fillColor: isDark
? AppColors.darkSurface
: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: isDark
? AppColors.darkDivider
: AppColors.lightDivider,
),
),
),
),
),
],
)
else
TextFormField(
controller: controller,
maxLines: maxLines,
style: TextStyle(
fontSize: 14,
fontFamily: isLink ? 'monospace' : null,
color: isLink
? AppColors.lightPrimary
: isDark ? AppColors.darkText : AppColors.lightText,
decoration: isLink ? TextDecoration.underline : null,
),
decoration: InputDecoration(
isDense: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
filled: true,
fillColor: isDark
? AppColors.darkSurface
: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: isDark
? AppColors.darkDivider
: AppColors.lightDivider,
),
),
),
),
],
),
);
}
// 컨트롤러 초기화
void _clearControllers() {
_nameController.clear();
_categoryController.clear();
_subCategoryController.clear();
_descriptionController.clear();
_phoneController.clear();
_roadAddressController.clear();
_jibunAddressController.clear();
_latitudeController.clear();
_longitudeController.clear();
_linkController.clear();
}
// 네이버 URL에서 정보 가져오기
Future<void> _fetchFromNaverUrl() async {
final url = _naverUrlController.text.trim();
if (url.isEmpty) {
setState(() {
_errorMessage = 'URL을 입력해주세요.';
});
return;
}
setState(() {
_isLoading = true;
_errorMessage = null;
});
try {
final notifier = ref.read(restaurantNotifierProvider.notifier);
final restaurant = await notifier.addRestaurantFromUrl(url);
// 성공 시 폼에 정보 채우고 _fetchedRestaurantData 설정
setState(() {
_nameController.text = restaurant.name;
_categoryController.text = restaurant.category;
_subCategoryController.text = restaurant.subCategory;
_descriptionController.text = restaurant.description ?? '';
_phoneController.text = restaurant.phoneNumber ?? '';
_roadAddressController.text = restaurant.roadAddress;
_jibunAddressController.text = restaurant.jibunAddress;
_latitudeController.text = restaurant.latitude.toString();
_longitudeController.text = restaurant.longitude.toString();
// 링크 정보가 있다면 설정
_linkController.text = restaurant.naverUrl ?? '';
// Restaurant 객체 저장
_fetchedRestaurantData = restaurant;
_isLoading = false;
});
// 성공 메시지 표시
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: Colors.white, size: 20),
const SizedBox(width: 8),
Text('맛집 정보를 가져왔습니다. 확인 후 저장해주세요.'),
],
),
backgroundColor: AppColors.lightPrimary,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
);
}
} catch (e) {
setState(() {
_isLoading = false;
_errorMessage = e.toString().replaceFirst('Exception: ', '');
});
}
}
Future<void> _saveRestaurant() async {
if (_formKey.currentState?.validate() != true) {
return;
}
final notifier = ref.read(restaurantNotifierProvider.notifier);
try {
// _fetchedRestaurantData가 있으면 해당 데이터 사용 (네이버에서 가져온 경우)
final fetchedData = _fetchedRestaurantData;
if (fetchedData != null) {
// 사용자가 수정한 필드만 업데이트
final updatedRestaurant = fetchedData.copyWith(
name: _nameController.text.trim(),
category: _categoryController.text.trim(),
subCategory: _subCategoryController.text.trim().isEmpty
? _categoryController.text.trim()
: _subCategoryController.text.trim(),
description: _descriptionController.text.trim().isEmpty
? null
: _descriptionController.text.trim(),
phoneNumber: _phoneController.text.trim().isEmpty
? null
: _phoneController.text.trim(),
roadAddress: _roadAddressController.text.trim(),
jibunAddress: _jibunAddressController.text.trim().isEmpty
? _roadAddressController.text.trim()
: _jibunAddressController.text.trim(),
latitude: double.tryParse(_latitudeController.text.trim()) ?? fetchedData.latitude,
longitude: double.tryParse(_longitudeController.text.trim()) ?? fetchedData.longitude,
updatedAt: DateTime.now(),
);
// 이미 완성된 Restaurant 객체를 직접 추가
await notifier.addRestaurantDirect(updatedRestaurant);
} else {
// 직접 입력한 경우 (기존 로직)
await notifier.addRestaurant(
name: _nameController.text.trim(),
category: _categoryController.text.trim(),
subCategory: _subCategoryController.text.trim().isEmpty
? _categoryController.text.trim()
: _subCategoryController.text.trim(),
description: _descriptionController.text.trim().isEmpty
? null
: _descriptionController.text.trim(),
phoneNumber: _phoneController.text.trim().isEmpty
? null
: _phoneController.text.trim(),
roadAddress: _roadAddressController.text.trim(),
jibunAddress: _jibunAddressController.text.trim().isEmpty
? _roadAddressController.text.trim()
: _jibunAddressController.text.trim(),
latitude: _latitudeController.text.trim().isEmpty
? _defaultLatitude
: double.tryParse(_latitudeController.text.trim()) ?? _defaultLatitude,
longitude: _longitudeController.text.trim().isEmpty
? _defaultLongitude
: double.tryParse(_longitudeController.text.trim()) ?? _defaultLongitude,
source: DataSource.USER_INPUT,
);
}
if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('맛집이 추가되었습니다'),
backgroundColor: AppColors.lightPrimary,
),
);
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('오류가 발생했습니다: ${e.toString()}'),
backgroundColor: AppColors.lightError,
),
);
}
}
}
}

View File

@@ -0,0 +1,227 @@
import 'package:flutter/material.dart';
import '../../../services/restaurant_form_validator.dart';
/// 식당 추가 폼 위젯
class AddRestaurantForm extends StatelessWidget {
final GlobalKey<FormState> formKey;
final TextEditingController nameController;
final TextEditingController categoryController;
final TextEditingController subCategoryController;
final TextEditingController descriptionController;
final TextEditingController phoneController;
final TextEditingController roadAddressController;
final TextEditingController jibunAddressController;
final TextEditingController latitudeController;
final TextEditingController longitudeController;
final Function(String) onFieldChanged;
const AddRestaurantForm({
super.key,
required this.formKey,
required this.nameController,
required this.categoryController,
required this.subCategoryController,
required this.descriptionController,
required this.phoneController,
required this.roadAddressController,
required this.jibunAddressController,
required this.latitudeController,
required this.longitudeController,
required this.onFieldChanged,
});
@override
Widget build(BuildContext context) {
return Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 가게 이름
TextFormField(
controller: nameController,
decoration: InputDecoration(
labelText: '가게 이름 *',
hintText: '예: 맛있는 한식당',
prefixIcon: const Icon(Icons.store),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
validator: (value) {
if (value == null || value.isEmpty) {
return '가게 이름을 입력해주세요';
}
return null;
},
),
const SizedBox(height: 16),
// 카테고리
Row(
children: [
Expanded(
child: TextFormField(
controller: categoryController,
decoration: InputDecoration(
labelText: '카테고리 *',
hintText: '예: 한식',
prefixIcon: const Icon(Icons.category),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
validator: (value) => RestaurantFormValidator.validateCategory(value),
),
),
const SizedBox(width: 8),
Expanded(
child: TextFormField(
controller: subCategoryController,
decoration: InputDecoration(
labelText: '세부 카테고리',
hintText: '예: 갈비',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
),
),
],
),
const SizedBox(height: 16),
// 설명
TextFormField(
controller: descriptionController,
maxLines: 2,
decoration: InputDecoration(
labelText: '설명',
hintText: '맛집에 대한 간단한 설명',
prefixIcon: const Icon(Icons.description),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
),
const SizedBox(height: 16),
// 전화번호
TextFormField(
controller: phoneController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: '전화번호',
hintText: '예: 02-1234-5678',
prefixIcon: const Icon(Icons.phone),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
validator: (value) => RestaurantFormValidator.validatePhoneNumber(value),
),
const SizedBox(height: 16),
// 도로명 주소
TextFormField(
controller: roadAddressController,
decoration: InputDecoration(
labelText: '도로명 주소 *',
hintText: '예: 서울시 중구 세종대로 110',
prefixIcon: const Icon(Icons.location_on),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
validator: (value) => RestaurantFormValidator.validateAddress(value),
),
const SizedBox(height: 16),
// 지번 주소
TextFormField(
controller: jibunAddressController,
decoration: InputDecoration(
labelText: '지번 주소',
hintText: '예: 서울시 중구 태평로1가 31',
prefixIcon: const Icon(Icons.map),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
),
const SizedBox(height: 16),
// 위도/경도 입력
Row(
children: [
Expanded(
child: TextFormField(
controller: latitudeController,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: '위도',
hintText: '37.5665',
prefixIcon: const Icon(Icons.explore),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
validator: (value) {
if (value != null && value.isNotEmpty) {
final latitude = double.tryParse(value);
if (latitude == null || latitude < -90 || latitude > 90) {
return '올바른 위도값을 입력해주세요';
}
}
return null;
},
),
),
const SizedBox(width: 8),
Expanded(
child: TextFormField(
controller: longitudeController,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: '경도',
hintText: '126.9780',
prefixIcon: const Icon(Icons.explore),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
onChanged: onFieldChanged,
validator: (value) {
if (value != null && value.isNotEmpty) {
final longitude = double.tryParse(value);
if (longitude == null || longitude < -180 || longitude > 180) {
return '올바른 경도값을 입력해주세요';
}
}
return null;
},
),
),
],
),
const SizedBox(height: 8),
Text(
'* 위도/경도를 입력하지 않으면 서울시청 기준으로 저장됩니다',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey,
),
textAlign: TextAlign.center,
),
],
),
);
}
}

View File

@@ -0,0 +1,138 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import '../../../../core/constants/app_colors.dart';
import '../../../../core/constants/app_typography.dart';
/// 네이버 URL 입력 탭 위젯
class AddRestaurantUrlTab extends StatelessWidget {
final TextEditingController urlController;
final bool isLoading;
final String? errorMessage;
final VoidCallback onFetchPressed;
const AddRestaurantUrlTab({
super.key,
required this.urlController,
required this.isLoading,
this.errorMessage,
required this.onFetchPressed,
});
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 안내 텍스트
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: isDark
? AppColors.darkPrimary.withOpacity(0.1)
: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.info_outline,
size: 20,
color: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
),
const SizedBox(width: 8),
Text(
'네이버 지도에서 맛집 정보 가져오기',
style: AppTypography.body1(isDark).copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 8),
Text(
'1. 네이버 지도에서 맛집을 검색합니다\n'
'2. 공유 버튼을 눌러 URL을 복사합니다\n'
'3. 아래에 붙여넣고 가져오기를 누릅니다',
style: AppTypography.body2(isDark),
),
],
),
),
const SizedBox(height: 16),
// URL 입력 필드
TextField(
controller: urlController,
decoration: InputDecoration(
labelText: '네이버 지도 URL',
hintText: kIsWeb
? 'https://map.naver.com/...'
: 'https://naver.me/...',
prefixIcon: const Icon(Icons.link),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
errorText: errorMessage,
),
onSubmitted: (_) => onFetchPressed(),
),
const SizedBox(height: 16),
// 가져오기 버튼
ElevatedButton.icon(
onPressed: isLoading ? null : onFetchPressed,
icon: isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: const Icon(Icons.download),
label: Text(isLoading ? '가져오는 중...' : '맛집 정보 가져오기'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
),
),
const SizedBox(height: 16),
// 웹 환경 경고
if (kIsWeb) ...[
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.orange.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.orange.withOpacity(0.3)),
),
child: Row(
children: [
const Icon(Icons.warning_amber_rounded,
color: Colors.orange, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
'웹 환경에서는 CORS 정책으로 인해 일부 맛집 정보가 제한될 수 있습니다.',
style: AppTypography.caption(isDark).copyWith(
color: Colors.orange[700],
),
),
),
],
),
),
],
],
);
}
}

View File

@@ -0,0 +1,304 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/constants/app_typography.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';
class RestaurantCard extends ConsumerWidget {
final Restaurant restaurant;
const RestaurantCard({
super.key,
required this.restaurant,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final lastVisitAsync = ref.watch(lastVisitDateProvider(restaurant.id));
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: InkWell(
onTap: () => _showRestaurantDetail(context, isDark),
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
// 카테고리 아이콘
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
_getCategoryIcon(restaurant.category),
color: AppColors.lightPrimary,
size: 24,
),
),
const SizedBox(width: 12),
// 가게 정보
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
restaurant.name,
style: AppTypography.heading2(isDark),
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Row(
children: [
Text(
restaurant.category,
style: AppTypography.body2(isDark),
),
if (restaurant.subCategory != restaurant.category) ...[
Text(
'',
style: AppTypography.body2(isDark),
),
Text(
restaurant.subCategory,
style: AppTypography.body2(isDark),
),
],
],
),
],
),
),
// 더보기 버튼
IconButton(
icon: Icon(
Icons.more_vert,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
onPressed: () => _showOptions(context, ref, isDark),
),
],
),
if (restaurant.description != null) ...[
const SizedBox(height: 12),
Text(
restaurant.description!,
style: AppTypography.body2(isDark),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
const SizedBox(height: 12),
// 주소
Row(
children: [
Icon(
Icons.location_on,
size: 16,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 4),
Expanded(
child: Text(
restaurant.roadAddress,
style: AppTypography.caption(isDark),
overflow: TextOverflow.ellipsis,
),
),
],
),
// 마지막 방문일
lastVisitAsync.when(
data: (lastVisit) {
if (lastVisit != null) {
final daysSinceVisit = DateTime.now().difference(lastVisit).inDays;
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Row(
children: [
Icon(
Icons.schedule,
size: 16,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
const SizedBox(width: 4),
Text(
daysSinceVisit == 0
? '오늘 방문'
: '$daysSinceVisit일 전 방문',
style: AppTypography.caption(isDark),
),
],
),
);
}
return const SizedBox.shrink();
},
loading: () => const SizedBox.shrink(),
error: (_, __) => const SizedBox.shrink(),
),
],
),
),
),
);
}
IconData _getCategoryIcon(String category) {
switch (category) {
case '한식':
return Icons.rice_bowl;
case '중식':
return Icons.ramen_dining;
case '일식':
return Icons.set_meal;
case '양식':
return Icons.restaurant;
case '카페':
return Icons.coffee;
case '분식':
return Icons.fastfood;
case '치킨':
return Icons.egg;
case '피자':
return Icons.local_pizza;
default:
return Icons.restaurant_menu;
}
}
void _showRestaurantDetail(BuildContext context, bool isDark) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
title: Text(restaurant.name),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildDetailRow('카테고리', '${restaurant.category} > ${restaurant.subCategory}', isDark),
if (restaurant.description != null)
_buildDetailRow('설명', restaurant.description!, isDark),
if (restaurant.phoneNumber != null)
_buildDetailRow('전화번호', restaurant.phoneNumber!, isDark),
_buildDetailRow('도로명 주소', restaurant.roadAddress, isDark),
_buildDetailRow('지번 주소', restaurant.jibunAddress, isDark),
if (restaurant.lastVisitDate != null)
_buildDetailRow(
'마지막 방문',
'${restaurant.lastVisitDate!.year}${restaurant.lastVisitDate!.month}${restaurant.lastVisitDate!.day}',
isDark,
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('닫기'),
),
],
),
);
}
Widget _buildDetailRow(String label, String value, bool isDark) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: AppTypography.caption(isDark),
),
const SizedBox(height: 2),
Text(
value,
style: AppTypography.body2(isDark),
),
],
),
);
}
void _showOptions(BuildContext context, WidgetRef ref, bool isDark) {
showModalBottomSheet(
context: context,
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (context) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 40,
height: 4,
margin: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
borderRadius: BorderRadius.circular(2),
),
),
ListTile(
leading: const Icon(Icons.edit, color: AppColors.lightPrimary),
title: const Text('수정'),
onTap: () {
Navigator.pop(context);
// TODO: 수정 기능 구현
},
),
ListTile(
leading: const Icon(Icons.delete, color: AppColors.lightError),
title: const Text('삭제'),
onTap: () async {
Navigator.pop(context);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('맛집 삭제'),
content: Text('${restaurant.name}을(를) 삭제하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('취소'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('삭제', style: TextStyle(color: AppColors.lightError)),
),
],
),
);
if (confirmed == true) {
await ref.read(restaurantNotifierProvider.notifier).deleteRestaurant(restaurant.id);
}
},
),
const SizedBox(height: 8),
],
),
);
},
);
}
}

View File

@@ -0,0 +1,442 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../../core/constants/app_colors.dart';
import '../../../core/constants/app_typography.dart';
import '../../providers/settings_provider.dart';
class SettingsScreen extends ConsumerStatefulWidget {
const SettingsScreen({super.key});
@override
ConsumerState<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends ConsumerState<SettingsScreen> {
int _daysToExclude = 7;
int _notificationMinutes = 90;
bool _notificationEnabled = true;
@override
void initState() {
super.initState();
_loadSettings();
}
Future<void> _loadSettings() async {
final daysToExclude = await ref.read(daysToExcludeProvider.future);
final notificationMinutes = await ref.read(notificationDelayMinutesProvider.future);
final notificationEnabled = await ref.read(notificationEnabledProvider.future);
if (mounted) {
setState(() {
_daysToExclude = daysToExclude;
_notificationMinutes = notificationMinutes;
_notificationEnabled = notificationEnabled;
});
}
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
appBar: AppBar(
title: const Text('설정'),
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
foregroundColor: Colors.white,
elevation: 0,
),
body: ListView(
children: [
// 추천 설정
_buildSection(
'추천 설정',
[
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
title: const Text('중복 방문 제외 기간'),
subtitle: Text('$_daysToExclude일 이내 방문한 곳은 추천에서 제외'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.remove_circle_outline),
onPressed: _daysToExclude > 1
? () async {
setState(() => _daysToExclude--);
await ref.read(settingsNotifierProvider.notifier)
.setDaysToExclude(_daysToExclude);
}
: null,
color: AppColors.lightPrimary,
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
'$_daysToExclude일',
style: const TextStyle(
fontWeight: FontWeight.bold,
color: AppColors.lightPrimary,
),
),
),
IconButton(
icon: const Icon(Icons.add_circle_outline),
onPressed: () async {
setState(() => _daysToExclude++);
await ref.read(settingsNotifierProvider.notifier)
.setDaysToExclude(_daysToExclude);
},
color: AppColors.lightPrimary,
),
],
),
),
),
],
isDark,
),
// 권한 설정
_buildSection(
'권한 관리',
[
FutureBuilder<PermissionStatus>(
future: Permission.location.status,
builder: (context, snapshot) {
final status = snapshot.data;
final isGranted = status?.isGranted ?? false;
return _buildPermissionTile(
icon: Icons.location_on,
title: '위치 권한',
subtitle: '주변 맛집 거리 계산에 필요',
isGranted: isGranted,
onRequest: _requestLocationPermission,
isDark: isDark,
);
},
),
if (!kIsWeb)
FutureBuilder<PermissionStatus>(
future: Permission.bluetooth.status,
builder: (context, snapshot) {
final status = snapshot.data;
final isGranted = status?.isGranted ?? false;
return _buildPermissionTile(
icon: Icons.bluetooth,
title: '블루투스 권한',
subtitle: '맛집 리스트 공유에 필요',
isGranted: isGranted,
onRequest: _requestBluetoothPermission,
isDark: isDark,
);
},
),
FutureBuilder<PermissionStatus>(
future: Permission.notification.status,
builder: (context, snapshot) {
final status = snapshot.data;
final isGranted = status?.isGranted ?? false;
return _buildPermissionTile(
icon: Icons.notifications,
title: '알림 권한',
subtitle: '방문 확인 알림에 필요',
isGranted: isGranted,
onRequest: _requestNotificationPermission,
isDark: isDark,
);
},
),
],
isDark,
),
// 알림 설정
_buildSection(
'알림 설정',
[
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: SwitchListTile(
title: const Text('방문 확인 알림'),
subtitle: const Text('맛집 방문 후 확인 알림을 받습니다'),
value: _notificationEnabled,
onChanged: (value) async {
setState(() => _notificationEnabled = value);
await ref.read(settingsNotifierProvider.notifier)
.setNotificationEnabled(value);
},
activeColor: AppColors.lightPrimary,
),
),
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
enabled: _notificationEnabled,
title: const Text('방문 확인 알림 시간'),
subtitle: Text('추천 후 $_notificationMinutes분 뒤 알림'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: const Icon(Icons.remove_circle_outline),
onPressed: _notificationEnabled && _notificationMinutes > 60
? () async {
setState(() => _notificationMinutes -= 30);
await ref.read(settingsNotifierProvider.notifier)
.setNotificationDelayMinutes(_notificationMinutes);
}
: null,
color: AppColors.lightPrimary,
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
'${_notificationMinutes ~/ 60}시간 ${_notificationMinutes % 60}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: _notificationEnabled ? AppColors.lightPrimary : Colors.grey,
),
),
),
IconButton(
icon: const Icon(Icons.add_circle_outline),
onPressed: _notificationEnabled && _notificationMinutes < 360
? () async {
setState(() => _notificationMinutes += 30);
await ref.read(settingsNotifierProvider.notifier)
.setNotificationDelayMinutes(_notificationMinutes);
}
: null,
color: AppColors.lightPrimary,
),
],
),
),
),
],
isDark,
),
// 테마 설정
_buildSection(
'테마',
[
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
leading: Icon(
isDark ? Icons.dark_mode : Icons.light_mode,
color: AppColors.lightPrimary,
),
title: const Text('테마 설정'),
subtitle: Text(isDark ? '다크 모드' : '라이트 모드'),
trailing: Switch(
value: isDark,
onChanged: (value) {
if (value) {
AdaptiveTheme.of(context).setDark();
} else {
AdaptiveTheme.of(context).setLight();
}
},
activeColor: AppColors.lightPrimary,
),
),
),
],
isDark,
),
// 앱 정보
_buildSection(
'앱 정보',
[
Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Column(
children: [
const ListTile(
leading: Icon(Icons.info_outline, color: AppColors.lightPrimary),
title: Text('버전'),
subtitle: Text('1.0.0'),
),
const Divider(height: 1),
const ListTile(
leading: Icon(Icons.person_outline, color: AppColors.lightPrimary),
title: Text('개발자'),
subtitle: Text('NatureBridgeAI'),
),
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.description_outlined, color: AppColors.lightPrimary),
title: const Text('오픈소스 라이센스'),
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
onTap: () => showLicensePage(
context: context,
applicationName: '오늘 뭐 먹Z?',
applicationVersion: '1.0.0',
applicationLegalese: '© 2025 NatureBridgeAI',
),
),
],
),
),
],
isDark,
),
const SizedBox(height: 24),
],
),
);
}
Widget _buildSection(String title, List<Widget> children, bool isDark) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 8),
child: Text(
title,
style: AppTypography.body2(isDark).copyWith(
color: AppColors.lightPrimary,
fontWeight: FontWeight.w600,
),
),
),
...children,
],
);
}
Widget _buildPermissionTile({
required IconData icon,
required String title,
required String subtitle,
required bool isGranted,
required VoidCallback onRequest,
required bool isDark,
}) {
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
leading: Icon(icon, color: isGranted ? Colors.green : Colors.grey),
title: Text(title),
subtitle: Text(subtitle),
trailing: isGranted
? const Icon(Icons.check_circle, color: Colors.green)
: ElevatedButton(
onPressed: onRequest,
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: const Text('허용'),
),
enabled: !isGranted,
),
);
}
Future<void> _requestLocationPermission() async {
final status = await Permission.location.request();
if (status.isGranted) {
setState(() {});
} else if (status.isPermanentlyDenied) {
_showPermissionDialog('위치');
}
}
Future<void> _requestBluetoothPermission() async {
final status = await Permission.bluetooth.request();
if (status.isGranted) {
setState(() {});
} else if (status.isPermanentlyDenied) {
_showPermissionDialog('블루투스');
}
}
Future<void> _requestNotificationPermission() async {
final status = await Permission.notification.request();
if (status.isGranted) {
setState(() {});
} else if (status.isPermanentlyDenied) {
_showPermissionDialog('알림');
}
}
void _showPermissionDialog(String permissionName) {
final isDark = Theme.of(context).brightness == Brightness.dark;
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
title: const Text('권한 설정 필요'),
content: Text('$permissionName 권한이 거부되었습니다. 설정에서 직접 권한을 허용해주세요.'),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('취소'),
),
TextButton(
onPressed: () {
Navigator.pop(context);
openAppSettings();
},
style: TextButton.styleFrom(
foregroundColor: AppColors.lightPrimary,
),
child: const Text('설정으로 이동'),
),
],
),
);
}
}

View File

@@ -0,0 +1,219 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/constants/app_colors.dart';
import '../../../core/constants/app_typography.dart';
class ShareScreen extends ConsumerStatefulWidget {
const ShareScreen({super.key});
@override
ConsumerState<ShareScreen> createState() => _ShareScreenState();
}
class _ShareScreenState extends ConsumerState<ShareScreen> {
String? _shareCode;
bool _isScanning = false;
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
appBar: AppBar(
title: const Text('리스트 공유'),
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
foregroundColor: Colors.white,
elevation: 0,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
children: [
// 공유받기 섹션
Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
children: [
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: const Icon(
Icons.download_rounded,
size: 48,
color: AppColors.lightPrimary,
),
),
const SizedBox(height: 16),
Text(
'리스트 공유받기',
style: AppTypography.heading2(isDark),
),
const SizedBox(height: 8),
Text(
'다른 사람의 맛집 리스트를 받아보세요',
style: AppTypography.body2(isDark),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
if (_shareCode != null) ...[
Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
decoration: BoxDecoration(
color: AppColors.lightPrimary.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppColors.lightPrimary.withOpacity(0.3),
width: 2,
),
),
child: Text(
_shareCode!,
style: const TextStyle(
fontSize: 36,
fontWeight: FontWeight.bold,
letterSpacing: 6,
color: AppColors.lightPrimary,
),
),
),
const SizedBox(height: 12),
Text(
'이 코드를 상대방에게 알려주세요',
style: AppTypography.caption(isDark),
),
const SizedBox(height: 16),
TextButton.icon(
onPressed: () {
setState(() {
_shareCode = null;
});
},
icon: const Icon(Icons.close),
label: const Text('취소'),
style: TextButton.styleFrom(
foregroundColor: AppColors.lightError,
),
),
] else
ElevatedButton.icon(
onPressed: _generateShareCode,
icon: const Icon(Icons.qr_code),
label: const Text('공유 코드 생성'),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightPrimary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
),
),
const SizedBox(height: 16),
// 공유하기 섹션
Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
children: [
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.lightSecondary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: const Icon(
Icons.upload_rounded,
size: 48,
color: AppColors.lightSecondary,
),
),
const SizedBox(height: 16),
Text(
'내 리스트 공유하기',
style: AppTypography.heading2(isDark),
),
const SizedBox(height: 8),
Text(
'내 맛집 리스트를 다른 사람과 공유하세요',
style: AppTypography.body2(isDark),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
if (_isScanning) ...[
const CircularProgressIndicator(
color: AppColors.lightSecondary,
),
const SizedBox(height: 16),
Text(
'주변 기기를 검색 중...',
style: AppTypography.caption(isDark),
),
const SizedBox(height: 16),
TextButton.icon(
onPressed: () {
setState(() {
_isScanning = false;
});
},
icon: const Icon(Icons.stop),
label: const Text('스캔 중지'),
style: TextButton.styleFrom(
foregroundColor: AppColors.lightError,
),
),
] else
ElevatedButton.icon(
onPressed: () {
setState(() {
_isScanning = true;
});
},
icon: const Icon(Icons.radar),
label: const Text('주변 기기 스캔'),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.lightSecondary,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
],
),
),
),
],
),
),
);
}
void _generateShareCode() {
// TODO: 실제 구현 시 랜덤 코드 생성
setState(() {
_shareCode = '123456';
});
}
}

View File

@@ -0,0 +1,189 @@
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../core/constants/app_colors.dart';
import '../../../core/constants/app_typography.dart';
import '../../../core/constants/app_constants.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMixin {
late List<AnimationController> _foodControllers;
late AnimationController _questionMarkController;
late AnimationController _centerIconController;
final List<IconData> foodIcons = [
Icons.rice_bowl,
Icons.ramen_dining,
Icons.lunch_dining,
Icons.fastfood,
Icons.local_pizza,
Icons.cake,
Icons.coffee,
Icons.icecream,
Icons.bakery_dining,
];
@override
void initState() {
super.initState();
_initializeAnimations();
_navigateToHome();
}
void _initializeAnimations() {
// 음식 아이콘 애니메이션 (여러 개)
_foodControllers = List.generate(
foodIcons.length,
(index) => AnimationController(
duration: Duration(seconds: 2 + index % 3),
vsync: this,
)..repeat(reverse: true),
);
// 물음표 애니메이션
_questionMarkController = AnimationController(
duration: const Duration(milliseconds: 500),
vsync: this,
)..repeat();
// 중앙 아이콘 애니메이션
_centerIconController = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
)..repeat(reverse: true);
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
body: Stack(
children: [
// 랜덤 위치 음식 아이콘들
..._buildFoodIcons(),
// 중앙 컨텐츠
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// 선택 아이콘
ScaleTransition(
scale: Tween(begin: 0.8, end: 1.2).animate(
CurvedAnimation(
parent: _centerIconController,
curve: Curves.easeInOut,
),
),
child: Icon(
Icons.restaurant_menu,
size: 80,
color: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
),
),
const SizedBox(height: 20),
// 앱 타이틀
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'오늘 뭐 먹Z',
style: AppTypography.heading1(isDark),
),
AnimatedBuilder(
animation: _questionMarkController,
builder: (context, child) {
final questionMarks = '?' * (((_questionMarkController.value * 3).floor() % 3) + 1);
return Text(
questionMarks,
style: AppTypography.heading1(isDark),
);
},
),
],
),
],
),
),
// 하단 카피라이트
Positioned(
bottom: 30,
left: 0,
right: 0,
child: Text(
AppConstants.appCopyright,
style: AppTypography.caption(isDark).copyWith(
color: (isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary)
.withOpacity(0.5),
),
textAlign: TextAlign.center,
),
),
],
),
);
}
List<Widget> _buildFoodIcons() {
final random = math.Random();
return List.generate(foodIcons.length, (index) {
final left = random.nextDouble() * 0.8 + 0.1;
final top = random.nextDouble() * 0.7 + 0.1;
return Positioned(
left: MediaQuery.of(context).size.width * left,
top: MediaQuery.of(context).size.height * top,
child: FadeTransition(
opacity: Tween(begin: 0.2, end: 0.8).animate(
CurvedAnimation(
parent: _foodControllers[index],
curve: Curves.easeInOut,
),
),
child: ScaleTransition(
scale: Tween(begin: 0.5, end: 1.5).animate(
CurvedAnimation(
parent: _foodControllers[index],
curve: Curves.easeInOut,
),
),
child: Icon(
foodIcons[index],
size: 40,
color: AppColors.lightPrimary.withOpacity(0.3),
),
),
),
);
});
}
void _navigateToHome() {
Future.delayed(AppConstants.splashAnimationDuration, () {
if (mounted) {
context.go('/home');
}
});
}
@override
void dispose() {
for (final controller in _foodControllers) {
controller.dispose();
}
_questionMarkController.dispose();
_centerIconController.dispose();
super.dispose();
}
}

View File

@@ -0,0 +1,36 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/data/repositories/restaurant_repository_impl.dart';
import 'package:lunchpick/data/repositories/visit_repository_impl.dart';
import 'package:lunchpick/data/repositories/settings_repository_impl.dart';
import 'package:lunchpick/data/repositories/weather_repository_impl.dart';
import 'package:lunchpick/data/repositories/recommendation_repository_impl.dart';
import 'package:lunchpick/domain/repositories/restaurant_repository.dart';
import 'package:lunchpick/domain/repositories/visit_repository.dart';
import 'package:lunchpick/domain/repositories/settings_repository.dart';
import 'package:lunchpick/domain/repositories/weather_repository.dart';
import 'package:lunchpick/domain/repositories/recommendation_repository.dart';
/// RestaurantRepository Provider
final restaurantRepositoryProvider = Provider<RestaurantRepository>((ref) {
return RestaurantRepositoryImpl();
});
/// VisitRepository Provider
final visitRepositoryProvider = Provider<VisitRepository>((ref) {
return VisitRepositoryImpl();
});
/// SettingsRepository Provider
final settingsRepositoryProvider = Provider<SettingsRepository>((ref) {
return SettingsRepositoryImpl();
});
/// WeatherRepository Provider
final weatherRepositoryProvider = Provider<WeatherRepository>((ref) {
return WeatherRepositoryImpl();
});
/// RecommendationRepository Provider
final recommendationRepositoryProvider = Provider<RecommendationRepository>((ref) {
return RecommendationRepositoryImpl();
});

View File

@@ -0,0 +1,133 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:geolocator/geolocator.dart';
import 'package:permission_handler/permission_handler.dart';
/// 위치 권한 상태 Provider
final locationPermissionProvider = FutureProvider<PermissionStatus>((ref) async {
return await Permission.location.status;
});
/// 현재 위치 Provider
final currentLocationProvider = FutureProvider<Position?>((ref) async {
// 위치 권한 확인
final permissionStatus = await Permission.location.status;
if (!permissionStatus.isGranted) {
// 권한이 없으면 요청
final result = await Permission.location.request();
if (!result.isGranted) {
return null;
}
}
// 위치 서비스 활성화 확인
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
throw Exception('위치 서비스가 비활성화되어 있습니다');
}
// 현재 위치 가져오기
try {
return await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high,
timeLimit: const Duration(seconds: 10),
);
} catch (e) {
// 타임아웃이나 오류 발생 시 마지막 알려진 위치 반환
return await Geolocator.getLastKnownPosition();
}
});
/// 위치 스트림 Provider
final locationStreamProvider = StreamProvider<Position>((ref) {
return Geolocator.getPositionStream(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 10, // 10미터 이상 이동 시 업데이트
),
);
});
/// 위치 관리 StateNotifier
class LocationNotifier extends StateNotifier<AsyncValue<Position?>> {
LocationNotifier() : super(const AsyncValue.loading());
/// 위치 권한 요청
Future<bool> requestLocationPermission() async {
try {
final status = await Permission.location.request();
return status.isGranted;
} catch (e) {
return false;
}
}
/// 위치 서비스 활성화 요청
Future<bool> requestLocationService() async {
try {
return await Geolocator.openLocationSettings();
} catch (e) {
return false;
}
}
/// 현재 위치 가져오기
Future<void> getCurrentLocation() async {
state = const AsyncValue.loading();
try {
// 권한 확인
final permissionStatus = await Permission.location.status;
if (!permissionStatus.isGranted) {
final granted = await requestLocationPermission();
if (!granted) {
state = const AsyncValue.data(null);
return;
}
}
// 위치 서비스 확인
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
state = AsyncValue.error('위치 서비스가 비활성화되어 있습니다', StackTrace.current);
return;
}
// 위치 가져오기
final position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high,
timeLimit: const Duration(seconds: 10),
);
state = AsyncValue.data(position);
} catch (e, stack) {
// 오류 발생 시 마지막 알려진 위치 시도
try {
final lastPosition = await Geolocator.getLastKnownPosition();
state = AsyncValue.data(lastPosition);
} catch (_) {
state = AsyncValue.error(e, stack);
}
}
}
/// 두 지점 간의 거리 계산 (미터 단위)
double calculateDistance(
double startLatitude,
double startLongitude,
double endLatitude,
double endLongitude,
) {
return Geolocator.distanceBetween(
startLatitude,
startLongitude,
endLatitude,
endLongitude,
);
}
}
/// LocationNotifier Provider
final locationNotifierProvider = StateNotifierProvider<LocationNotifier, AsyncValue<Position?>>((ref) {
return LocationNotifier();
});

View File

@@ -0,0 +1,174 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:lunchpick/presentation/pages/calendar/widgets/visit_confirmation_dialog.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
/// 알림 payload 데이터 모델
class NotificationPayload {
final String type;
final String restaurantId;
final String restaurantName;
final DateTime recommendationTime;
NotificationPayload({
required this.type,
required this.restaurantId,
required this.restaurantName,
required this.recommendationTime,
});
factory NotificationPayload.fromString(String payload) {
try {
final parts = payload.split('|');
if (parts.length < 4) {
throw FormatException('Invalid payload format - expected 4 parts but got ${parts.length}: $payload');
}
// 각 필드 유효성 검증
if (parts[0].isEmpty) {
throw FormatException('Type cannot be empty');
}
if (parts[1].isEmpty) {
throw FormatException('Restaurant ID cannot be empty');
}
if (parts[2].isEmpty) {
throw FormatException('Restaurant name cannot be empty');
}
// DateTime 파싱 시도
DateTime? recommendationTime;
try {
recommendationTime = DateTime.parse(parts[3]);
} catch (e) {
throw FormatException('Invalid date format: ${parts[3]}. Error: $e');
}
return NotificationPayload(
type: parts[0],
restaurantId: parts[1],
restaurantName: parts[2],
recommendationTime: recommendationTime,
);
} catch (e) {
// 더 상세한 오류 정보 제공
print('NotificationPayload parsing error: $e');
print('Original payload: $payload');
rethrow;
}
}
String toString() {
return '$type|$restaurantId|$restaurantName|${recommendationTime.toIso8601String()}';
}
}
/// 알림 핸들러 StateNotifier
class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
final Ref _ref;
NotificationHandlerNotifier(this._ref) : super(const AsyncValue.data(null));
/// 알림 클릭 처리
Future<void> handleNotificationTap(BuildContext context, String? payload) async {
if (payload == null || payload.isEmpty) {
print('Notification payload is null or empty');
return;
}
print('Handling notification with payload: $payload');
try {
// 기존 형식 (visit_reminder:restaurantName) 처리
if (payload.startsWith('visit_reminder:')) {
final restaurantName = payload.substring(15);
print('Legacy format - Restaurant name: $restaurantName');
// 맛집 이름으로 ID 찾기
final restaurantsAsync = await _ref.read(restaurantListProvider.future);
final restaurant = restaurantsAsync.firstWhere(
(r) => r.name == restaurantName,
orElse: () => throw Exception('Restaurant not found: $restaurantName'),
);
// 방문 확인 다이얼로그 표시
if (context.mounted) {
await VisitConfirmationDialog.show(
context: context,
restaurantId: restaurant.id,
restaurantName: restaurant.name,
recommendationTime: DateTime.now().subtract(const Duration(hours: 2)),
);
}
} else {
// 새로운 형식의 payload 처리
print('Attempting to parse new format payload');
try {
final notificationPayload = NotificationPayload.fromString(payload);
print('Successfully parsed payload - Type: ${notificationPayload.type}, RestaurantId: ${notificationPayload.restaurantId}');
if (notificationPayload.type == 'visit_reminder') {
// 방문 확인 다이얼로그 표시
if (context.mounted) {
final confirmed = await VisitConfirmationDialog.show(
context: context,
restaurantId: notificationPayload.restaurantId,
restaurantName: notificationPayload.restaurantName,
recommendationTime: notificationPayload.recommendationTime,
);
// 확인 또는 취소 후 캘린더 화면으로 이동
if (context.mounted && confirmed != null) {
context.go('/home?tab=calendar');
}
}
}
} catch (parseError) {
print('Failed to parse new format, attempting fallback parsing');
print('Parse error: $parseError');
// Fallback: 간단한 파싱 시도
if (payload.contains('|')) {
final parts = payload.split('|');
if (parts.isNotEmpty && parts[0] == 'visit_reminder') {
// 최소한 캘린더로 이동
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('알림을 처리했습니다. 방문 기록을 확인해주세요.'),
),
);
context.go('/home?tab=calendar');
}
return;
}
}
// 파싱 실패 시 원래 에러 다시 발생
rethrow;
}
}
} catch (e, stackTrace) {
print('Error handling notification: $e');
print('Stack trace: $stackTrace');
state = AsyncValue.error(e, stackTrace);
// 에러 발생 시 기본적으로 캘린더 화면으로 이동
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('알림 처리 중 오류가 발생했습니다: ${e.toString()}'),
backgroundColor: Colors.red,
),
);
context.go('/home?tab=calendar');
}
}
}
}
/// NotificationHandler Provider
final notificationHandlerProvider = StateNotifierProvider<NotificationHandlerNotifier, AsyncValue<void>>((ref) {
return NotificationHandlerNotifier(ref);
});

View File

@@ -0,0 +1,19 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/services/notification_service.dart';
/// NotificationService 싱글톤 Provider
final notificationServiceProvider = Provider<NotificationService>((ref) {
return NotificationService();
});
/// 알림 권한 상태 Provider
final notificationPermissionProvider = FutureProvider<bool>((ref) async {
final service = ref.watch(notificationServiceProvider);
return await service.checkPermission();
});
/// 예약된 알림 목록 Provider
final pendingNotificationsProvider = FutureProvider((ref) async {
final service = ref.watch(notificationServiceProvider);
return await service.getPendingNotifications();
});

View File

@@ -0,0 +1,341 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/entities/recommendation_record.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
import 'package:lunchpick/domain/repositories/recommendation_repository.dart';
import 'package:lunchpick/domain/usecases/recommendation_engine.dart';
import 'package:lunchpick/presentation/providers/di_providers.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
import 'package:lunchpick/presentation/providers/settings_provider.dart' hide currentLocationProvider, locationPermissionProvider;
import 'package:lunchpick/presentation/providers/weather_provider.dart';
import 'package:lunchpick/presentation/providers/location_provider.dart';
import 'package:lunchpick/presentation/providers/visit_provider.dart';
import 'package:uuid/uuid.dart';
/// 추천 기록 목록 Provider
final recommendationRecordsProvider = StreamProvider<List<RecommendationRecord>>((ref) {
final repository = ref.watch(recommendationRepositoryProvider);
return repository.watchRecommendationRecords();
});
/// 오늘의 추천 횟수 Provider
final todayRecommendationCountProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(recommendationRepositoryProvider);
return repository.getTodayRecommendationCount();
});
/// 추천 설정 모델
class RecommendationSettings {
final int daysToExclude;
final int maxDistanceRainy;
final int maxDistanceNormal;
final List<String> selectedCategories;
RecommendationSettings({
required this.daysToExclude,
required this.maxDistanceRainy,
required this.maxDistanceNormal,
required this.selectedCategories,
});
}
/// 추천 관리 StateNotifier
class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
final RecommendationRepository _repository;
final Ref _ref;
final RecommendationEngine _recommendationEngine = RecommendationEngine();
RecommendationNotifier(this._repository, this._ref) : super(const AsyncValue.data(null));
/// 랜덤 추천 실행
Future<void> getRandomRecommendation({
required double maxDistance,
required List<String> selectedCategories,
}) async {
state = const AsyncValue.loading();
try {
// 현재 위치 가져오기
final location = await _ref.read(currentLocationProvider.future);
if (location == null) {
throw Exception('위치 정보를 가져올 수 없습니다');
}
// 날씨 정보 가져오기
final weather = await _ref.read(weatherProvider.future);
// 사용자 설정 가져오기
final userSettings = await _ref.read(userSettingsProvider.future);
// 모든 식당 가져오기
final allRestaurants = await _ref.read(restaurantListProvider.future);
// 방문 기록 가져오기
final allVisitRecords = await _ref.read(visitRecordsProvider.future);
// 추천 설정 구성
final config = RecommendationConfig(
userLatitude: location.latitude,
userLongitude: location.longitude,
maxDistance: maxDistance,
selectedCategories: selectedCategories,
userSettings: userSettings,
weather: weather,
);
// 추천 엔진 사용
final selectedRestaurant = await _recommendationEngine.generateRecommendation(
allRestaurants: allRestaurants,
recentVisits: allVisitRecords,
config: config,
);
if (selectedRestaurant == null) {
state = const AsyncValue.data(null);
return;
}
// 추천 기록 저장
await _saveRecommendationRecord(selectedRestaurant);
state = AsyncValue.data(selectedRestaurant);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 추천 기록 저장
Future<void> _saveRecommendationRecord(Restaurant restaurant) async {
final record = RecommendationRecord(
id: const Uuid().v4(),
restaurantId: restaurant.id,
recommendationDate: DateTime.now(),
visited: false,
createdAt: DateTime.now(),
);
await _repository.addRecommendationRecord(record);
}
/// 추천 후 방문 확인
Future<void> confirmVisit(String recommendationId) async {
try {
await _repository.markAsVisited(recommendationId);
// 방문 기록도 생성
final recommendations = await _ref.read(recommendationRecordsProvider.future);
final recommendation = recommendations.firstWhere((r) => r.id == recommendationId);
final visitNotifier = _ref.read(visitNotifierProvider.notifier);
await visitNotifier.createVisitFromRecommendation(
restaurantId: recommendation.restaurantId,
recommendationTime: recommendation.recommendationDate,
);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 추천 기록 삭제
Future<void> deleteRecommendation(String id) async {
try {
await _repository.deleteRecommendationRecord(id);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
}
/// RecommendationNotifier Provider
final recommendationNotifierProvider = StateNotifierProvider<RecommendationNotifier, AsyncValue<Restaurant?>>((ref) {
final repository = ref.watch(recommendationRepositoryProvider);
return RecommendationNotifier(repository, ref);
});
/// 월별 추천 통계 Provider
final monthlyRecommendationStatsProvider = FutureProvider.family<Map<String, int>, ({int year, int month})>((ref, params) async {
final repository = ref.watch(recommendationRepositoryProvider);
return repository.getMonthlyRecommendationStats(params.year, params.month);
});
/// 추천 상태 관리 (다시 추천 기능 포함)
class RecommendationState {
final Restaurant? currentRecommendation;
final List<Restaurant> excludedRestaurants;
final bool isLoading;
final String? error;
const RecommendationState({
this.currentRecommendation,
this.excludedRestaurants = const [],
this.isLoading = false,
this.error,
});
RecommendationState copyWith({
Restaurant? currentRecommendation,
List<Restaurant>? excludedRestaurants,
bool? isLoading,
String? error,
}) {
return RecommendationState(
currentRecommendation: currentRecommendation ?? this.currentRecommendation,
excludedRestaurants: excludedRestaurants ?? this.excludedRestaurants,
isLoading: isLoading ?? this.isLoading,
error: error,
);
}
}
/// 향상된 추천 StateNotifier (다시 추천 기능 포함)
class EnhancedRecommendationNotifier extends StateNotifier<RecommendationState> {
final Ref _ref;
final RecommendationEngine _recommendationEngine = RecommendationEngine();
EnhancedRecommendationNotifier(this._ref) : super(const RecommendationState());
/// 다시 추천 (현재 추천 제외)
Future<void> rerollRecommendation() async {
if (state.currentRecommendation == null) return;
// 현재 추천을 제외 목록에 추가
final excluded = [...state.excludedRestaurants, state.currentRecommendation!];
state = state.copyWith(excludedRestaurants: excluded);
// 다시 추천 생성 (제외 목록 적용)
await generateRecommendation(excludedRestaurants: excluded);
}
/// 추천 생성 (새로운 추천 엔진 활용)
Future<void> generateRecommendation({List<Restaurant>? excludedRestaurants}) async {
state = state.copyWith(isLoading: true);
try {
// 현재 위치 가져오기
final location = await _ref.read(currentLocationProvider.future);
if (location == null) {
state = state.copyWith(error: '위치 정보를 가져올 수 없습니다', isLoading: false);
return;
}
// 필요한 데이터 가져오기
final weather = await _ref.read(weatherProvider.future);
final userSettings = await _ref.read(userSettingsProvider.future);
final allRestaurants = await _ref.read(restaurantListProvider.future);
final allVisitRecords = await _ref.read(visitRecordsProvider.future);
final maxDistanceNormal = await _ref.read(maxDistanceNormalProvider.future);
final selectedCategory = _ref.read(selectedCategoryProvider);
final categories = selectedCategory != null ? [selectedCategory] : <String>[];
// 제외 리스트 포함한 식당 필터링
final availableRestaurants = excludedRestaurants != null
? allRestaurants.where((r) => !excludedRestaurants.any((ex) => ex.id == r.id)).toList()
: allRestaurants;
// 추천 설정 구성
final config = RecommendationConfig(
userLatitude: location.latitude,
userLongitude: location.longitude,
maxDistance: maxDistanceNormal.toDouble(),
selectedCategories: categories,
userSettings: userSettings,
weather: weather,
);
// 추천 엔진 사용
final selectedRestaurant = await _recommendationEngine.generateRecommendation(
allRestaurants: availableRestaurants,
recentVisits: allVisitRecords,
config: config,
);
if (selectedRestaurant != null) {
// 추천 기록 저장
final record = RecommendationRecord(
id: const Uuid().v4(),
restaurantId: selectedRestaurant.id,
recommendationDate: DateTime.now(),
visited: false,
createdAt: DateTime.now(),
);
final repository = _ref.read(recommendationRepositoryProvider);
await repository.addRecommendationRecord(record);
state = state.copyWith(
currentRecommendation: selectedRestaurant,
isLoading: false,
);
} else {
state = state.copyWith(
error: '조건에 맞는 맛집이 없습니다',
isLoading: false,
);
}
} catch (e) {
state = state.copyWith(
error: e.toString(),
isLoading: false,
);
}
}
/// 추천 초기화
void resetRecommendation() {
state = const RecommendationState();
}
}
/// 향상된 추천 Provider
final enhancedRecommendationProvider =
StateNotifierProvider<EnhancedRecommendationNotifier, RecommendationState>((ref) {
return EnhancedRecommendationNotifier(ref);
});
/// 추천 가능한 맛집 수 Provider
final recommendableRestaurantsCountProvider = FutureProvider<int>((ref) async {
final daysToExclude = await ref.watch(daysToExcludeProvider.future);
final recentlyVisited = await ref.watch(
restaurantsNotVisitedInDaysProvider(daysToExclude).future
);
return recentlyVisited.length;
});
/// 카테고리별 추천 통계 Provider
final recommendationStatsByCategoryProvider = FutureProvider<Map<String, int>>((ref) async {
final records = await ref.watch(recommendationRecordsProvider.future);
final stats = <String, int>{};
for (final record in records) {
final restaurant = await ref.watch(restaurantProvider(record.restaurantId).future);
if (restaurant != null) {
stats[restaurant.category] = (stats[restaurant.category] ?? 0) + 1;
}
}
return stats;
});
/// 추천 성공률 Provider
final recommendationSuccessRateProvider = FutureProvider<double>((ref) async {
final records = await ref.watch(recommendationRecordsProvider.future);
if (records.isEmpty) return 0.0;
final visitedCount = records.where((r) => r.visited).length;
return (visitedCount / records.length) * 100;
});
/// 가장 많이 추천된 맛집 Top 5 Provider
final topRecommendedRestaurantsProvider = FutureProvider<List<({String restaurantId, int count})>>((ref) async {
final records = await ref.watch(recommendationRecordsProvider.future);
final counts = <String, int>{};
for (final record in records) {
counts[record.restaurantId] = (counts[record.restaurantId] ?? 0) + 1;
}
final sorted = counts.entries.toList()
..sort((a, b) => b.value.compareTo(a.value));
return sorted.take(5).map((e) => (restaurantId: e.key, count: e.value)).toList();
});

View File

@@ -0,0 +1,216 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
import 'package:lunchpick/domain/repositories/restaurant_repository.dart';
import 'package:lunchpick/presentation/providers/di_providers.dart';
import 'package:uuid/uuid.dart';
/// 맛집 목록 Provider
final restaurantListProvider = StreamProvider<List<Restaurant>>((ref) {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.watchRestaurants();
});
/// 특정 맛집 Provider
final restaurantProvider = FutureProvider.family<Restaurant?, String>((ref, id) async {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.getRestaurantById(id);
});
/// 카테고리 목록 Provider
final categoriesProvider = FutureProvider<List<String>>((ref) async {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.getAllCategories();
});
/// 맛집 관리 StateNotifier
class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
final RestaurantRepository _repository;
RestaurantNotifier(this._repository) : super(const AsyncValue.data(null));
/// 맛집 추가
Future<void> addRestaurant({
required String name,
required String category,
required String subCategory,
String? description,
String? phoneNumber,
required String roadAddress,
required String jibunAddress,
required double latitude,
required double longitude,
required DataSource source,
}) async {
state = const AsyncValue.loading();
try {
final restaurant = Restaurant(
id: const Uuid().v4(),
name: name,
category: category,
subCategory: subCategory,
description: description,
phoneNumber: phoneNumber,
roadAddress: roadAddress,
jibunAddress: jibunAddress,
latitude: latitude,
longitude: longitude,
source: source,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
await _repository.addRestaurant(restaurant);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 맛집 수정
Future<void> updateRestaurant(Restaurant restaurant) async {
state = const AsyncValue.loading();
try {
final updated = Restaurant(
id: restaurant.id,
name: restaurant.name,
category: restaurant.category,
subCategory: restaurant.subCategory,
description: restaurant.description,
phoneNumber: restaurant.phoneNumber,
roadAddress: restaurant.roadAddress,
jibunAddress: restaurant.jibunAddress,
latitude: restaurant.latitude,
longitude: restaurant.longitude,
lastVisitDate: restaurant.lastVisitDate,
source: restaurant.source,
createdAt: restaurant.createdAt,
updatedAt: DateTime.now(),
);
await _repository.updateRestaurant(updated);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 맛집 삭제
Future<void> deleteRestaurant(String id) async {
state = const AsyncValue.loading();
try {
await _repository.deleteRestaurant(id);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 마지막 방문일 업데이트
Future<void> updateLastVisitDate(String restaurantId, DateTime visitDate) async {
try {
await _repository.updateLastVisitDate(restaurantId, visitDate);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 네이버 지도 URL로부터 맛집 추가
Future<Restaurant> addRestaurantFromUrl(String url) async {
state = const AsyncValue.loading();
try {
final restaurant = await _repository.addRestaurantFromUrl(url);
state = const AsyncValue.data(null);
return restaurant;
} catch (e, stack) {
state = AsyncValue.error(e, stack);
rethrow;
}
}
/// 미리 생성된 Restaurant 객체를 직접 추가
Future<void> addRestaurantDirect(Restaurant restaurant) async {
state = const AsyncValue.loading();
try {
await _repository.addRestaurant(restaurant);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
rethrow;
}
}
}
/// RestaurantNotifier Provider
final restaurantNotifierProvider = StateNotifierProvider<RestaurantNotifier, AsyncValue<void>>((ref) {
final repository = ref.watch(restaurantRepositoryProvider);
return RestaurantNotifier(repository);
});
/// 거리 내 맛집 Provider
final restaurantsWithinDistanceProvider = FutureProvider.family<List<Restaurant>, ({double latitude, double longitude, double maxDistance})>((ref, params) async {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.getRestaurantsWithinDistance(
userLatitude: params.latitude,
userLongitude: params.longitude,
maxDistanceInMeters: params.maxDistance,
);
});
/// n일 이내 방문하지 않은 맛집 Provider
final restaurantsNotVisitedInDaysProvider = FutureProvider.family<List<Restaurant>, int>((ref, days) async {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.getRestaurantsNotVisitedInDays(days);
});
/// 검색어로 맛집 검색 Provider
final searchRestaurantsProvider = FutureProvider.family<List<Restaurant>, String>((ref, query) async {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.searchRestaurants(query);
});
/// 카테고리별 맛집 Provider
final restaurantsByCategoryProvider = FutureProvider.family<List<Restaurant>, String>((ref, category) async {
final repository = ref.watch(restaurantRepositoryProvider);
return repository.getRestaurantsByCategory(category);
});
/// 검색 쿼리 상태 Provider
final searchQueryProvider = StateProvider<String>((ref) => '');
/// 선택된 카테고리 상태 Provider
final selectedCategoryProvider = StateProvider<String?>((ref) => null);
/// 필터링된 맛집 목록 Provider (검색 + 카테고리)
final filteredRestaurantsProvider = StreamProvider<List<Restaurant>>((ref) async* {
final searchQuery = ref.watch(searchQueryProvider);
final selectedCategory = ref.watch(selectedCategoryProvider);
final restaurantsStream = ref.watch(restaurantListProvider.stream);
await for (final restaurants in restaurantsStream) {
var filtered = restaurants;
// 검색 필터 적용
if (searchQuery.isNotEmpty) {
final lowercaseQuery = searchQuery.toLowerCase();
filtered = filtered.where((restaurant) {
return restaurant.name.toLowerCase().contains(lowercaseQuery) ||
(restaurant.description?.toLowerCase().contains(lowercaseQuery) ?? false) ||
restaurant.category.toLowerCase().contains(lowercaseQuery);
}).toList();
}
// 카테고리 필터 적용
if (selectedCategory != null) {
filtered = filtered.where((restaurant) {
return restaurant.category == selectedCategory;
}).toList();
}
yield filtered;
}
});

View File

@@ -0,0 +1,264 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/repositories/settings_repository.dart';
import 'package:lunchpick/domain/entities/user_settings.dart';
import 'package:lunchpick/presentation/providers/di_providers.dart';
/// 재방문 금지 일수 Provider
final daysToExcludeProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.getDaysToExclude();
});
/// 우천시 최대 거리 Provider
final maxDistanceRainyProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.getMaxDistanceRainy();
});
/// 평상시 최대 거리 Provider
final maxDistanceNormalProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.getMaxDistanceNormal();
});
/// 알림 지연 시간 Provider
final notificationDelayMinutesProvider = FutureProvider<int>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.getNotificationDelayMinutes();
});
/// 알림 활성화 여부 Provider
final notificationEnabledProvider = FutureProvider<bool>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.isNotificationEnabled();
});
/// 다크모드 활성화 여부 Provider
final darkModeEnabledProvider = FutureProvider<bool>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.isDarkModeEnabled();
});
/// 첫 실행 여부 Provider
final isFirstRunProvider = FutureProvider<bool>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.isFirstRun();
});
/// 설정 스트림 Provider
final settingsStreamProvider = StreamProvider<Map<String, dynamic>>((ref) {
final repository = ref.watch(settingsRepositoryProvider);
return repository.watchSettings();
});
/// UserSettings Provider
final userSettingsProvider = FutureProvider<UserSettings>((ref) async {
final repository = ref.watch(settingsRepositoryProvider);
return repository.getUserSettings();
});
/// UserSettings 스트림 Provider
final userSettingsStreamProvider = StreamProvider<UserSettings>((ref) {
final repository = ref.watch(settingsRepositoryProvider);
return repository.watchUserSettings();
});
/// 설정 관리 StateNotifier
class SettingsNotifier extends StateNotifier<AsyncValue<void>> {
final SettingsRepository _repository;
SettingsNotifier(this._repository) : super(const AsyncValue.data(null));
/// 재방문 금지 일수 설정
Future<void> setDaysToExclude(int days) async {
state = const AsyncValue.loading();
try {
await _repository.setDaysToExclude(days);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 우천시 최대 거리 설정
Future<void> setMaxDistanceRainy(int meters) async {
state = const AsyncValue.loading();
try {
await _repository.setMaxDistanceRainy(meters);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 평상시 최대 거리 설정
Future<void> setMaxDistanceNormal(int meters) async {
state = const AsyncValue.loading();
try {
await _repository.setMaxDistanceNormal(meters);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 알림 지연 시간 설정
Future<void> setNotificationDelayMinutes(int minutes) async {
state = const AsyncValue.loading();
try {
await _repository.setNotificationDelayMinutes(minutes);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 알림 활성화 설정
Future<void> setNotificationEnabled(bool enabled) async {
state = const AsyncValue.loading();
try {
await _repository.setNotificationEnabled(enabled);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 다크모드 설정
Future<void> setDarkModeEnabled(bool enabled) async {
state = const AsyncValue.loading();
try {
await _repository.setDarkModeEnabled(enabled);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 첫 실행 상태 업데이트
Future<void> setFirstRun(bool isFirst) async {
state = const AsyncValue.loading();
try {
await _repository.setFirstRun(isFirst);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 설정 초기화
Future<void> resetSettings() async {
state = const AsyncValue.loading();
try {
await _repository.resetSettings();
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// UserSettings 업데이트
Future<void> updateUserSettings(UserSettings settings) async {
state = const AsyncValue.loading();
try {
await _repository.updateUserSettings(settings);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
}
/// SettingsNotifier Provider
final settingsNotifierProvider = StateNotifierProvider<SettingsNotifier, AsyncValue<void>>((ref) {
final repository = ref.watch(settingsRepositoryProvider);
return SettingsNotifier(repository);
});
/// 설정 프리셋
enum SettingsPreset {
normal(
name: '일반 모드',
daysToExclude: 7,
maxDistanceNormal: 1000,
maxDistanceRainy: 500,
),
economic(
name: '절약 모드',
daysToExclude: 3,
maxDistanceNormal: 500,
maxDistanceRainy: 300,
),
convenience(
name: '편의 모드',
daysToExclude: 14,
maxDistanceNormal: 2000,
maxDistanceRainy: 1000,
);
final String name;
final int daysToExclude;
final int maxDistanceNormal;
final int maxDistanceRainy;
const SettingsPreset({
required this.name,
required this.daysToExclude,
required this.maxDistanceNormal,
required this.maxDistanceRainy,
});
}
/// 프리셋 적용 Provider
final applyPresetProvider = Provider.family<Future<void>, SettingsPreset>((ref, preset) async {
final notifier = ref.read(settingsNotifierProvider.notifier);
await notifier.setDaysToExclude(preset.daysToExclude);
await notifier.setMaxDistanceNormal(preset.maxDistanceNormal);
await notifier.setMaxDistanceRainy(preset.maxDistanceRainy);
});
/// 현재 위치 Provider
final currentLocationProvider = StateProvider<({double latitude, double longitude})?>((ref) => null);
/// 선호 카테고리 Provider
final preferredCategoriesProvider = StateProvider<List<String>>((ref) => []);
/// 제외 카테고리 Provider
final excludedCategoriesProvider = StateProvider<List<String>>((ref) => []);
/// 언어 설정 Provider
final languageProvider = StateProvider<String>((ref) => 'ko');
/// 위치 권한 상태 Provider
final locationPermissionProvider = StateProvider<bool>((ref) => false);
/// 알림 권한 상태 Provider
final notificationPermissionProvider = StateProvider<bool>((ref) => false);
/// 모든 설정 상태를 통합한 Provider
final allSettingsProvider = Provider<Map<String, dynamic>>((ref) {
final daysToExclude = ref.watch(daysToExcludeProvider).value ?? 7;
final maxDistanceRainy = ref.watch(maxDistanceRainyProvider).value ?? 500;
final maxDistanceNormal = ref.watch(maxDistanceNormalProvider).value ?? 1000;
final notificationDelay = ref.watch(notificationDelayMinutesProvider).value ?? 90;
final notificationEnabled = ref.watch(notificationEnabledProvider).value ?? false;
final darkMode = ref.watch(darkModeEnabledProvider).value ?? false;
final currentLocation = ref.watch(currentLocationProvider);
final preferredCategories = ref.watch(preferredCategoriesProvider);
final excludedCategories = ref.watch(excludedCategoriesProvider);
final language = ref.watch(languageProvider);
return {
'daysToExclude': daysToExclude,
'maxDistanceRainy': maxDistanceRainy,
'maxDistanceNormal': maxDistanceNormal,
'notificationDelayMinutes': notificationDelay,
'notificationEnabled': notificationEnabled,
'darkModeEnabled': darkMode,
'currentLocation': currentLocation,
'preferredCategories': preferredCategories,
'excludedCategories': excludedCategories,
'language': language,
};
});

View File

@@ -0,0 +1,214 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/entities/visit_record.dart';
import 'package:lunchpick/domain/repositories/visit_repository.dart';
import 'package:lunchpick/presentation/providers/di_providers.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
import 'package:uuid/uuid.dart';
/// 방문 기록 목록 Provider
final visitRecordsProvider = StreamProvider<List<VisitRecord>>((ref) {
final repository = ref.watch(visitRepositoryProvider);
return repository.watchVisitRecords();
});
/// 날짜별 방문 기록 Provider
final visitRecordsByDateProvider = FutureProvider.family<List<VisitRecord>, DateTime>((ref, date) async {
final repository = ref.watch(visitRepositoryProvider);
return repository.getVisitRecordsByDate(date);
});
/// 맛집별 방문 기록 Provider
final visitRecordsByRestaurantProvider = FutureProvider.family<List<VisitRecord>, String>((ref, restaurantId) async {
final repository = ref.watch(visitRepositoryProvider);
return repository.getVisitRecordsByRestaurantId(restaurantId);
});
/// 월별 방문 통계 Provider
final monthlyVisitStatsProvider = FutureProvider.family<Map<String, int>, ({int year, int month})>((ref, params) async {
final repository = ref.watch(visitRepositoryProvider);
return repository.getMonthlyVisitStats(params.year, params.month);
});
/// 방문 기록 관리 StateNotifier
class VisitNotifier extends StateNotifier<AsyncValue<void>> {
final VisitRepository _repository;
final Ref _ref;
VisitNotifier(this._repository, this._ref) : super(const AsyncValue.data(null));
/// 방문 기록 추가
Future<void> addVisitRecord({
required String restaurantId,
required DateTime visitDate,
bool isConfirmed = false,
}) async {
state = const AsyncValue.loading();
try {
final visitRecord = VisitRecord(
id: const Uuid().v4(),
restaurantId: restaurantId,
visitDate: visitDate,
isConfirmed: isConfirmed,
createdAt: DateTime.now(),
);
await _repository.addVisitRecord(visitRecord);
// 맛집의 마지막 방문일도 업데이트
final restaurantNotifier = _ref.read(restaurantNotifierProvider.notifier);
await restaurantNotifier.updateLastVisitDate(restaurantId, visitDate);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 방문 확인
Future<void> confirmVisit(String visitRecordId) async {
state = const AsyncValue.loading();
try {
await _repository.confirmVisit(visitRecordId);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 방문 기록 삭제
Future<void> deleteVisitRecord(String id) async {
state = const AsyncValue.loading();
try {
await _repository.deleteVisitRecord(id);
state = const AsyncValue.data(null);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 추천 후 자동 방문 기록 생성
Future<void> createVisitFromRecommendation({
required String restaurantId,
required DateTime recommendationTime,
}) async {
// 추천 시간으로부터 1.5시간 후를 방문 시간으로 설정
final visitTime = recommendationTime.add(const Duration(minutes: 90));
await addVisitRecord(
restaurantId: restaurantId,
visitDate: visitTime,
isConfirmed: false, // 나중에 확인 필요
);
}
}
/// VisitNotifier Provider
final visitNotifierProvider = StateNotifierProvider<VisitNotifier, AsyncValue<void>>((ref) {
final repository = ref.watch(visitRepositoryProvider);
return VisitNotifier(repository, ref);
});
/// 특정 맛집의 마지막 방문일 Provider
final lastVisitDateProvider = FutureProvider.family<DateTime?, String>((ref, restaurantId) async {
final repository = ref.watch(visitRepositoryProvider);
return repository.getLastVisitDate(restaurantId);
});
/// 기간별 방문 기록 Provider
final visitRecordsByPeriodProvider = FutureProvider.family<List<VisitRecord>, ({DateTime startDate, DateTime endDate})>((ref, params) async {
final allRecords = await ref.watch(visitRecordsProvider.future);
return allRecords.where((record) {
return record.visitDate.isAfter(params.startDate) &&
record.visitDate.isBefore(params.endDate.add(const Duration(days: 1)));
}).toList()
..sort((a, b) => b.visitDate.compareTo(a.visitDate));
});
/// 주간 방문 통계 Provider (최근 7일)
final weeklyVisitStatsProvider = FutureProvider<Map<String, int>>((ref) async {
final now = DateTime.now();
final startOfWeek = DateTime(now.year, now.month, now.day).subtract(const Duration(days: 6));
final records = await ref.watch(visitRecordsByPeriodProvider((
startDate: startOfWeek,
endDate: now,
)).future);
final stats = <String, int>{};
for (var i = 0; i < 7; i++) {
final date = startOfWeek.add(Duration(days: i));
final dateKey = '${date.month}/${date.day}';
stats[dateKey] = records.where((r) =>
r.visitDate.year == date.year &&
r.visitDate.month == date.month &&
r.visitDate.day == date.day
).length;
}
return stats;
});
/// 자주 방문하는 맛집 Provider (상위 10개)
final frequentRestaurantsProvider = FutureProvider<List<({String restaurantId, int visitCount})>>((ref) async {
final allRecords = await ref.watch(visitRecordsProvider.future);
final visitCounts = <String, int>{};
for (final record in allRecords) {
visitCounts[record.restaurantId] = (visitCounts[record.restaurantId] ?? 0) + 1;
}
final sorted = visitCounts.entries.toList()
..sort((a, b) => b.value.compareTo(a.value));
return sorted.take(10).map((e) => (restaurantId: e.key, visitCount: e.value)).toList();
});
/// 방문 기록 정렬 옵션
enum VisitSortOption {
dateDesc, // 최신순
dateAsc, // 오래된순
restaurant, // 맛집별
}
/// 정렬된 방문 기록 Provider
final sortedVisitRecordsProvider = Provider.family<AsyncValue<List<VisitRecord>>, VisitSortOption>((ref, sortOption) {
final recordsAsync = ref.watch(visitRecordsProvider);
return recordsAsync.when(
data: (records) {
final sorted = List<VisitRecord>.from(records);
switch (sortOption) {
case VisitSortOption.dateDesc:
sorted.sort((a, b) => b.visitDate.compareTo(a.visitDate));
break;
case VisitSortOption.dateAsc:
sorted.sort((a, b) => a.visitDate.compareTo(b.visitDate));
break;
case VisitSortOption.restaurant:
sorted.sort((a, b) => a.restaurantId.compareTo(b.restaurantId));
break;
}
return AsyncValue.data(sorted);
},
loading: () => const AsyncValue.loading(),
error: (error, stack) => AsyncValue.error(error, stack),
);
});
/// 카테고리별 방문 통계 Provider
final categoryVisitStatsProvider = FutureProvider<Map<String, int>>((ref) async {
final allRecords = await ref.watch(visitRecordsProvider.future);
final restaurantsAsync = await ref.watch(restaurantListProvider.future);
final categoryCount = <String, int>{};
for (final record in allRecords) {
final restaurant = restaurantsAsync.where((r) => r.id == record.restaurantId).firstOrNull;
if (restaurant != null) {
categoryCount[restaurant.category] = (categoryCount[restaurant.category] ?? 0) + 1;
}
}
return categoryCount;
});

View File

@@ -0,0 +1,92 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/entities/weather_info.dart';
import 'package:lunchpick/domain/repositories/weather_repository.dart';
import 'package:lunchpick/presentation/providers/di_providers.dart';
import 'package:lunchpick/presentation/providers/location_provider.dart';
/// 현재 날씨 Provider
final weatherProvider = FutureProvider<WeatherInfo>((ref) async {
final repository = ref.watch(weatherRepositoryProvider);
final location = await ref.watch(currentLocationProvider.future);
if (location == null) {
throw Exception('위치 정보를 가져올 수 없습니다');
}
// 캐시된 날씨 정보 확인
final cached = await repository.getCachedWeather();
if (cached != null) {
return cached;
}
// 새로운 날씨 정보 가져오기
return repository.getCurrentWeather(
latitude: location.latitude,
longitude: location.longitude,
);
});
/// 날씨 업데이트 필요 여부 Provider
final isWeatherUpdateNeededProvider = FutureProvider<bool>((ref) async {
final repository = ref.watch(weatherRepositoryProvider);
return repository.isWeatherUpdateNeeded();
});
/// 날씨 관리 StateNotifier
class WeatherNotifier extends StateNotifier<AsyncValue<WeatherInfo>> {
final WeatherRepository _repository;
final Ref _ref;
WeatherNotifier(this._repository, this._ref) : super(const AsyncValue.loading());
/// 날씨 정보 새로고침
Future<void> refreshWeather() async {
state = const AsyncValue.loading();
try {
final location = await _ref.read(currentLocationProvider.future);
if (location == null) {
throw Exception('위치 정보를 가져올 수 없습니다');
}
final weather = await _repository.getCurrentWeather(
latitude: location.latitude,
longitude: location.longitude,
);
state = AsyncValue.data(weather);
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 캐시에서 날씨 정보 로드
Future<void> loadCachedWeather() async {
try {
final cached = await _repository.getCachedWeather();
if (cached != null) {
state = AsyncValue.data(cached);
} else {
// 캐시가 없으면 새로 가져오기
await refreshWeather();
}
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
/// 날씨 캐시 삭제
Future<void> clearCache() async {
try {
await _repository.clearWeatherCache();
} catch (e, stack) {
state = AsyncValue.error(e, stack);
}
}
}
/// WeatherNotifier Provider
final weatherNotifierProvider = StateNotifierProvider<WeatherNotifier, AsyncValue<WeatherInfo>>((ref) {
final repository = ref.watch(weatherRepositoryProvider);
return WeatherNotifier(repository, ref);
});

View File

@@ -0,0 +1,163 @@
import '../../core/utils/validators.dart';
import '../view_models/add_restaurant_view_model.dart';
/// 식당 폼 검증 서비스
class RestaurantFormValidator {
/// 폼 데이터 검증
static Map<String, String?> validateFormData(RestaurantFormData formData) {
final errors = <String, String?>{};
// 이름 검증
if (formData.name.isEmpty) {
errors['name'] = '가게 이름을 입력해주세요';
}
// 카테고리 검증
if (formData.category.isEmpty) {
errors['category'] = '카테고리를 입력해주세요';
}
// 도로명 주소 검증
if (formData.roadAddress.isEmpty) {
errors['roadAddress'] = '도로명 주소를 입력해주세요';
}
// 위도 검증
if (formData.latitude.isNotEmpty) {
final latitudeError = Validators.validateLatitude(formData.latitude);
if (latitudeError != null) {
errors['latitude'] = latitudeError;
}
}
// 경도 검증
if (formData.longitude.isNotEmpty) {
final longitudeError = Validators.validateLongitude(formData.longitude);
if (longitudeError != null) {
errors['longitude'] = longitudeError;
}
}
return errors;
}
/// 네이버 URL 검증
static String? validateNaverUrl(String url) {
if (url.trim().isEmpty) {
return 'URL을 입력해주세요';
}
// 네이버 지도 URL 패턴 검증
final naverMapRegex = RegExp(
r'^https?://(map\.naver\.com|naver\.me)',
caseSensitive: false,
);
if (!naverMapRegex.hasMatch(url)) {
return '네이버 지도 URL만 입력 가능합니다';
}
return null;
}
/// 전화번호 형식 검증
static String? validatePhoneNumber(String? phoneNumber) {
if (phoneNumber == null || phoneNumber.isEmpty) {
return null; // 선택 필드
}
// 전화번호 패턴: 02-1234-5678, 010-1234-5678 등
final phoneRegex = RegExp(
r'^0\d{1,2}-?\d{3,4}-?\d{4}$',
);
if (!phoneRegex.hasMatch(phoneNumber.replaceAll(' ', ''))) {
return '올바른 전화번호 형식이 아닙니다';
}
return null;
}
/// 주소 형식 검증
static String? validateAddress(String? address) {
if (address == null || address.isEmpty) {
return '주소를 입력해주세요';
}
// 최소 길이 검증
if (address.length < 5) {
return '올바른 주소를 입력해주세요';
}
return null;
}
/// 카테고리 검증
static String? validateCategory(String? category) {
if (category == null || category.isEmpty) {
return '카테고리를 입력해주세요';
}
// 허용된 카테고리 목록 (필요시 추가)
// final allowedCategories = [
// '한식', '중식', '일식', '양식', '아시안',
// '카페', '디저트', '분식', '패스트푸드', '기타'
// ];
// 정확한 매칭이 아니어도 허용 (사용자 입력 고려)
// 필요시 더 엄격한 검증 추가 가능
return null;
}
/// 전체 폼 유효성 검사
static bool isFormValid(RestaurantFormData formData) {
final errors = validateFormData(formData);
return errors.isEmpty;
}
/// 필수 필드만 검증
static bool hasRequiredFields(RestaurantFormData formData) {
return formData.name.isNotEmpty &&
formData.category.isNotEmpty &&
formData.roadAddress.isNotEmpty;
}
}
/// 폼 필드 에러 메시지 클래스
class FormFieldErrors {
final String? name;
final String? category;
final String? roadAddress;
final String? latitude;
final String? longitude;
final String? phoneNumber;
const FormFieldErrors({
this.name,
this.category,
this.roadAddress,
this.latitude,
this.longitude,
this.phoneNumber,
});
bool get hasErrors =>
name != null ||
category != null ||
roadAddress != null ||
latitude != null ||
longitude != null ||
phoneNumber != null;
Map<String, String> toMap() {
final map = <String, String>{};
if (name != null) map['name'] = name!;
if (category != null) map['category'] = category!;
if (roadAddress != null) map['roadAddress'] = roadAddress!;
if (latitude != null) map['latitude'] = latitude!;
if (longitude != null) map['longitude'] = longitude!;
if (phoneNumber != null) map['phoneNumber'] = phoneNumber!;
return map;
}
}

View File

@@ -0,0 +1,246 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:uuid/uuid.dart';
import '../../domain/entities/restaurant.dart';
import '../providers/restaurant_provider.dart';
/// 식당 추가 화면의 상태 모델
class AddRestaurantState {
final bool isLoading;
final String? errorMessage;
final Restaurant? fetchedRestaurantData;
final RestaurantFormData formData;
const AddRestaurantState({
this.isLoading = false,
this.errorMessage,
this.fetchedRestaurantData,
required this.formData,
});
AddRestaurantState copyWith({
bool? isLoading,
String? errorMessage,
Restaurant? fetchedRestaurantData,
RestaurantFormData? formData,
}) {
return AddRestaurantState(
isLoading: isLoading ?? this.isLoading,
errorMessage: errorMessage ?? this.errorMessage,
fetchedRestaurantData: fetchedRestaurantData ?? this.fetchedRestaurantData,
formData: formData ?? this.formData,
);
}
}
/// 식당 폼 데이터 모델
class RestaurantFormData {
final String name;
final String category;
final String subCategory;
final String description;
final String phoneNumber;
final String roadAddress;
final String jibunAddress;
final String latitude;
final String longitude;
final String naverUrl;
const RestaurantFormData({
this.name = '',
this.category = '',
this.subCategory = '',
this.description = '',
this.phoneNumber = '',
this.roadAddress = '',
this.jibunAddress = '',
this.latitude = '',
this.longitude = '',
this.naverUrl = '',
});
RestaurantFormData copyWith({
String? name,
String? category,
String? subCategory,
String? description,
String? phoneNumber,
String? roadAddress,
String? jibunAddress,
String? latitude,
String? longitude,
String? naverUrl,
}) {
return RestaurantFormData(
name: name ?? this.name,
category: category ?? this.category,
subCategory: subCategory ?? this.subCategory,
description: description ?? this.description,
phoneNumber: phoneNumber ?? this.phoneNumber,
roadAddress: roadAddress ?? this.roadAddress,
jibunAddress: jibunAddress ?? this.jibunAddress,
latitude: latitude ?? this.latitude,
longitude: longitude ?? this.longitude,
naverUrl: naverUrl ?? this.naverUrl,
);
}
/// TextEditingController로부터 폼 데이터 생성
factory RestaurantFormData.fromControllers({
required TextEditingController nameController,
required TextEditingController categoryController,
required TextEditingController subCategoryController,
required TextEditingController descriptionController,
required TextEditingController phoneController,
required TextEditingController roadAddressController,
required TextEditingController jibunAddressController,
required TextEditingController latitudeController,
required TextEditingController longitudeController,
required TextEditingController naverUrlController,
}) {
return RestaurantFormData(
name: nameController.text.trim(),
category: categoryController.text.trim(),
subCategory: subCategoryController.text.trim(),
description: descriptionController.text.trim(),
phoneNumber: phoneController.text.trim(),
roadAddress: roadAddressController.text.trim(),
jibunAddress: jibunAddressController.text.trim(),
latitude: latitudeController.text.trim(),
longitude: longitudeController.text.trim(),
naverUrl: naverUrlController.text.trim(),
);
}
/// Restaurant 엔티티로부터 폼 데이터 생성
factory RestaurantFormData.fromRestaurant(Restaurant restaurant) {
return RestaurantFormData(
name: restaurant.name,
category: restaurant.category,
subCategory: restaurant.subCategory,
description: restaurant.description ?? '',
phoneNumber: restaurant.phoneNumber ?? '',
roadAddress: restaurant.roadAddress,
jibunAddress: restaurant.jibunAddress,
latitude: restaurant.latitude.toString(),
longitude: restaurant.longitude.toString(),
naverUrl: restaurant.naverUrl ?? '',
);
}
/// Restaurant 엔티티로 변환
Restaurant toRestaurant() {
final uuid = const Uuid();
return Restaurant(
id: uuid.v4(),
name: name,
category: category,
subCategory: subCategory.isEmpty ? category : subCategory,
description: description.isEmpty ? null : description,
phoneNumber: phoneNumber.isEmpty ? null : phoneNumber,
roadAddress: roadAddress,
jibunAddress: jibunAddress.isEmpty ? roadAddress : jibunAddress,
latitude: double.tryParse(latitude) ?? 37.5665,
longitude: double.tryParse(longitude) ?? 126.9780,
naverUrl: naverUrl.isEmpty ? null : naverUrl,
source: naverUrl.isNotEmpty ? DataSource.NAVER : DataSource.USER_INPUT,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
}
}
/// 식당 추가 화면의 ViewModel
class AddRestaurantViewModel extends StateNotifier<AddRestaurantState> {
final Ref _ref;
AddRestaurantViewModel(this._ref)
: super(const AddRestaurantState(formData: RestaurantFormData()));
/// 네이버 URL로부터 식당 정보 가져오기
Future<void> fetchFromNaverUrl(String url) async {
if (url.trim().isEmpty) {
state = state.copyWith(errorMessage: 'URL을 입력해주세요.');
return;
}
state = state.copyWith(isLoading: true, errorMessage: null);
try {
final notifier = _ref.read(restaurantNotifierProvider.notifier);
final restaurant = await notifier.addRestaurantFromUrl(url);
state = state.copyWith(
isLoading: false,
fetchedRestaurantData: restaurant,
formData: RestaurantFormData.fromRestaurant(restaurant),
);
} catch (e) {
state = state.copyWith(
isLoading: false,
errorMessage: e.toString(),
);
}
}
/// 식당 정보 저장
Future<bool> saveRestaurant() async {
final notifier = _ref.read(restaurantNotifierProvider.notifier);
try {
Restaurant restaurantToSave;
// 네이버에서 가져온 데이터가 있으면 업데이트
final fetchedData = state.fetchedRestaurantData;
if (fetchedData != null) {
restaurantToSave = fetchedData.copyWith(
name: state.formData.name,
category: state.formData.category,
subCategory: state.formData.subCategory.isEmpty
? state.formData.category
: state.formData.subCategory,
description: state.formData.description.isEmpty
? null
: state.formData.description,
phoneNumber: state.formData.phoneNumber.isEmpty
? null
: state.formData.phoneNumber,
roadAddress: state.formData.roadAddress,
jibunAddress: state.formData.jibunAddress.isEmpty
? state.formData.roadAddress
: state.formData.jibunAddress,
latitude: double.tryParse(state.formData.latitude) ?? fetchedData.latitude,
longitude: double.tryParse(state.formData.longitude) ?? fetchedData.longitude,
naverUrl: state.formData.naverUrl.isEmpty ? null : state.formData.naverUrl,
updatedAt: DateTime.now(),
);
} else {
// 직접 입력한 경우
restaurantToSave = state.formData.toRestaurant();
}
await notifier.addRestaurantDirect(restaurantToSave);
return true;
} catch (e) {
state = state.copyWith(errorMessage: e.toString());
return false;
}
}
/// 폼 데이터 업데이트
void updateFormData(RestaurantFormData formData) {
state = state.copyWith(formData: formData);
}
/// 에러 메시지 초기화
void clearError() {
state = state.copyWith(errorMessage: null);
}
}
/// AddRestaurantViewModel Provider
final addRestaurantViewModelProvider =
StateNotifierProvider.autoDispose<AddRestaurantViewModel, AddRestaurantState>(
(ref) => AddRestaurantViewModel(ref),
);

View File

@@ -0,0 +1,332 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/core/constants/app_colors.dart';
import 'package:lunchpick/core/utils/category_mapper.dart';
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
class CategorySelector extends ConsumerWidget {
final String? selectedCategory;
final Function(String?) onCategorySelected;
final bool showAllOption;
final bool multiSelect;
final List<String>? selectedCategories;
final Function(List<String>)? onMultipleSelected;
const CategorySelector({
super.key,
this.selectedCategory,
required this.onCategorySelected,
this.showAllOption = true,
this.multiSelect = false,
this.selectedCategories,
this.onMultipleSelected,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final categoriesAsync = ref.watch(categoriesProvider);
return categoriesAsync.when(
data: (categories) {
return SizedBox(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
if (showAllOption && !multiSelect) ...[
_buildCategoryChip(
context: context,
label: '전체',
icon: Icons.restaurant_menu,
color: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
isSelected: selectedCategory == null,
onTap: () => onCategorySelected(null),
),
const SizedBox(width: 8),
],
...categories.map((category) {
final isSelected = multiSelect
? selectedCategories?.contains(category) ?? false
: selectedCategory == category;
return Padding(
padding: const EdgeInsets.only(right: 8),
child: _buildCategoryChip(
context: context,
label: CategoryMapper.getDisplayName(category),
icon: CategoryMapper.getIcon(category),
color: CategoryMapper.getColor(category),
isSelected: isSelected,
onTap: () {
if (multiSelect) {
_handleMultiSelect(category);
} else {
onCategorySelected(category);
}
},
),
);
}).toList(),
],
),
);
},
loading: () => const SizedBox(
height: 50,
child: Center(
child: CircularProgressIndicator(),
),
),
error: (error, stack) => const SizedBox(
height: 50,
child: Center(
child: Text('카테고리를 불러올 수 없습니다'),
),
),
);
}
void _handleMultiSelect(String category) {
if (onMultipleSelected == null || selectedCategories == null) return;
final List<String> updatedCategories = List.from(selectedCategories!);
if (updatedCategories.contains(category)) {
updatedCategories.remove(category);
} else {
updatedCategories.add(category);
}
onMultipleSelected!(updatedCategories);
}
Widget _buildCategoryChip({
required BuildContext context,
required String label,
required IconData icon,
required Color color,
required bool isSelected,
required VoidCallback onTap,
}) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(20),
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
color: isSelected
? color.withOpacity(0.2)
: isDark
? AppColors.darkSurface
: AppColors.lightBackground,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isSelected ? color : Colors.transparent,
width: 2,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 20,
color: isSelected
? color
: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
),
const SizedBox(width: 6),
Text(
label,
style: TextStyle(
color: isSelected
? color
: isDark
? AppColors.darkText
: AppColors.lightText,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
],
),
),
),
);
}
}
/// 카테고리 선택 다이얼로그
class CategorySelectionDialog extends ConsumerWidget {
final List<String> selectedCategories;
final String title;
final String? subtitle;
const CategorySelectionDialog({
super.key,
required this.selectedCategories,
this.title = '카테고리 선택',
this.subtitle,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final categoriesAsync = ref.watch(categoriesProvider);
return AlertDialog(
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title),
if (subtitle != null) ...[
const SizedBox(height: 4),
Text(
subtitle!,
style: TextStyle(
fontSize: 14,
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
),
],
],
),
content: categoriesAsync.when(
data: (categories) => SizedBox(
width: double.maxFinite,
child: GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
childAspectRatio: 1.2,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
),
itemCount: categories.length,
itemBuilder: (context, index) {
final category = categories[index];
final isSelected = selectedCategories.contains(category);
return _CategoryGridItem(
category: category,
isSelected: isSelected,
onTap: () {
final updatedCategories = List<String>.from(selectedCategories);
if (isSelected) {
updatedCategories.remove(category);
} else {
updatedCategories.add(category);
}
Navigator.pop(context, updatedCategories);
},
);
},
),
),
loading: () => const Center(
child: CircularProgressIndicator(),
),
error: (error, stack) => Center(
child: Text('카테고리를 불러올 수 없습니다: $error'),
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(
'취소',
style: TextStyle(
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
),
),
),
TextButton(
onPressed: () => Navigator.pop(context, selectedCategories),
child: const Text('확인'),
),
],
);
}
}
class _CategoryGridItem extends StatelessWidget {
final String category;
final bool isSelected;
final VoidCallback onTap;
const _CategoryGridItem({
required this.category,
required this.isSelected,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final color = CategoryMapper.getColor(category);
final icon = CategoryMapper.getIcon(category);
final displayName = CategoryMapper.getDisplayName(category);
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: isSelected
? color.withOpacity(0.2)
: isDark
? AppColors.darkCard
: AppColors.lightCard,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected ? color : Colors.transparent,
width: 2,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
size: 28,
color: isSelected
? color
: isDark
? AppColors.darkTextSecondary
: AppColors.lightTextSecondary,
),
const SizedBox(height: 4),
Text(
displayName,
style: TextStyle(
fontSize: 12,
color: isSelected
? color
: isDark
? AppColors.darkText
: AppColors.lightText,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
);
}
}