feat(app): add manual entry and sharing flows
This commit is contained in:
@@ -15,13 +15,14 @@ class CalendarScreen extends ConsumerStatefulWidget {
|
||||
ConsumerState<CalendarScreen> createState() => _CalendarScreenState();
|
||||
}
|
||||
|
||||
class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTickerProviderStateMixin {
|
||||
class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late DateTime _selectedDay;
|
||||
late DateTime _focusedDay;
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
late TabController _tabController;
|
||||
Map<DateTime, List<VisitRecord>> _visitRecordEvents = {};
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -29,27 +30,31 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
_focusedDay = DateTime.now();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
List<VisitRecord> _getEventsForDay(DateTime day) {
|
||||
final normalizedDay = DateTime(day.year, day.month, day.day);
|
||||
return _visitRecordEvents[normalizedDay] ?? [];
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('방문 기록'),
|
||||
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
bottom: TabBar(
|
||||
@@ -73,12 +78,12 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildCalendarTab(bool isDark) {
|
||||
return Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final visitRecordsAsync = ref.watch(visitRecordsProvider);
|
||||
|
||||
|
||||
// 방문 기록을 날짜별로 그룹화
|
||||
visitRecordsAsync.whenData((records) {
|
||||
_visitRecordEvents = {};
|
||||
@@ -94,148 +99,147 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// 캘린더
|
||||
Card(
|
||||
margin: const EdgeInsets.all(16),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.utc(2025, 1, 1),
|
||||
lastDay: DateTime.utc(2030, 12, 31),
|
||||
focusedDay: _focusedDay,
|
||||
calendarFormat: _calendarFormat,
|
||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
});
|
||||
},
|
||||
onFormatChanged: (format) {
|
||||
setState(() {
|
||||
_calendarFormat = format;
|
||||
});
|
||||
},
|
||||
eventLoader: _getEventsForDay,
|
||||
calendarBuilders: CalendarBuilders(
|
||||
markerBuilder: (context, day, events) {
|
||||
if (events.isEmpty) return null;
|
||||
|
||||
final visitRecords = events.cast<VisitRecord>();
|
||||
final confirmedCount = visitRecords.where((r) => r.isConfirmed).length;
|
||||
final unconfirmedCount = visitRecords.length - confirmedCount;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (confirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (unconfirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.orange,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
margin: const EdgeInsets.all(16),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TableCalendar(
|
||||
firstDay: DateTime.utc(2025, 1, 1),
|
||||
lastDay: DateTime.utc(2030, 12, 31),
|
||||
focusedDay: _focusedDay,
|
||||
calendarFormat: _calendarFormat,
|
||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
||||
onDaySelected: (selectedDay, focusedDay) {
|
||||
setState(() {
|
||||
_selectedDay = selectedDay;
|
||||
_focusedDay = focusedDay;
|
||||
});
|
||||
},
|
||||
),
|
||||
calendarStyle: CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
onFormatChanged: (format) {
|
||||
setState(() {
|
||||
_calendarFormat = format;
|
||||
});
|
||||
},
|
||||
eventLoader: _getEventsForDay,
|
||||
calendarBuilders: CalendarBuilders(
|
||||
markerBuilder: (context, day, events) {
|
||||
if (events.isEmpty) return null;
|
||||
|
||||
final visitRecords = events.cast<VisitRecord>();
|
||||
final confirmedCount = visitRecords
|
||||
.where((r) => r.isConfirmed)
|
||||
.length;
|
||||
final unconfirmedCount =
|
||||
visitRecords.length - confirmedCount;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (confirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
if (unconfirmedCount > 0)
|
||||
Container(
|
||||
width: 6,
|
||||
height: 6,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 1),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.orange,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
todayDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.5),
|
||||
shape: BoxShape.circle,
|
||||
calendarStyle: CalendarStyle(
|
||||
outsideDaysVisible: false,
|
||||
selectedDecoration: const BoxDecoration(
|
||||
color: AppColors.lightPrimary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
todayDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.5),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
markersMaxCount: 2,
|
||||
markerDecoration: const BoxDecoration(
|
||||
color: AppColors.lightSecondary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
weekendTextStyle: const TextStyle(
|
||||
color: AppColors.lightError,
|
||||
),
|
||||
),
|
||||
markersMaxCount: 2,
|
||||
markerDecoration: const BoxDecoration(
|
||||
color: AppColors.lightSecondary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
weekendTextStyle: const TextStyle(
|
||||
color: AppColors.lightError,
|
||||
),
|
||||
),
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonVisible: true,
|
||||
titleCentered: true,
|
||||
formatButtonShowsNext: false,
|
||||
formatButtonDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
formatButtonTextStyle: const TextStyle(
|
||||
color: AppColors.lightPrimary,
|
||||
headerStyle: HeaderStyle(
|
||||
formatButtonVisible: true,
|
||||
titleCentered: true,
|
||||
formatButtonShowsNext: false,
|
||||
formatButtonDecoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
formatButtonTextStyle: const TextStyle(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 범례
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildLegend('추천받음', Colors.orange, isDark),
|
||||
const SizedBox(width: 24),
|
||||
_buildLegend('방문완료', Colors.green, isDark),
|
||||
],
|
||||
|
||||
// 범례
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildLegend('추천받음', Colors.orange, isDark),
|
||||
const SizedBox(width: 24),
|
||||
_buildLegend('방문완료', Colors.green, isDark),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 선택된 날짜의 기록
|
||||
Expanded(
|
||||
child: _buildDayRecords(_selectedDay, isDark),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 선택된 날짜의 기록
|
||||
Expanded(child: _buildDayRecords(_selectedDay, isDark)),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildLegend(String label, Color color, bool isDark) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 14,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(label, style: AppTypography.body2(isDark)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildDayRecords(DateTime day, bool isDark) {
|
||||
final events = _getEventsForDay(day);
|
||||
|
||||
|
||||
if (events.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
@@ -244,18 +248,17 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
Icon(
|
||||
Icons.event_available,
|
||||
size: 48,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'이날의 기록이 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
Text('이날의 기록이 없습니다', style: AppTypography.body2(isDark)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
@@ -265,14 +268,16 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
Icon(
|
||||
Icons.calendar_today,
|
||||
size: 20,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${day.month}월 ${day.day}일 방문 기록',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
@@ -289,7 +294,8 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
child: ListView.builder(
|
||||
itemCount: events.length,
|
||||
itemBuilder: (context, index) {
|
||||
final sortedEvents = events..sort((a, b) => b.visitDate.compareTo(a.visitDate));
|
||||
final sortedEvents = events
|
||||
..sort((a, b) => b.visitDate.compareTo(a.visitDate));
|
||||
return VisitRecordCard(
|
||||
visitRecord: sortedEvents[index],
|
||||
onTap: () {
|
||||
@@ -302,4 +308,4 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen> with SingleTick
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,19 +19,13 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return AlertDialog(
|
||||
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.restaurant,
|
||||
size: 48,
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
Icon(Icons.restaurant, size: 48, color: AppColors.lightPrimary),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'다녀왔음? 🍴',
|
||||
@@ -45,9 +39,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
children: [
|
||||
Text(
|
||||
restaurantName,
|
||||
style: AppTypography.heading2(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
style: AppTypography.heading2(
|
||||
isDark,
|
||||
).copyWith(color: AppColors.lightPrimary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -60,7 +54,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: (isDark ? AppColors.darkBackground : AppColors.lightBackground),
|
||||
color: (isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
@@ -69,7 +65,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 16,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
@@ -93,7 +91,9 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
child: Text(
|
||||
'안 갔어요',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -103,15 +103,17 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
// 방문 기록 추가
|
||||
await ref.read(visitNotifierProvider.notifier).addVisitRecord(
|
||||
restaurantId: restaurantId,
|
||||
visitDate: DateTime.now(),
|
||||
isConfirmed: true,
|
||||
);
|
||||
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.addVisitRecord(
|
||||
restaurantId: restaurantId,
|
||||
visitDate: DateTime.now(),
|
||||
isConfirmed: true,
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop(true);
|
||||
|
||||
|
||||
// 성공 메시지 표시
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -164,4 +166,4 @@ class VisitConfirmationDialog extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,7 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
final VisitRecord visitRecord;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const VisitRecordCard({
|
||||
super.key,
|
||||
required this.visitRecord,
|
||||
this.onTap,
|
||||
});
|
||||
const VisitRecordCard({super.key, required this.visitRecord, this.onTap});
|
||||
|
||||
String _formatTime(DateTime dateTime) {
|
||||
final hour = dateTime.hour.toString().padLeft(2, '0');
|
||||
@@ -27,7 +23,7 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: isConfirmed
|
||||
color: isConfirmed
|
||||
? AppColors.lightPrimary.withValues(alpha: 0.1)
|
||||
: Colors.orange.withValues(alpha: 0.1),
|
||||
shape: BoxShape.circle,
|
||||
@@ -43,7 +39,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final restaurantAsync = ref.watch(restaurantProvider(visitRecord.restaurantId));
|
||||
final restaurantAsync = ref.watch(
|
||||
restaurantProvider(visitRecord.restaurantId),
|
||||
);
|
||||
|
||||
return restaurantAsync.when(
|
||||
data: (restaurant) {
|
||||
@@ -73,9 +71,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
children: [
|
||||
Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -85,7 +83,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.category_outlined,
|
||||
size: 14,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
@@ -96,7 +96,9 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.access_time,
|
||||
size: 14,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
@@ -121,15 +123,21 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
PopupMenuButton<String>(
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
color: isDark
|
||||
? AppColors.darkSurface
|
||||
: AppColors.lightSurface,
|
||||
onSelected: (value) async {
|
||||
if (value == 'confirm' && !visitRecord.isConfirmed) {
|
||||
await ref.read(visitNotifierProvider.notifier).confirmVisit(visitRecord.id);
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.confirmVisit(visitRecord.id);
|
||||
} else if (value == 'delete') {
|
||||
// 삭제 확인 다이얼로그 표시
|
||||
final confirmed = await showDialog<bool>(
|
||||
@@ -139,11 +147,13 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
content: const Text('이 방문 기록을 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(true),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.lightError,
|
||||
),
|
||||
@@ -152,9 +162,11 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
if (confirmed == true) {
|
||||
await ref.read(visitNotifierProvider.notifier).deleteVisitRecord(visitRecord.id);
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.deleteVisitRecord(visitRecord.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -164,7 +176,11 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
value: 'confirm',
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.check, color: AppColors.lightPrimary, size: 20),
|
||||
const Icon(
|
||||
Icons.check,
|
||||
color: AppColors.lightPrimary,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('방문 확인', style: AppTypography.body2(isDark)),
|
||||
],
|
||||
@@ -174,11 +190,18 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete_outline, color: AppColors.lightError, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text('삭제', style: AppTypography.body2(isDark).copyWith(
|
||||
Icon(
|
||||
Icons.delete_outline,
|
||||
color: AppColors.lightError,
|
||||
)),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'삭제',
|
||||
style: AppTypography.body2(
|
||||
isDark,
|
||||
).copyWith(color: AppColors.lightError),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -194,12 +217,10 @@ class VisitRecordCard extends ConsumerWidget {
|
||||
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
error: (error, stack) => const SizedBox.shrink(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,24 +8,23 @@ import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
|
||||
class VisitStatistics extends ConsumerWidget {
|
||||
final DateTime selectedMonth;
|
||||
|
||||
const VisitStatistics({
|
||||
super.key,
|
||||
required this.selectedMonth,
|
||||
});
|
||||
const VisitStatistics({super.key, required this.selectedMonth});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
// 월별 통계
|
||||
final monthlyStatsAsync = ref.watch(monthlyVisitStatsProvider((
|
||||
year: selectedMonth.year,
|
||||
month: selectedMonth.month,
|
||||
)));
|
||||
|
||||
final monthlyStatsAsync = ref.watch(
|
||||
monthlyVisitStatsProvider((
|
||||
year: selectedMonth.year,
|
||||
month: selectedMonth.month,
|
||||
)),
|
||||
);
|
||||
|
||||
// 자주 방문한 맛집
|
||||
final frequentRestaurantsAsync = ref.watch(frequentRestaurantsProvider);
|
||||
|
||||
|
||||
// 주간 통계
|
||||
final weeklyStatsAsync = ref.watch(weeklyVisitStatsProvider);
|
||||
|
||||
@@ -36,11 +35,11 @@ class VisitStatistics extends ConsumerWidget {
|
||||
// 이번 달 통계
|
||||
_buildMonthlyStats(monthlyStatsAsync, isDark),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 주간 통계 차트
|
||||
_buildWeeklyChart(weeklyStatsAsync, isDark),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 자주 방문한 맛집 TOP 3
|
||||
_buildFrequentRestaurants(frequentRestaurantsAsync, ref, isDark),
|
||||
],
|
||||
@@ -48,13 +47,14 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMonthlyStats(AsyncValue<Map<String, int>> statsAsync, bool isDark) {
|
||||
Widget _buildMonthlyStats(
|
||||
AsyncValue<Map<String, int>> statsAsync,
|
||||
bool isDark,
|
||||
) {
|
||||
return Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
@@ -67,12 +67,14 @@ class VisitStatistics extends ConsumerWidget {
|
||||
const SizedBox(height: 16),
|
||||
statsAsync.when(
|
||||
data: (stats) {
|
||||
final totalVisits = stats.values.fold(0, (sum, count) => sum + count);
|
||||
final categoryCounts = stats.entries
|
||||
.where((e) => !e.key.contains('/'))
|
||||
.toList()
|
||||
..sort((a, b) => b.value.compareTo(a.value));
|
||||
|
||||
final totalVisits = stats.values.fold(
|
||||
0,
|
||||
(sum, count) => sum + count,
|
||||
);
|
||||
final categoryCounts =
|
||||
stats.entries.where((e) => !e.key.contains('/')).toList()
|
||||
..sort((a, b) => b.value.compareTo(a.value));
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
_buildStatItem(
|
||||
@@ -87,7 +89,8 @@ class VisitStatistics extends ConsumerWidget {
|
||||
_buildStatItem(
|
||||
icon: Icons.favorite,
|
||||
label: '가장 많이 간 카테고리',
|
||||
value: '${categoryCounts.first.key} (${categoryCounts.first.value}회)',
|
||||
value:
|
||||
'${categoryCounts.first.key} (${categoryCounts.first.value}회)',
|
||||
color: AppColors.lightSecondary,
|
||||
isDark: isDark,
|
||||
),
|
||||
@@ -96,10 +99,8 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Text(
|
||||
'통계를 불러올 수 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
error: (error, stack) =>
|
||||
Text('통계를 불러올 수 없습니다', style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -107,35 +108,37 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWeeklyChart(AsyncValue<Map<String, int>> statsAsync, bool isDark) {
|
||||
Widget _buildWeeklyChart(
|
||||
AsyncValue<Map<String, int>> statsAsync,
|
||||
bool isDark,
|
||||
) {
|
||||
return Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'최근 7일 방문 현황',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('최근 7일 방문 현황', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 16),
|
||||
statsAsync.when(
|
||||
data: (stats) {
|
||||
final maxCount = stats.values.isEmpty ? 1 : stats.values.reduce((a, b) => a > b ? a : b);
|
||||
|
||||
final maxCount = stats.values.isEmpty
|
||||
? 1
|
||||
: stats.values.reduce((a, b) => a > b ? a : b);
|
||||
|
||||
return SizedBox(
|
||||
height: 120,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: stats.entries.map((entry) {
|
||||
final height = maxCount == 0 ? 0.0 : (entry.value / maxCount) * 80;
|
||||
|
||||
final height = maxCount == 0
|
||||
? 0.0
|
||||
: (entry.value / maxCount) * 80;
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
@@ -153,10 +156,7 @@ class VisitStatistics extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
entry.key,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
Text(entry.key, style: AppTypography.caption(isDark)),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
@@ -164,10 +164,8 @@ class VisitStatistics extends ConsumerWidget {
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Text(
|
||||
'차트를 불러올 수 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
error: (error, stack) =>
|
||||
Text('차트를 불러올 수 없습니다', style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -183,18 +181,13 @@ class VisitStatistics extends ConsumerWidget {
|
||||
return Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'자주 방문한 맛집 TOP 3',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('자주 방문한 맛집 TOP 3', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 16),
|
||||
frequentAsync.when(
|
||||
data: (frequentList) {
|
||||
@@ -206,78 +199,89 @@ class VisitStatistics extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return Column(
|
||||
children: frequentList.take(3).map((item) {
|
||||
final restaurantAsync = ref.watch(restaurantProvider(item.restaurantId));
|
||||
|
||||
return restaurantAsync.when(
|
||||
data: (restaurant) {
|
||||
if (restaurant == null) return const SizedBox.shrink();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${frequentList.indexOf(item) + 1}',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
children:
|
||||
frequentList.take(3).map((item) {
|
||||
final restaurantAsync = ref.watch(
|
||||
restaurantProvider(item.restaurantId),
|
||||
);
|
||||
|
||||
return restaurantAsync.when(
|
||||
data: (restaurant) {
|
||||
if (restaurant == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary
|
||||
.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'${frequentList.indexOf(item) + 1}',
|
||||
style: AppTypography.body1(isDark)
|
||||
.copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
restaurant.category,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${item.visitCount}회',
|
||||
style: AppTypography.body2(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox(height: 44),
|
||||
error: (error, stack) => const SizedBox.shrink(),
|
||||
);
|
||||
}).toList() as List<Widget>,
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(isDark)
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
restaurant.category,
|
||||
style: AppTypography.caption(
|
||||
isDark,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${item.visitCount}회',
|
||||
style: AppTypography.body2(isDark)
|
||||
.copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox(height: 44),
|
||||
error: (error, stack) => const SizedBox.shrink(),
|
||||
);
|
||||
}).toList()
|
||||
as List<Widget>,
|
||||
);
|
||||
},
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Text(
|
||||
'데이터를 불러올 수 없습니다',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
error: (error, stack) =>
|
||||
Text('데이터를 불러올 수 없습니다', style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -301,26 +305,19 @@ class VisitStatistics extends ConsumerWidget {
|
||||
color: color.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color,
|
||||
size: 20,
|
||||
),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
Text(label, style: AppTypography.caption(isDark)),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -328,4 +325,4 @@ class VisitStatistics extends ConsumerWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import '../settings/settings_screen.dart';
|
||||
|
||||
class MainScreen extends ConsumerStatefulWidget {
|
||||
final int initialTab;
|
||||
|
||||
|
||||
const MainScreen({super.key, this.initialTab = 2});
|
||||
|
||||
@override
|
||||
@@ -21,31 +21,30 @@ class MainScreen extends ConsumerStatefulWidget {
|
||||
|
||||
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,
|
||||
);
|
||||
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: '맛집'),
|
||||
@@ -53,7 +52,7 @@ class _MainScreenState extends ConsumerState<MainScreen> {
|
||||
(icon: Icons.calendar_month, label: '기록'),
|
||||
(icon: Icons.settings, label: '설정'),
|
||||
];
|
||||
|
||||
|
||||
final List<Widget> _screens = [
|
||||
const ShareScreen(),
|
||||
const RestaurantListScreen(),
|
||||
@@ -61,28 +60,31 @@ class _MainScreenState extends ConsumerState<MainScreen> {
|
||||
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,
|
||||
),
|
||||
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(),
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,48 @@
|
||||
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 '../../../domain/entities/weather_info.dart';
|
||||
import '../../providers/ad_provider.dart';
|
||||
import '../../providers/location_provider.dart';
|
||||
import '../../providers/notification_provider.dart';
|
||||
import '../../providers/recommendation_provider.dart';
|
||||
import '../../providers/restaurant_provider.dart';
|
||||
import '../../providers/settings_provider.dart'
|
||||
show notificationDelayMinutesProvider, notificationEnabledProvider;
|
||||
import '../../providers/visit_provider.dart';
|
||||
import '../../providers/weather_provider.dart';
|
||||
import 'widgets/recommendation_result_dialog.dart';
|
||||
|
||||
class RandomSelectionScreen extends ConsumerStatefulWidget {
|
||||
const RandomSelectionScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<RandomSelectionScreen> createState() => _RandomSelectionScreenState();
|
||||
ConsumerState<RandomSelectionScreen> createState() =>
|
||||
_RandomSelectionScreenState();
|
||||
}
|
||||
|
||||
class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
double _distanceValue = 500;
|
||||
final List<String> _selectedCategories = [];
|
||||
|
||||
bool _isProcessingRecommendation = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('오늘 뭐 먹Z?'),
|
||||
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
@@ -58,37 +70,36 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
const SizedBox(height: 12),
|
||||
Consumer(
|
||||
builder: (context, ref, child) {
|
||||
final restaurantsAsync = ref.watch(restaurantListProvider);
|
||||
final restaurantsAsync = ref.watch(
|
||||
restaurantListProvider,
|
||||
);
|
||||
return restaurantsAsync.when(
|
||||
data: (restaurants) => Text(
|
||||
'${restaurants.length}개',
|
||||
style: AppTypography.heading1(isDark).copyWith(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
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,
|
||||
),
|
||||
style: AppTypography.heading1(
|
||||
isDark,
|
||||
).copyWith(color: AppColors.lightPrimary),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Text(
|
||||
'등록된 맛집',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
Text('등록된 맛집', style: AppTypography.body2(isDark)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 날씨 정보 카드
|
||||
Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
@@ -109,7 +120,9 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
Container(
|
||||
width: 1,
|
||||
height: 50,
|
||||
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
||||
color: isDark
|
||||
? AppColors.darkDivider
|
||||
: AppColors.lightDivider,
|
||||
),
|
||||
_buildWeatherData('1시간 후', weather.nextHour, isDark),
|
||||
],
|
||||
@@ -122,13 +135,27 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
error: (_, __) => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildWeatherInfo('지금', Icons.wb_sunny, '맑음', 20, isDark),
|
||||
_buildWeatherInfo(
|
||||
'지금',
|
||||
Icons.wb_sunny,
|
||||
'맑음',
|
||||
20,
|
||||
isDark,
|
||||
),
|
||||
Container(
|
||||
width: 1,
|
||||
height: 50,
|
||||
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
||||
color: isDark
|
||||
? AppColors.darkDivider
|
||||
: AppColors.lightDivider,
|
||||
),
|
||||
_buildWeatherInfo(
|
||||
'1시간 후',
|
||||
Icons.wb_sunny,
|
||||
'맑음',
|
||||
22,
|
||||
isDark,
|
||||
),
|
||||
_buildWeatherInfo('1시간 후', Icons.wb_sunny, '맑음', 22, isDark),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -136,9 +163,9 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 거리 설정 카드
|
||||
Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
@@ -151,10 +178,7 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'최대 거리',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('최대 거리', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
@@ -162,7 +186,8 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
child: SliderTheme(
|
||||
data: SliderTheme.of(context).copyWith(
|
||||
activeTrackColor: AppColors.lightPrimary,
|
||||
inactiveTrackColor: AppColors.lightPrimary.withValues(alpha: 0.3),
|
||||
inactiveTrackColor: AppColors.lightPrimary
|
||||
.withValues(alpha: 0.3),
|
||||
thumbColor: AppColors.lightPrimary,
|
||||
trackHeight: 4,
|
||||
),
|
||||
@@ -180,22 +205,27 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'${_distanceValue.toInt()}m',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
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 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,
|
||||
@@ -208,7 +238,7 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Text(
|
||||
'위치 정보를 가져오는 중...',
|
||||
style: AppTypography.caption(isDark),
|
||||
@@ -219,9 +249,9 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 카테고리 선택 카드
|
||||
Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
@@ -234,22 +264,26 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'카테고리',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
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(),
|
||||
: categories
|
||||
.map(
|
||||
(category) => _buildCategoryChip(
|
||||
category,
|
||||
isDark,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
loading: () => const CircularProgressIndicator(),
|
||||
error: (_, __) => const Text('카테고리를 불러올 수 없습니다'),
|
||||
@@ -260,12 +294,14 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
|
||||
// 추천받기 버튼
|
||||
ElevatedButton(
|
||||
onPressed: _canRecommend() ? _startRecommendation : null,
|
||||
onPressed: !_isProcessingRecommendation && _canRecommend()
|
||||
? () => _startRecommendation()
|
||||
: null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
@@ -275,27 +311,36 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
),
|
||||
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,
|
||||
child: _isProcessingRecommendation
|
||||
? const SizedBox(
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: 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: [
|
||||
@@ -309,47 +354,42 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${weatherData.temperature}°C',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
weatherData.description,
|
||||
style: AppTypography.caption(isDark),
|
||||
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) {
|
||||
|
||||
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,
|
||||
),
|
||||
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),
|
||||
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,
|
||||
@@ -362,18 +402,24 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
}
|
||||
});
|
||||
},
|
||||
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightBackground,
|
||||
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),
|
||||
color: isSelected
|
||||
? AppColors.lightPrimary
|
||||
: (isDark ? AppColors.darkTextPrimary : AppColors.lightTextPrimary),
|
||||
),
|
||||
side: BorderSide(
|
||||
color: isSelected ? AppColors.lightPrimary : (isDark ? AppColors.darkDivider : AppColors.lightDivider),
|
||||
color: isSelected
|
||||
? AppColors.lightPrimary
|
||||
: (isDark ? AppColors.darkDivider : AppColors.lightDivider),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
int _getRestaurantCountInRange(
|
||||
List<Restaurant> restaurants,
|
||||
Position location,
|
||||
@@ -389,62 +435,163 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
||||
return distance <= maxDistance;
|
||||
}).length;
|
||||
}
|
||||
|
||||
|
||||
bool _canRecommend() {
|
||||
final locationAsync = ref.read(currentLocationProvider);
|
||||
final restaurantsAsync = ref.read(restaurantListProvider);
|
||||
|
||||
if (!locationAsync.hasValue || !restaurantsAsync.hasValue) return false;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
if (location == null || restaurants == null || restaurants.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final count = _getRestaurantCountInRange(
|
||||
restaurants,
|
||||
location,
|
||||
_distanceValue,
|
||||
);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
Future<void> _startRecommendation() async {
|
||||
|
||||
Future<void> _startRecommendation({bool skipAd = false}) async {
|
||||
if (_isProcessingRecommendation) return;
|
||||
|
||||
setState(() {
|
||||
_isProcessingRecommendation = true;
|
||||
});
|
||||
|
||||
try {
|
||||
final candidate = await _generateRecommendationCandidate();
|
||||
if (candidate == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!skipAd) {
|
||||
final adService = ref.read(adServiceProvider);
|
||||
// Ad dialog 자체가 비동기 동작을 포함하므로 사용 후 mounted 체크를 수행한다.
|
||||
// ignore: use_build_context_synchronously
|
||||
final adWatched = await adService.showInterstitialAd(context);
|
||||
if (!mounted) return;
|
||||
if (!adWatched) {
|
||||
_showSnack(
|
||||
'광고를 끝까지 시청해야 추천을 받을 수 있어요.',
|
||||
backgroundColor: AppColors.lightError,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
_showRecommendationDialog(candidate);
|
||||
} catch (_) {
|
||||
_showSnack(
|
||||
'추천을 준비하는 중 문제가 발생했습니다.',
|
||||
backgroundColor: AppColors.lightError,
|
||||
);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isProcessingRecommendation = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<Restaurant?> _generateRecommendationCandidate() 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,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
if (result.hasError) {
|
||||
final message = result.error?.toString() ?? '알 수 없는 오류';
|
||||
_showSnack(
|
||||
'추천 중 오류가 발생했습니다: $message',
|
||||
backgroundColor: AppColors.lightError,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
final restaurant = result.asData?.value;
|
||||
if (restaurant == null) {
|
||||
_showSnack('조건에 맞는 식당이 존재하지 않습니다', backgroundColor: AppColors.lightError);
|
||||
}
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
void _showRecommendationDialog(Restaurant restaurant) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) => RecommendationResultDialog(
|
||||
restaurant: restaurant,
|
||||
onReroll: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
await _startRecommendation(skipAd: true);
|
||||
},
|
||||
onClose: () async {
|
||||
Navigator.pop(dialogContext);
|
||||
await _handleRecommendationAccepted(restaurant);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleRecommendationAccepted(Restaurant restaurant) async {
|
||||
final recommendationTime = DateTime.now();
|
||||
|
||||
try {
|
||||
final notificationEnabled = await ref.read(
|
||||
notificationEnabledProvider.future,
|
||||
);
|
||||
if (notificationEnabled) {
|
||||
final delayMinutes = await ref.read(
|
||||
notificationDelayMinutesProvider.future,
|
||||
);
|
||||
} else if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('조건에 맞는 맛집이 없습니다'),
|
||||
backgroundColor: AppColors.lightError,
|
||||
),
|
||||
final notificationService = ref.read(notificationServiceProvider);
|
||||
await notificationService.scheduleVisitReminder(
|
||||
restaurantId: restaurant.id,
|
||||
restaurantName: restaurant.name,
|
||||
recommendationTime: recommendationTime,
|
||||
delayMinutes: delayMinutes,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
await ref
|
||||
.read(visitNotifierProvider.notifier)
|
||||
.createVisitFromRecommendation(
|
||||
restaurantId: restaurant.id,
|
||||
recommendationTime: recommendationTime,
|
||||
);
|
||||
|
||||
_showSnack('맛있게 드세요! 🍴');
|
||||
} catch (_) {
|
||||
_showSnack(
|
||||
'방문 기록 또는 알림 예약에 실패했습니다.',
|
||||
backgroundColor: AppColors.lightError,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnack(
|
||||
String message, {
|
||||
Color backgroundColor = AppColors.lightPrimary,
|
||||
}) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
SnackBar(content: Text(message), backgroundColor: backgroundColor),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
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 {
|
||||
class RecommendationResultDialog extends StatelessWidget {
|
||||
final Restaurant restaurant;
|
||||
final VoidCallback onReroll;
|
||||
final VoidCallback onConfirmVisit;
|
||||
final Future<void> Function() onReroll;
|
||||
final Future<void> Function() onClose;
|
||||
|
||||
const RecommendationResultDialog({
|
||||
super.key,
|
||||
required this.restaurant,
|
||||
required this.onReroll,
|
||||
required this.onConfirmVisit,
|
||||
required this.onClose,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
child: Container(
|
||||
@@ -56,9 +52,9 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'오늘의 추천!',
|
||||
style: AppTypography.heading2(false).copyWith(
|
||||
color: Colors.white,
|
||||
),
|
||||
style: AppTypography.heading2(
|
||||
false,
|
||||
).copyWith(color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -68,13 +64,15 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
right: 8,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
onPressed: () async {
|
||||
await onClose();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
// 맛집 정보
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
@@ -90,24 +88,27 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
|
||||
// 카테고리
|
||||
Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
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,
|
||||
),
|
||||
style: AppTypography.body2(
|
||||
isDark,
|
||||
).copyWith(color: AppColors.lightPrimary),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
if (restaurant.description != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -116,18 +117,20 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
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,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
@@ -138,7 +141,7 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
if (restaurant.phoneNumber != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
@@ -146,7 +149,9 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.phone,
|
||||
size: 20,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
@@ -156,18 +161,22 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
|
||||
// 버튼들
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: onReroll,
|
||||
onPressed: () async {
|
||||
await onReroll();
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
side: const BorderSide(color: AppColors.lightPrimary),
|
||||
side: const BorderSide(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
@@ -182,29 +191,7 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
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();
|
||||
await onClose();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
@@ -214,7 +201,7 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text('여기로 갈게요!'),
|
||||
child: const Text('닫기'),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -227,4 +214,4 @@ class RecommendationResultDialog extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
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 'widgets/add_restaurant_form.dart';
|
||||
|
||||
class ManualRestaurantInputScreen extends ConsumerStatefulWidget {
|
||||
const ManualRestaurantInputScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ManualRestaurantInputScreen> createState() =>
|
||||
_ManualRestaurantInputScreenState();
|
||||
}
|
||||
|
||||
class _ManualRestaurantInputScreenState
|
||||
extends ConsumerState<ManualRestaurantInputScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
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;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nameController = TextEditingController();
|
||||
_categoryController = TextEditingController();
|
||||
_subCategoryController = TextEditingController();
|
||||
_descriptionController = TextEditingController();
|
||||
_phoneController = TextEditingController();
|
||||
_roadAddressController = TextEditingController();
|
||||
_jibunAddressController = TextEditingController();
|
||||
_latitudeController = TextEditingController();
|
||||
_longitudeController = TextEditingController();
|
||||
_naverUrlController = TextEditingController();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ref.read(addRestaurantViewModelProvider.notifier).reset();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_categoryController.dispose();
|
||||
_subCategoryController.dispose();
|
||||
_descriptionController.dispose();
|
||||
_phoneController.dispose();
|
||||
_roadAddressController.dispose();
|
||||
_jibunAddressController.dispose();
|
||||
_latitudeController.dispose();
|
||||
_longitudeController.dispose();
|
||||
_naverUrlController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onFieldChanged(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);
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
if (_formKey.currentState?.validate() != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
|
||||
final success = await viewModel.saveRestaurant();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (success) {
|
||||
Navigator.of(context).pop(true);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: const [
|
||||
Icon(Icons.check_circle, color: Colors.white, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('맛집이 추가되었습니다'),
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final errorMessage =
|
||||
ref.read(addRestaurantViewModelProvider).errorMessage ??
|
||||
'저장에 실패했습니다.';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(errorMessage),
|
||||
backgroundColor: Colors.redAccent,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final state = ref.watch(addRestaurantViewModelProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('직접 입력'),
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('가게 정보를 직접 입력하세요', style: AppTypography.body1(isDark)),
|
||||
const SizedBox(height: 16),
|
||||
AddRestaurantForm(
|
||||
formKey: _formKey,
|
||||
nameController: _nameController,
|
||||
categoryController: _categoryController,
|
||||
subCategoryController: _subCategoryController,
|
||||
descriptionController: _descriptionController,
|
||||
phoneController: _phoneController,
|
||||
roadAddressController: _roadAddressController,
|
||||
jibunAddressController: _jibunAddressController,
|
||||
latitudeController: _latitudeController,
|
||||
longitudeController: _longitudeController,
|
||||
onFieldChanged: _onFieldChanged,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: state.isLoading
|
||||
? null
|
||||
: () => Navigator.of(context).pop(),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton(
|
||||
onPressed: state.isLoading ? null : _save,
|
||||
child: state.isLoading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Text('저장'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import '../../../core/constants/app_colors.dart';
|
||||
import '../../../core/constants/app_typography.dart';
|
||||
import '../../providers/restaurant_provider.dart';
|
||||
import '../../widgets/category_selector.dart';
|
||||
import 'manual_restaurant_input_screen.dart';
|
||||
import 'widgets/restaurant_card.dart';
|
||||
import 'widgets/add_restaurant_dialog.dart';
|
||||
|
||||
@@ -11,34 +12,37 @@ class RestaurantListScreen extends ConsumerStatefulWidget {
|
||||
const RestaurantListScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<RestaurantListScreen> createState() => _RestaurantListScreenState();
|
||||
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
|
||||
searchQuery.isNotEmpty || selectedCategory != null
|
||||
? filteredRestaurantsProvider
|
||||
: restaurantListProvider,
|
||||
);
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
appBar: AppBar(
|
||||
title: _isSearching
|
||||
title: _isSearching
|
||||
? TextField(
|
||||
controller: _searchController,
|
||||
autofocus: true,
|
||||
@@ -53,7 +57,9 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
},
|
||||
)
|
||||
: const Text('내 맛집 리스트'),
|
||||
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
@@ -101,7 +107,7 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
if (restaurants.isEmpty) {
|
||||
return _buildEmptyState(isDark);
|
||||
}
|
||||
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: restaurants.length,
|
||||
itemBuilder: (context, index) {
|
||||
@@ -110,9 +116,7 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
);
|
||||
},
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
child: CircularProgressIndicator(color: AppColors.lightPrimary),
|
||||
),
|
||||
error: (error, stack) => Center(
|
||||
child: Column(
|
||||
@@ -121,13 +125,12 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: isDark ? AppColors.darkError : AppColors.lightError,
|
||||
color: isDark
|
||||
? AppColors.darkError
|
||||
: AppColors.lightError,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'오류가 발생했습니다',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('오류가 발생했습니다', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
error.toString(),
|
||||
@@ -148,12 +151,12 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildEmptyState(bool isDark) {
|
||||
final selectedCategory = ref.watch(selectedCategoryProvider);
|
||||
final searchQuery = ref.watch(searchQueryProvider);
|
||||
final isFiltering = selectedCategory != null || searchQuery.isNotEmpty;
|
||||
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -161,21 +164,21 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
Icon(
|
||||
isFiltering ? Icons.search_off : Icons.restaurant_menu,
|
||||
size: 80,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
isFiltering
|
||||
? '조건에 맞는 맛집이 없어요'
|
||||
: '아직 등록된 맛집이 없어요',
|
||||
isFiltering ? '조건에 맞는 맛집이 없어요' : '아직 등록된 맛집이 없어요',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
isFiltering
|
||||
? selectedCategory != null
|
||||
? '선택한 카테고리에 해당하는 맛집이 없습니다'
|
||||
: '검색 결과가 없습니다'
|
||||
? selectedCategory != null
|
||||
? '선택한 카테고리에 해당하는 맛집이 없습니다'
|
||||
: '검색 결과가 없습니다'
|
||||
: '+ 버튼을 눌러 맛집을 추가해보세요',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
@@ -188,9 +191,7 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
},
|
||||
child: Text(
|
||||
'필터 초기화',
|
||||
style: TextStyle(
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
style: TextStyle(color: AppColors.lightPrimary),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -198,11 +199,110 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _showAddOptions() {
|
||||
showDialog(
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => const AddRestaurantDialog(initialTabIndex: 0),
|
||||
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: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.link, color: AppColors.lightPrimary),
|
||||
),
|
||||
title: const Text('네이버 지도 링크로 추가'),
|
||||
subtitle: const Text('네이버 지도앱에서 공유한 링크 붙여넣기'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_addByNaverLink();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.search,
|
||||
color: AppColors.lightPrimary,
|
||||
),
|
||||
),
|
||||
title: const Text('상호명으로 검색'),
|
||||
subtitle: const Text('가게 이름으로 검색하여 추가'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_addBySearch();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.edit, color: AppColors.lightPrimary),
|
||||
),
|
||||
title: const Text('직접 입력'),
|
||||
subtitle: const Text('가게 정보를 직접 입력하여 추가'),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_addManually();
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _addByNaverLink() {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const AddRestaurantDialog(mode: AddRestaurantDialogMode.naverLink),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _addBySearch() {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const AddRestaurantDialog(mode: AddRestaurantDialogMode.search),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _addManually() async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const ManualRestaurantInputScreen()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,31 +3,28 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../../core/constants/app_colors.dart';
|
||||
import '../../../../core/constants/app_typography.dart';
|
||||
import '../../../../domain/entities/restaurant.dart';
|
||||
import '../../../view_models/add_restaurant_view_model.dart';
|
||||
import 'add_restaurant_form.dart';
|
||||
import 'add_restaurant_search_tab.dart';
|
||||
import 'add_restaurant_url_tab.dart';
|
||||
import 'fetched_restaurant_json_view.dart';
|
||||
|
||||
/// 식당 추가 다이얼로그
|
||||
///
|
||||
/// UI 렌더링만 담당하며, 비즈니스 로직은 ViewModel에 위임합니다.
|
||||
enum AddRestaurantDialogMode { naverLink, search }
|
||||
|
||||
/// 네이버 링크/검색 기반 맛집 추가 다이얼로그
|
||||
class AddRestaurantDialog extends ConsumerStatefulWidget {
|
||||
final int initialTabIndex;
|
||||
|
||||
const AddRestaurantDialog({
|
||||
super.key,
|
||||
this.initialTabIndex = 0,
|
||||
});
|
||||
final AddRestaurantDialogMode mode;
|
||||
|
||||
const AddRestaurantDialog({super.key, required this.mode});
|
||||
|
||||
@override
|
||||
ConsumerState<AddRestaurantDialog> createState() => _AddRestaurantDialogState();
|
||||
ConsumerState<AddRestaurantDialog> createState() =>
|
||||
_AddRestaurantDialogState();
|
||||
}
|
||||
|
||||
class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
with SingleTickerProviderStateMixin {
|
||||
// Form 관련
|
||||
class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
// TextEditingController들
|
||||
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _categoryController;
|
||||
late final TextEditingController _subCategoryController;
|
||||
@@ -38,22 +35,11 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
late final TextEditingController _latitudeController;
|
||||
late final TextEditingController _longitudeController;
|
||||
late final TextEditingController _naverUrlController;
|
||||
|
||||
// UI 상태
|
||||
late TabController _tabController;
|
||||
|
||||
late final TextEditingController _searchQueryController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// TabController 초기화
|
||||
_tabController = TabController(
|
||||
length: 2,
|
||||
vsync: this,
|
||||
initialIndex: widget.initialTabIndex,
|
||||
);
|
||||
|
||||
// TextEditingController 초기화
|
||||
_nameController = TextEditingController();
|
||||
_categoryController = TextEditingController();
|
||||
_subCategoryController = TextEditingController();
|
||||
@@ -64,14 +50,15 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
_latitudeController = TextEditingController();
|
||||
_longitudeController = TextEditingController();
|
||||
_naverUrlController = TextEditingController();
|
||||
_searchQueryController = TextEditingController();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ref.read(addRestaurantViewModelProvider.notifier).reset();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TabController 정리
|
||||
_tabController.dispose();
|
||||
|
||||
// TextEditingController 정리
|
||||
_nameController.dispose();
|
||||
_categoryController.dispose();
|
||||
_subCategoryController.dispose();
|
||||
@@ -82,11 +69,10 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
_latitudeController.dispose();
|
||||
_longitudeController.dispose();
|
||||
_naverUrlController.dispose();
|
||||
|
||||
_searchQueryController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 폼 데이터가 변경될 때 ViewModel 업데이트
|
||||
void _onFormDataChanged(String _) {
|
||||
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
|
||||
final formData = RestaurantFormData.fromControllers(
|
||||
@@ -104,41 +90,30 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 폼 컨트롤러 업데이트
|
||||
Future<void> _performSearch() async {
|
||||
final query = _searchQueryController.text.trim();
|
||||
await ref
|
||||
.read(addRestaurantViewModelProvider.notifier)
|
||||
.searchRestaurants(query);
|
||||
}
|
||||
|
||||
void _selectSearchResult(Restaurant restaurant) {
|
||||
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
|
||||
viewModel.selectSearchResult(restaurant);
|
||||
final state = ref.read(addRestaurantViewModelProvider);
|
||||
_updateFormControllers(state.formData);
|
||||
_naverUrlController.text = restaurant.naverUrl ?? _naverUrlController.text;
|
||||
}
|
||||
|
||||
void _updateFormControllers(RestaurantFormData formData) {
|
||||
_nameController.text = formData.name;
|
||||
_categoryController.text = formData.category;
|
||||
@@ -149,23 +124,30 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
_jibunAddressController.text = formData.jibunAddress;
|
||||
_latitudeController.text = formData.latitude;
|
||||
_longitudeController.text = formData.longitude;
|
||||
_naverUrlController.text = formData.naverUrl;
|
||||
}
|
||||
|
||||
/// 식당 저장
|
||||
Future<void> _saveRestaurant() async {
|
||||
final state = ref.read(addRestaurantViewModelProvider);
|
||||
if (state.fetchedRestaurantData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_formKey.currentState?.validate() != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
final viewModel = ref.read(addRestaurantViewModelProvider.notifier);
|
||||
final success = await viewModel.saveRestaurant();
|
||||
|
||||
if (success && mounted) {
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (success) {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
children: const [
|
||||
Icon(Icons.check_circle, color: Colors.white, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('맛집이 추가되었습니다'),
|
||||
@@ -174,6 +156,25 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final errorMessage =
|
||||
ref.read(addRestaurantViewModelProvider).errorMessage ??
|
||||
'맛집 저장에 실패했습니다.';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(errorMessage),
|
||||
backgroundColor: Colors.redAccent,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String get _title {
|
||||
switch (widget.mode) {
|
||||
case AddRestaurantDialogMode.naverLink:
|
||||
return '네이버 지도 링크로 추가';
|
||||
case AddRestaurantDialogMode.search:
|
||||
return '상호명으로 검색';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,150 +182,96 @@ class _AddRestaurantDialogState extends ConsumerState<AddRestaurantDialog>
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 420),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
_title,
|
||||
style: AppTypography.heading1(isDark),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
// 버튼
|
||||
_buildButtons(isDark, state),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
if (widget.mode == AddRestaurantDialogMode.naverLink)
|
||||
AddRestaurantUrlTab(
|
||||
urlController: _naverUrlController,
|
||||
isLoading: state.isLoading,
|
||||
errorMessage: state.errorMessage,
|
||||
onFetchPressed: _fetchFromNaverUrl,
|
||||
)
|
||||
else
|
||||
AddRestaurantSearchTab(
|
||||
queryController: _searchQueryController,
|
||||
isSearching: state.isSearching,
|
||||
results: state.searchResults,
|
||||
selectedRestaurant: state.fetchedRestaurantData,
|
||||
onResultSelected: _selectSearchResult,
|
||||
onSearch: _performSearch,
|
||||
errorMessage: state.errorMessage,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (state.fetchedRestaurantData != null) ...[
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: FetchedRestaurantJsonView(
|
||||
isDark: isDark,
|
||||
nameController: _nameController,
|
||||
categoryController: _categoryController,
|
||||
subCategoryController: _subCategoryController,
|
||||
descriptionController: _descriptionController,
|
||||
phoneController: _phoneController,
|
||||
roadAddressController: _roadAddressController,
|
||||
jibunAddressController: _jibunAddressController,
|
||||
latitudeController: _latitudeController,
|
||||
longitudeController: _longitudeController,
|
||||
naverUrlController: _naverUrlController,
|
||||
onFieldChanged: _onFormDataChanged,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: state.isLoading
|
||||
? null
|
||||
: () => Navigator.of(context).pop(),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton(
|
||||
onPressed:
|
||||
state.isLoading || state.fetchedRestaurantData == null
|
||||
? null
|
||||
: _saveRestaurant,
|
||||
child: state.isLoading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Text('저장'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 헤더 빌드
|
||||
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 ? '가져오기' : '저장',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 카테고리
|
||||
Row(
|
||||
children: [
|
||||
@@ -73,7 +73,8 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
onChanged: onFieldChanged,
|
||||
validator: (value) => RestaurantFormValidator.validateCategory(value),
|
||||
validator: (value) =>
|
||||
RestaurantFormValidator.validateCategory(value),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
@@ -93,7 +94,7 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 설명
|
||||
TextFormField(
|
||||
controller: descriptionController,
|
||||
@@ -109,7 +110,7 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
onChanged: onFieldChanged,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 전화번호
|
||||
TextFormField(
|
||||
controller: phoneController,
|
||||
@@ -123,10 +124,11 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
onChanged: onFieldChanged,
|
||||
validator: (value) => RestaurantFormValidator.validatePhoneNumber(value),
|
||||
validator: (value) =>
|
||||
RestaurantFormValidator.validatePhoneNumber(value),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 도로명 주소
|
||||
TextFormField(
|
||||
controller: roadAddressController,
|
||||
@@ -139,10 +141,11 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
onChanged: onFieldChanged,
|
||||
validator: (value) => RestaurantFormValidator.validateAddress(value),
|
||||
validator: (value) =>
|
||||
RestaurantFormValidator.validateAddress(value),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 지번 주소
|
||||
TextFormField(
|
||||
controller: jibunAddressController,
|
||||
@@ -157,14 +160,16 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
onChanged: onFieldChanged,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 위도/경도 입력
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: latitudeController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: '위도',
|
||||
hintText: '37.5665',
|
||||
@@ -189,7 +194,9 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: longitudeController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: '경도',
|
||||
hintText: '126.9780',
|
||||
@@ -202,7 +209,9 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
validator: (value) {
|
||||
if (value != null && value.isNotEmpty) {
|
||||
final longitude = double.tryParse(value);
|
||||
if (longitude == null || longitude < -180 || longitude > 180) {
|
||||
if (longitude == null ||
|
||||
longitude < -180 ||
|
||||
longitude > 180) {
|
||||
return '올바른 경도값을 입력해주세요';
|
||||
}
|
||||
}
|
||||
@@ -215,13 +224,13 @@ class AddRestaurantForm extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'* 위도/경도를 입력하지 않으면 서울시청 기준으로 저장됩니다',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodySmall?.copyWith(color: Colors.grey),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/constants/app_colors.dart';
|
||||
import '../../../../core/constants/app_typography.dart';
|
||||
import '../../../../domain/entities/restaurant.dart';
|
||||
|
||||
class AddRestaurantSearchTab extends StatelessWidget {
|
||||
final TextEditingController queryController;
|
||||
final bool isSearching;
|
||||
final List<Restaurant> results;
|
||||
final Restaurant? selectedRestaurant;
|
||||
final VoidCallback onSearch;
|
||||
final ValueChanged<Restaurant> onResultSelected;
|
||||
final String? errorMessage;
|
||||
|
||||
const AddRestaurantSearchTab({
|
||||
super.key,
|
||||
required this.queryController,
|
||||
required this.isSearching,
|
||||
required this.results,
|
||||
required this.selectedRestaurant,
|
||||
required this.onSearch,
|
||||
required this.onResultSelected,
|
||||
this.errorMessage,
|
||||
});
|
||||
|
||||
@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.search,
|
||||
color: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'상호명으로 검색',
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'가게 이름(필요 시 주소 키워드 포함)을 입력하면 네이버 로컬 검색 API로 결과를 불러옵니다.',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: queryController,
|
||||
decoration: InputDecoration(
|
||||
labelText: '상호명',
|
||||
prefixIcon: const Icon(Icons.storefront),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
textInputAction: TextInputAction.search,
|
||||
onSubmitted: (_) => onSearch(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ElevatedButton.icon(
|
||||
onPressed: isSearching ? null : onSearch,
|
||||
icon: isSearching
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.search),
|
||||
label: Text(isSearching ? '검색 중...' : '검색'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
),
|
||||
),
|
||||
if (errorMessage != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
errorMessage!,
|
||||
style: TextStyle(color: Colors.red[400], fontSize: 13),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
if (results.isNotEmpty)
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
||||
),
|
||||
),
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: results.length,
|
||||
separatorBuilder: (_, __) => Divider(
|
||||
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
||||
height: 1,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final restaurant = results[index];
|
||||
final isSelected = selectedRestaurant?.id == restaurant.id;
|
||||
return ListTile(
|
||||
onTap: () => onResultSelected(restaurant),
|
||||
selected: isSelected,
|
||||
selectedTileColor: isDark
|
||||
? AppColors.darkPrimary.withOpacity(0.08)
|
||||
: AppColors.lightPrimary.withOpacity(0.08),
|
||||
title: Text(
|
||||
restaurant.name,
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (restaurant.roadAddress.isNotEmpty)
|
||||
Text(
|
||||
restaurant.roadAddress,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
Text(
|
||||
restaurant.category,
|
||||
style: AppTypography.caption(isDark).copyWith(
|
||||
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: isSelected
|
||||
? const Icon(
|
||||
Icons.check_circle,
|
||||
color: AppColors.lightPrimary,
|
||||
)
|
||||
: const Icon(Icons.chevron_right),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
else
|
||||
Text(
|
||||
'검색 결과가 여기에 표시됩니다.',
|
||||
style: AppTypography.caption(
|
||||
isDark,
|
||||
).copyWith(color: isDark ? Colors.grey[400] : Colors.grey[600]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
@@ -29,8 +29,8 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark
|
||||
? AppColors.darkPrimary.withOpacity(0.1)
|
||||
color: isDark
|
||||
? AppColors.darkPrimary.withOpacity(0.1)
|
||||
: AppColors.lightPrimary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
@@ -42,14 +42,16 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 20,
|
||||
color: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
color: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'네이버 지도에서 맛집 정보 가져오기',
|
||||
style: AppTypography.body1(isDark).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -63,32 +65,30 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// URL 입력 필드
|
||||
TextField(
|
||||
controller: urlController,
|
||||
decoration: InputDecoration(
|
||||
labelText: '네이버 지도 URL',
|
||||
hintText: kIsWeb
|
||||
? 'https://map.naver.com/...'
|
||||
hintText: kIsWeb
|
||||
? 'https://map.naver.com/...'
|
||||
: 'https://naver.me/...',
|
||||
prefixIcon: const Icon(Icons.link),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
errorText: errorMessage,
|
||||
),
|
||||
onSubmitted: (_) => onFetchPressed(),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 가져오기 버튼
|
||||
ElevatedButton.icon(
|
||||
onPressed: isLoading ? null : onFetchPressed,
|
||||
icon: isLoading
|
||||
icon: isLoading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
@@ -103,9 +103,9 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 웹 환경 경고
|
||||
if (kIsWeb) ...[
|
||||
Container(
|
||||
@@ -117,15 +117,18 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning_amber_rounded,
|
||||
color: Colors.orange, size: 20),
|
||||
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],
|
||||
),
|
||||
style: AppTypography.caption(
|
||||
isDark,
|
||||
).copyWith(color: Colors.orange[700]),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -135,4 +138,4 @@ class AddRestaurantUrlTab extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/constants/app_colors.dart';
|
||||
import '../../../../core/constants/app_typography.dart';
|
||||
import '../../../services/restaurant_form_validator.dart';
|
||||
|
||||
class FetchedRestaurantJsonView extends StatelessWidget {
|
||||
final bool isDark;
|
||||
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 TextEditingController naverUrlController;
|
||||
final ValueChanged<String> onFieldChanged;
|
||||
|
||||
const FetchedRestaurantJsonView({
|
||||
super.key,
|
||||
required this.isDark,
|
||||
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.naverUrlController,
|
||||
required this.onFieldChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return 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: [
|
||||
const Icon(Icons.code, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'가져온 정보',
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'{',
|
||||
style: TextStyle(fontFamily: 'RobotoMono', fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'name',
|
||||
controller: nameController,
|
||||
icon: Icons.store,
|
||||
validator: (value) =>
|
||||
value == null || value.isEmpty ? '가게 이름을 입력해주세요' : null,
|
||||
),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'category',
|
||||
controller: categoryController,
|
||||
icon: Icons.category,
|
||||
validator: RestaurantFormValidator.validateCategory,
|
||||
),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'subCategory',
|
||||
controller: subCategoryController,
|
||||
icon: Icons.label_outline,
|
||||
),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'description',
|
||||
controller: descriptionController,
|
||||
icon: Icons.description,
|
||||
maxLines: 2,
|
||||
),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'phoneNumber',
|
||||
controller: phoneController,
|
||||
icon: Icons.phone,
|
||||
keyboardType: TextInputType.phone,
|
||||
validator: RestaurantFormValidator.validatePhoneNumber,
|
||||
),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'roadAddress',
|
||||
controller: roadAddressController,
|
||||
icon: Icons.location_on,
|
||||
validator: RestaurantFormValidator.validateAddress,
|
||||
),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'jibunAddress',
|
||||
controller: jibunAddressController,
|
||||
icon: Icons.map,
|
||||
),
|
||||
_buildCoordinateFields(context),
|
||||
_buildJsonField(
|
||||
context,
|
||||
label: 'naverUrl',
|
||||
controller: naverUrlController,
|
||||
icon: Icons.link,
|
||||
monospace: true,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'}',
|
||||
style: TextStyle(fontFamily: 'RobotoMono', fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCoordinateFields(BuildContext context) {
|
||||
final border = OutlineInputBorder(borderRadius: BorderRadius.circular(8));
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: const [
|
||||
Icon(Icons.my_location, size: 16),
|
||||
SizedBox(width: 8),
|
||||
Text('coordinates'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: latitudeController,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'latitude',
|
||||
border: border,
|
||||
isDense: true,
|
||||
),
|
||||
onChanged: onFieldChanged,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '위도를 입력해주세요';
|
||||
}
|
||||
final latitude = double.tryParse(value);
|
||||
if (latitude == null || latitude < -90 || latitude > 90) {
|
||||
return '올바른 위도값을 입력해주세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: longitudeController,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'longitude',
|
||||
border: border,
|
||||
isDense: true,
|
||||
),
|
||||
onChanged: onFieldChanged,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '경도를 입력해주세요';
|
||||
}
|
||||
final longitude = double.tryParse(value);
|
||||
if (longitude == null ||
|
||||
longitude < -180 ||
|
||||
longitude > 180) {
|
||||
return '올바른 경도값을 입력해주세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildJsonField(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required TextEditingController controller,
|
||||
required IconData icon,
|
||||
int maxLines = 1,
|
||||
TextInputType? keyboardType,
|
||||
bool monospace = false,
|
||||
String? Function(String?)? validator,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 16),
|
||||
const SizedBox(width: 8),
|
||||
Text('$label:'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
TextFormField(
|
||||
controller: controller,
|
||||
maxLines: maxLines,
|
||||
keyboardType: keyboardType,
|
||||
onChanged: onFieldChanged,
|
||||
validator: validator,
|
||||
style: monospace
|
||||
? const TextStyle(fontFamily: 'RobotoMono', fontSize: 13)
|
||||
: null,
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,13 @@ import 'package:lunchpick/presentation/providers/visit_provider.dart';
|
||||
class RestaurantCard extends ConsumerWidget {
|
||||
final Restaurant restaurant;
|
||||
|
||||
const RestaurantCard({
|
||||
super.key,
|
||||
required this.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(
|
||||
@@ -46,7 +43,7 @@ class RestaurantCard extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
|
||||
// 가게 정보
|
||||
Expanded(
|
||||
child: Column(
|
||||
@@ -64,11 +61,9 @@ class RestaurantCard extends ConsumerWidget {
|
||||
restaurant.category,
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
if (restaurant.subCategory != restaurant.category) ...[
|
||||
Text(
|
||||
' • ',
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
if (restaurant.subCategory !=
|
||||
restaurant.category) ...[
|
||||
Text(' • ', style: AppTypography.body2(isDark)),
|
||||
Text(
|
||||
restaurant.subCategory,
|
||||
style: AppTypography.body2(isDark),
|
||||
@@ -79,18 +74,20 @@ class RestaurantCard extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
// 더보기 버튼
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
onPressed: () => _showOptions(context, ref, isDark),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
if (restaurant.description != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
@@ -100,16 +97,18 @@ class RestaurantCard extends ConsumerWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
|
||||
// 주소
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.location_on,
|
||||
size: 16,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
@@ -121,12 +120,14 @@ class RestaurantCard extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
// 마지막 방문일
|
||||
lastVisitAsync.when(
|
||||
data: (lastVisit) {
|
||||
if (lastVisit != null) {
|
||||
final daysSinceVisit = DateTime.now().difference(lastVisit).inDays;
|
||||
final daysSinceVisit = DateTime.now()
|
||||
.difference(lastVisit)
|
||||
.inDays;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Row(
|
||||
@@ -134,12 +135,14 @@ class RestaurantCard extends ConsumerWidget {
|
||||
Icon(
|
||||
Icons.schedule,
|
||||
size: 16,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
daysSinceVisit == 0
|
||||
? '오늘 방문'
|
||||
daysSinceVisit == 0
|
||||
? '오늘 방문'
|
||||
: '$daysSinceVisit일 전 방문',
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
@@ -186,13 +189,19 @@ class RestaurantCard extends ConsumerWidget {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
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),
|
||||
_buildDetailRow(
|
||||
'카테고리',
|
||||
'${restaurant.category} > ${restaurant.subCategory}',
|
||||
isDark,
|
||||
),
|
||||
if (restaurant.description != null)
|
||||
_buildDetailRow('설명', restaurant.description!, isDark),
|
||||
if (restaurant.phoneNumber != null)
|
||||
@@ -223,15 +232,9 @@ class RestaurantCard extends ConsumerWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
Text(label, style: AppTypography.caption(isDark)),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.body2(isDark),
|
||||
),
|
||||
Text(value, style: AppTypography.body2(isDark)),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -254,7 +257,9 @@ class RestaurantCard extends ConsumerWidget {
|
||||
height: 4,
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
||||
color: isDark
|
||||
? AppColors.darkDivider
|
||||
: AppColors.lightDivider,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
@@ -283,14 +288,19 @@ class RestaurantCard extends ConsumerWidget {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('삭제', style: TextStyle(color: AppColors.lightError)),
|
||||
child: const Text(
|
||||
'삭제',
|
||||
style: TextStyle(color: AppColors.lightError),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
if (confirmed == true) {
|
||||
await ref.read(restaurantNotifierProvider.notifier).deleteRestaurant(restaurant.id);
|
||||
await ref
|
||||
.read(restaurantNotifierProvider.notifier)
|
||||
.deleteRestaurant(restaurant.id);
|
||||
}
|
||||
},
|
||||
),
|
||||
@@ -301,4 +311,4 @@ class RestaurantCard extends ConsumerWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,22 @@ 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);
|
||||
|
||||
final notificationMinutes = await ref.read(
|
||||
notificationDelayMinutesProvider.future,
|
||||
);
|
||||
final notificationEnabled = await ref.read(
|
||||
notificationEnabledProvider.future,
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_daysToExclude = daysToExclude;
|
||||
@@ -38,297 +42,309 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('설정'),
|
||||
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildSection('추천 설정', [
|
||||
Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
],
|
||||
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(
|
||||
child: ListTile(
|
||||
title: const Text('중복 방문 제외 기간'),
|
||||
subtitle: Text('$_daysToExclude일 이내 방문한 곳은 추천에서 제외'),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const ListTile(
|
||||
leading: Icon(Icons.info_outline, color: AppColors.lightPrimary),
|
||||
title: Text('버전'),
|
||||
subtitle: Text('1.0.0'),
|
||||
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,
|
||||
),
|
||||
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',
|
||||
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,
|
||||
),
|
||||
|
||||
),
|
||||
], 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,
|
||||
@@ -347,7 +363,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildPermissionTile({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
@@ -359,14 +375,12 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
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
|
||||
trailing: isGranted
|
||||
? const Icon(Icons.check_circle, color: Colors.green)
|
||||
: ElevatedButton(
|
||||
onPressed: onRequest,
|
||||
@@ -383,7 +397,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Future<void> _requestLocationPermission() async {
|
||||
final status = await Permission.location.request();
|
||||
if (status.isGranted) {
|
||||
@@ -392,7 +406,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
_showPermissionDialog('위치');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> _requestBluetoothPermission() async {
|
||||
final status = await Permission.bluetooth.request();
|
||||
if (status.isGranted) {
|
||||
@@ -401,7 +415,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
_showPermissionDialog('블루투스');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> _requestNotificationPermission() async {
|
||||
final status = await Permission.notification.request();
|
||||
if (status.isGranted) {
|
||||
@@ -410,14 +424,16 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
_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,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkSurface
|
||||
: AppColors.lightSurface,
|
||||
title: const Text('권한 설정 필요'),
|
||||
content: Text('$permissionName 권한이 거부되었습니다. 설정에서 직접 권한을 허용해주세요.'),
|
||||
actions: [
|
||||
@@ -439,4 +455,4 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
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 'package:lunchpick/core/constants/app_colors.dart';
|
||||
import 'package:lunchpick/core/constants/app_typography.dart';
|
||||
import 'package:lunchpick/core/services/permission_service.dart';
|
||||
import 'package:lunchpick/domain/entities/restaurant.dart';
|
||||
import 'package:lunchpick/domain/entities/share_device.dart';
|
||||
import 'package:lunchpick/presentation/providers/ad_provider.dart';
|
||||
import 'package:lunchpick/presentation/providers/bluetooth_provider.dart';
|
||||
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ShareScreen extends ConsumerStatefulWidget {
|
||||
const ShareScreen({super.key});
|
||||
@@ -13,16 +24,39 @@ class ShareScreen extends ConsumerStatefulWidget {
|
||||
class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
String? _shareCode;
|
||||
bool _isScanning = false;
|
||||
|
||||
List<ShareDevice>? _nearbyDevices;
|
||||
StreamSubscription<String>? _dataSubscription;
|
||||
final _uuid = const Uuid();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final bluetoothService = ref.read(bluetoothServiceProvider);
|
||||
_dataSubscription = bluetoothService.onDataReceived.listen((payload) {
|
||||
_handleIncomingData(payload);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_dataSubscription?.cancel();
|
||||
ref.read(bluetoothServiceProvider).stopListening();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: isDark ? AppColors.darkBackground : AppColors.lightBackground,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
appBar: AppBar(
|
||||
title: const Text('리스트 공유'),
|
||||
backgroundColor: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
@@ -54,10 +88,7 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'리스트 공유받기',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('리스트 공유받기', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'다른 사람의 맛집 리스트를 받아보세요',
|
||||
@@ -67,7 +98,10 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
const SizedBox(height: 20),
|
||||
if (_shareCode != null) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 16,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.lightPrimary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -97,6 +131,7 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
setState(() {
|
||||
_shareCode = null;
|
||||
});
|
||||
ref.read(bluetoothServiceProvider).stopListening();
|
||||
},
|
||||
icon: const Icon(Icons.close),
|
||||
label: const Text('취소'),
|
||||
@@ -106,13 +141,18 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
),
|
||||
] else
|
||||
ElevatedButton.icon(
|
||||
onPressed: _generateShareCode,
|
||||
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),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
@@ -122,9 +162,9 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
|
||||
// 공유하기 섹션
|
||||
Card(
|
||||
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||
@@ -149,10 +189,7 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'내 리스트 공유하기',
|
||||
style: AppTypography.heading2(isDark),
|
||||
),
|
||||
Text('내 리스트 공유하기', style: AppTypography.heading2(isDark)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'내 맛집 리스트를 다른 사람과 공유하세요',
|
||||
@@ -160,20 +197,61 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (_isScanning) ...[
|
||||
const CircularProgressIndicator(
|
||||
color: AppColors.lightSecondary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'주변 기기를 검색 중...',
|
||||
style: AppTypography.caption(isDark),
|
||||
if (_isScanning && _nearbyDevices != null) ...[
|
||||
Container(
|
||||
constraints: const BoxConstraints(maxHeight: 220),
|
||||
child: _nearbyDevices!.isEmpty
|
||||
? Column(
|
||||
children: [
|
||||
const CircularProgressIndicator(
|
||||
color: AppColors.lightSecondary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'주변 기기를 검색 중...',
|
||||
style: AppTypography.caption(isDark),
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: _nearbyDevices!.length,
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (context, index) {
|
||||
final device = _nearbyDevices![index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
leading: const Icon(
|
||||
Icons.phone_android,
|
||||
color: AppColors.lightSecondary,
|
||||
),
|
||||
title: Text(
|
||||
device.code,
|
||||
style: AppTypography.body1(
|
||||
isDark,
|
||||
).copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(
|
||||
'기기 ID: ${device.deviceId}',
|
||||
),
|
||||
trailing: const Icon(
|
||||
Icons.send,
|
||||
color: AppColors.lightSecondary,
|
||||
),
|
||||
onTap: () {
|
||||
_sendList(device.code);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isScanning = false;
|
||||
_nearbyDevices = null;
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.stop),
|
||||
@@ -185,16 +263,17 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
] else
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isScanning = true;
|
||||
});
|
||||
_scanDevices();
|
||||
},
|
||||
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),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
@@ -209,11 +288,218 @@ class _ShareScreenState extends ConsumerState<ShareScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _generateShareCode() {
|
||||
// TODO: 실제 구현 시 랜덤 코드 생성
|
||||
|
||||
Future<void> _generateShareCode() async {
|
||||
final adService = ref.read(adServiceProvider);
|
||||
final adWatched = await adService.showInterstitialAd(context);
|
||||
if (!mounted) return;
|
||||
if (!adWatched) {
|
||||
_showErrorSnackBar('광고를 끝까지 시청해야 공유 코드를 생성할 수 있어요.');
|
||||
return;
|
||||
}
|
||||
|
||||
final random = Random();
|
||||
final code = List.generate(6, (_) => random.nextInt(10)).join();
|
||||
|
||||
setState(() {
|
||||
_shareCode = '123456';
|
||||
_shareCode = code;
|
||||
});
|
||||
|
||||
await ref.read(bluetoothServiceProvider).startListening(code);
|
||||
_showSuccessSnackBar('공유 코드가 생성되었습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _scanDevices() async {
|
||||
final hasPermission =
|
||||
await PermissionService.checkAndRequestBluetoothPermission();
|
||||
if (!hasPermission) {
|
||||
if (!mounted) return;
|
||||
_showErrorSnackBar('블루투스 권한이 필요합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isScanning = true;
|
||||
_nearbyDevices = [];
|
||||
});
|
||||
|
||||
try {
|
||||
final devices = await ref
|
||||
.read(bluetoothServiceProvider)
|
||||
.scanNearbyDevices();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_nearbyDevices = devices;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_isScanning = false;
|
||||
});
|
||||
_showErrorSnackBar('스캔 중 오류가 발생했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendList(String targetCode) async {
|
||||
final restaurants = await ref.read(restaurantListProvider.future);
|
||||
if (!mounted) return;
|
||||
|
||||
_showLoadingDialog('리스트 전송 중...');
|
||||
try {
|
||||
await ref
|
||||
.read(bluetoothServiceProvider)
|
||||
.sendRestaurantList(targetCode, restaurants);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
_showSuccessSnackBar('리스트 전송 완료!');
|
||||
setState(() {
|
||||
_isScanning = false;
|
||||
_nearbyDevices = null;
|
||||
});
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
_showErrorSnackBar('전송 실패: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleIncomingData(String payload) async {
|
||||
if (!mounted) return;
|
||||
final adWatched = await ref
|
||||
.read(adServiceProvider)
|
||||
.showInterstitialAd(context);
|
||||
if (!mounted) return;
|
||||
if (!adWatched) {
|
||||
_showErrorSnackBar('광고를 시청해야 리스트를 받을 수 있어요.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final restaurants = _parseReceivedData(payload);
|
||||
await _mergeRestaurantList(restaurants);
|
||||
} catch (_) {
|
||||
_showErrorSnackBar('전송된 데이터를 처리하는 데 실패했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
List<Restaurant> _parseReceivedData(String data) {
|
||||
final jsonList = jsonDecode(data) as List<dynamic>;
|
||||
return jsonList
|
||||
.map((item) => _restaurantFromJson(item as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Restaurant _restaurantFromJson(Map<String, dynamic> json) {
|
||||
return Restaurant(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
category: json['category'] as String,
|
||||
subCategory: json['subCategory'] as String,
|
||||
description: json['description'] as String?,
|
||||
phoneNumber: json['phoneNumber'] as String?,
|
||||
roadAddress: json['roadAddress'] as String,
|
||||
jibunAddress: json['jibunAddress'] as String,
|
||||
latitude: (json['latitude'] as num).toDouble(),
|
||||
longitude: (json['longitude'] as num).toDouble(),
|
||||
lastVisitDate: json['lastVisitDate'] != null
|
||||
? DateTime.parse(json['lastVisitDate'] as String)
|
||||
: null,
|
||||
source: DataSource.values.firstWhere(
|
||||
(source) =>
|
||||
source.name ==
|
||||
(json['source'] as String? ?? DataSource.USER_INPUT.name),
|
||||
orElse: () => DataSource.USER_INPUT,
|
||||
),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
updatedAt: DateTime.parse(json['updatedAt'] as String),
|
||||
naverPlaceId: json['naverPlaceId'] as String?,
|
||||
naverUrl: json['naverUrl'] as String?,
|
||||
businessHours: json['businessHours'] as String?,
|
||||
lastVisited: json['lastVisited'] != null
|
||||
? DateTime.parse(json['lastVisited'] as String)
|
||||
: null,
|
||||
visitCount: (json['visitCount'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _mergeRestaurantList(List<Restaurant> receivedList) async {
|
||||
final currentList = await ref.read(restaurantListProvider.future);
|
||||
final notifier = ref.read(restaurantNotifierProvider.notifier);
|
||||
|
||||
final newRestaurants = <Restaurant>[];
|
||||
for (final restaurant in receivedList) {
|
||||
final exists = currentList.any(
|
||||
(existing) =>
|
||||
existing.name == restaurant.name &&
|
||||
existing.roadAddress == restaurant.roadAddress,
|
||||
);
|
||||
if (!exists) {
|
||||
newRestaurants.add(
|
||||
restaurant.copyWith(
|
||||
id: _uuid.v4(),
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
source: DataSource.USER_INPUT,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (final restaurant in newRestaurants) {
|
||||
await notifier.addRestaurantDirect(restaurant);
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
if (newRestaurants.isEmpty) {
|
||||
_showSuccessSnackBar('이미 등록된 맛집과 동일한 항목만 전송되었습니다.');
|
||||
} else {
|
||||
_showSuccessSnackBar('${newRestaurants.length}개의 새로운 맛집이 추가되었습니다!');
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_shareCode = null;
|
||||
});
|
||||
ref.read(bluetoothServiceProvider).stopListening();
|
||||
}
|
||||
|
||||
void _showLoadingDialog(String message) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => Dialog(
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkSurface
|
||||
: AppColors.lightSurface,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(color: AppColors.lightPrimary),
|
||||
const SizedBox(width: 20),
|
||||
Flexible(
|
||||
child: Text(message, style: AppTypography.body2(isDark)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showSuccessSnackBar(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message), backgroundColor: AppColors.lightPrimary),
|
||||
);
|
||||
}
|
||||
|
||||
void _showErrorSnackBar(String message) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message), backgroundColor: AppColors.lightError),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,12 @@ class SplashScreen extends StatefulWidget {
|
||||
State<SplashScreen> createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMixin {
|
||||
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,
|
||||
@@ -28,14 +29,14 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
Icons.icecream,
|
||||
Icons.bakery_dining,
|
||||
];
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeAnimations();
|
||||
_navigateToHome();
|
||||
}
|
||||
|
||||
|
||||
void _initializeAnimations() {
|
||||
// 음식 아이콘 애니메이션 (여러 개)
|
||||
_foodControllers = List.generate(
|
||||
@@ -45,31 +46,33 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
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,
|
||||
backgroundColor: isDark
|
||||
? AppColors.darkBackground
|
||||
: AppColors.lightBackground,
|
||||
body: Stack(
|
||||
children: [
|
||||
// 랜덤 위치 음식 아이콘들
|
||||
..._buildFoodIcons(),
|
||||
|
||||
|
||||
// 중앙 컨텐츠
|
||||
Center(
|
||||
child: Column(
|
||||
@@ -86,23 +89,25 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
child: Icon(
|
||||
Icons.restaurant_menu,
|
||||
size: 80,
|
||||
color: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
color: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
|
||||
// 앱 타이틀
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'오늘 뭐 먹Z',
|
||||
style: AppTypography.heading1(isDark),
|
||||
),
|
||||
Text('오늘 뭐 먹Z', style: AppTypography.heading1(isDark)),
|
||||
AnimatedBuilder(
|
||||
animation: _questionMarkController,
|
||||
builder: (context, child) {
|
||||
final questionMarks = '?' * (((_questionMarkController.value * 3).floor() % 3) + 1);
|
||||
final questionMarks =
|
||||
'?' *
|
||||
(((_questionMarkController.value * 3).floor() % 3) +
|
||||
1);
|
||||
return Text(
|
||||
questionMarks,
|
||||
style: AppTypography.heading1(isDark),
|
||||
@@ -114,7 +119,7 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
// 하단 카피라이트
|
||||
Positioned(
|
||||
bottom: 30,
|
||||
@@ -123,8 +128,11 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
child: Text(
|
||||
AppConstants.appCopyright,
|
||||
style: AppTypography.caption(isDark).copyWith(
|
||||
color: (isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary)
|
||||
.withOpacity(0.5),
|
||||
color:
|
||||
(isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary)
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
@@ -133,14 +141,14 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
@@ -168,7 +176,7 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void _navigateToHome() {
|
||||
Future.delayed(AppConstants.splashAnimationDuration, () {
|
||||
if (mounted) {
|
||||
@@ -176,7 +184,7 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
for (final controller in _foodControllers) {
|
||||
@@ -186,4 +194,4 @@ class _SplashScreenState extends State<SplashScreen> with TickerProviderStateMix
|
||||
_centerIconController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
lib/presentation/providers/ad_provider.dart
Normal file
7
lib/presentation/providers/ad_provider.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:lunchpick/core/services/ad_service.dart';
|
||||
|
||||
/// 광고 서비스 Provider
|
||||
final adServiceProvider = Provider<AdService>((ref) {
|
||||
return AdService();
|
||||
});
|
||||
8
lib/presentation/providers/bluetooth_provider.dart
Normal file
8
lib/presentation/providers/bluetooth_provider.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:lunchpick/core/services/bluetooth_service.dart';
|
||||
|
||||
final bluetoothServiceProvider = Provider<BluetoothService>((ref) {
|
||||
final service = BluetoothService();
|
||||
ref.onDispose(service.dispose);
|
||||
return service;
|
||||
});
|
||||
@@ -31,6 +31,8 @@ final weatherRepositoryProvider = Provider<WeatherRepository>((ref) {
|
||||
});
|
||||
|
||||
/// RecommendationRepository Provider
|
||||
final recommendationRepositoryProvider = Provider<RecommendationRepository>((ref) {
|
||||
final recommendationRepositoryProvider = Provider<RecommendationRepository>((
|
||||
ref,
|
||||
) {
|
||||
return RecommendationRepositoryImpl();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,9 @@ import 'package:geolocator/geolocator.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
/// 위치 권한 상태 Provider
|
||||
final locationPermissionProvider = FutureProvider<PermissionStatus>((ref) async {
|
||||
final locationPermissionProvider = FutureProvider<PermissionStatus>((
|
||||
ref,
|
||||
) async {
|
||||
return await Permission.location.status;
|
||||
});
|
||||
|
||||
@@ -11,7 +13,7 @@ final locationPermissionProvider = FutureProvider<PermissionStatus>((ref) async
|
||||
final currentLocationProvider = FutureProvider<Position?>((ref) async {
|
||||
// 위치 권한 확인
|
||||
final permissionStatus = await Permission.location.status;
|
||||
|
||||
|
||||
if (!permissionStatus.isGranted) {
|
||||
// 권한이 없으면 요청
|
||||
final result = await Permission.location.request();
|
||||
@@ -74,7 +76,7 @@ class LocationNotifier extends StateNotifier<AsyncValue<Position?>> {
|
||||
/// 현재 위치 가져오기
|
||||
Future<void> getCurrentLocation() async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
// 권한 확인
|
||||
final permissionStatus = await Permission.location.status;
|
||||
@@ -128,6 +130,7 @@ class LocationNotifier extends StateNotifier<AsyncValue<Position?>> {
|
||||
}
|
||||
|
||||
/// LocationNotifier Provider
|
||||
final locationNotifierProvider = StateNotifierProvider<LocationNotifier, AsyncValue<Position?>>((ref) {
|
||||
return LocationNotifier();
|
||||
});
|
||||
final locationNotifierProvider =
|
||||
StateNotifierProvider<LocationNotifier, AsyncValue<Position?>>((ref) {
|
||||
return LocationNotifier();
|
||||
});
|
||||
|
||||
@@ -22,7 +22,9 @@ class NotificationPayload {
|
||||
try {
|
||||
final parts = payload.split('|');
|
||||
if (parts.length < 4) {
|
||||
throw FormatException('Invalid payload format - expected 4 parts but got ${parts.length}: $payload');
|
||||
throw FormatException(
|
||||
'Invalid payload format - expected 4 parts but got ${parts.length}: $payload',
|
||||
);
|
||||
}
|
||||
|
||||
// 각 필드 유효성 검증
|
||||
@@ -66,11 +68,14 @@ class NotificationPayload {
|
||||
/// 알림 핸들러 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 {
|
||||
Future<void> handleNotificationTap(
|
||||
BuildContext context,
|
||||
String? payload,
|
||||
) async {
|
||||
if (payload == null || payload.isEmpty) {
|
||||
print('Notification payload is null or empty');
|
||||
return;
|
||||
@@ -83,12 +88,13 @@ class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
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'),
|
||||
orElse: () =>
|
||||
throw Exception('Restaurant not found: $restaurantName'),
|
||||
);
|
||||
|
||||
// 방문 확인 다이얼로그 표시
|
||||
@@ -97,17 +103,21 @@ class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
context: context,
|
||||
restaurantId: restaurant.id,
|
||||
restaurantName: restaurant.name,
|
||||
recommendationTime: DateTime.now().subtract(const Duration(hours: 2)),
|
||||
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}');
|
||||
|
||||
print(
|
||||
'Successfully parsed payload - Type: ${notificationPayload.type}, RestaurantId: ${notificationPayload.restaurantId}',
|
||||
);
|
||||
|
||||
if (notificationPayload.type == 'visit_reminder') {
|
||||
// 방문 확인 다이얼로그 표시
|
||||
if (context.mounted) {
|
||||
@@ -127,7 +137,7 @@ class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
} catch (parseError) {
|
||||
print('Failed to parse new format, attempting fallback parsing');
|
||||
print('Parse error: $parseError');
|
||||
|
||||
|
||||
// Fallback: 간단한 파싱 시도
|
||||
if (payload.contains('|')) {
|
||||
final parts = payload.split('|');
|
||||
@@ -135,16 +145,14 @@ class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
// 최소한 캘린더로 이동
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('알림을 처리했습니다. 방문 기록을 확인해주세요.'),
|
||||
),
|
||||
const SnackBar(content: Text('알림을 처리했습니다. 방문 기록을 확인해주세요.')),
|
||||
);
|
||||
context.go('/home?tab=calendar');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 파싱 실패 시 원래 에러 다시 발생
|
||||
rethrow;
|
||||
}
|
||||
@@ -153,7 +161,7 @@ class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
print('Error handling notification: $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
state = AsyncValue.error(e, stackTrace);
|
||||
|
||||
|
||||
// 에러 발생 시 기본적으로 캘린더 화면으로 이동
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -169,6 +177,7 @@ class NotificationHandlerNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
}
|
||||
|
||||
/// NotificationHandler Provider
|
||||
final notificationHandlerProvider = StateNotifierProvider<NotificationHandlerNotifier, AsyncValue<void>>((ref) {
|
||||
return NotificationHandlerNotifier(ref);
|
||||
});
|
||||
final notificationHandlerProvider =
|
||||
StateNotifierProvider<NotificationHandlerNotifier, AsyncValue<void>>((ref) {
|
||||
return NotificationHandlerNotifier(ref);
|
||||
});
|
||||
|
||||
@@ -16,4 +16,4 @@ final notificationPermissionProvider = FutureProvider<bool>((ref) async {
|
||||
final pendingNotificationsProvider = FutureProvider((ref) async {
|
||||
final service = ref.watch(notificationServiceProvider);
|
||||
return await service.getPendingNotifications();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,17 +5,19 @@ 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/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();
|
||||
});
|
||||
final recommendationRecordsProvider =
|
||||
StreamProvider<List<RecommendationRecord>>((ref) {
|
||||
final repository = ref.watch(recommendationRepositoryProvider);
|
||||
return repository.watchRecommendationRecords();
|
||||
});
|
||||
|
||||
/// 오늘의 추천 횟수 Provider
|
||||
final todayRecommendationCountProvider = FutureProvider<int>((ref) async {
|
||||
@@ -44,7 +46,8 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
|
||||
final Ref _ref;
|
||||
final RecommendationEngine _recommendationEngine = RecommendationEngine();
|
||||
|
||||
RecommendationNotifier(this._repository, this._ref) : super(const AsyncValue.data(null));
|
||||
RecommendationNotifier(this._repository, this._ref)
|
||||
: super(const AsyncValue.data(null));
|
||||
|
||||
/// 랜덤 추천 실행
|
||||
Future<void> getRandomRecommendation({
|
||||
@@ -52,7 +55,7 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
|
||||
required List<String> selectedCategories,
|
||||
}) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
// 현재 위치 가져오기
|
||||
final location = await _ref.read(currentLocationProvider.future);
|
||||
@@ -62,16 +65,16 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
|
||||
|
||||
// 날씨 정보 가져오기
|
||||
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,
|
||||
@@ -81,14 +84,15 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
|
||||
userSettings: userSettings,
|
||||
weather: weather,
|
||||
);
|
||||
|
||||
|
||||
// 추천 엔진 사용
|
||||
final selectedRestaurant = await _recommendationEngine.generateRecommendation(
|
||||
allRestaurants: allRestaurants,
|
||||
recentVisits: allVisitRecords,
|
||||
config: config,
|
||||
);
|
||||
|
||||
final selectedRestaurant = await _recommendationEngine
|
||||
.generateRecommendation(
|
||||
allRestaurants: allRestaurants,
|
||||
recentVisits: allVisitRecords,
|
||||
config: config,
|
||||
);
|
||||
|
||||
if (selectedRestaurant == null) {
|
||||
state = const AsyncValue.data(null);
|
||||
return;
|
||||
@@ -120,11 +124,15 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
|
||||
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 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,
|
||||
@@ -146,16 +154,26 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
|
||||
}
|
||||
|
||||
/// RecommendationNotifier Provider
|
||||
final recommendationNotifierProvider = StateNotifierProvider<RecommendationNotifier, AsyncValue<Restaurant?>>((ref) {
|
||||
final repository = ref.watch(recommendationRepositoryProvider);
|
||||
return RecommendationNotifier(repository, ref);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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 {
|
||||
@@ -163,14 +181,14 @@ class RecommendationState {
|
||||
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,
|
||||
@@ -178,7 +196,8 @@ class RecommendationState {
|
||||
String? error,
|
||||
}) {
|
||||
return RecommendationState(
|
||||
currentRecommendation: currentRecommendation ?? this.currentRecommendation,
|
||||
currentRecommendation:
|
||||
currentRecommendation ?? this.currentRecommendation,
|
||||
excludedRestaurants: excludedRestaurants ?? this.excludedRestaurants,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
error: error,
|
||||
@@ -187,28 +206,35 @@ class RecommendationState {
|
||||
}
|
||||
|
||||
/// 향상된 추천 StateNotifier (다시 추천 기능 포함)
|
||||
class EnhancedRecommendationNotifier extends StateNotifier<RecommendationState> {
|
||||
class EnhancedRecommendationNotifier
|
||||
extends StateNotifier<RecommendationState> {
|
||||
final Ref _ref;
|
||||
final RecommendationEngine _recommendationEngine = RecommendationEngine();
|
||||
|
||||
EnhancedRecommendationNotifier(this._ref) : super(const RecommendationState());
|
||||
|
||||
|
||||
EnhancedRecommendationNotifier(this._ref)
|
||||
: super(const RecommendationState());
|
||||
|
||||
/// 다시 추천 (현재 추천 제외)
|
||||
Future<void> rerollRecommendation() async {
|
||||
if (state.currentRecommendation == null) return;
|
||||
|
||||
|
||||
// 현재 추천을 제외 목록에 추가
|
||||
final excluded = [...state.excludedRestaurants, state.currentRecommendation!];
|
||||
final excluded = [
|
||||
...state.excludedRestaurants,
|
||||
state.currentRecommendation!,
|
||||
];
|
||||
state = state.copyWith(excludedRestaurants: excluded);
|
||||
|
||||
|
||||
// 다시 추천 생성 (제외 목록 적용)
|
||||
await generateRecommendation(excludedRestaurants: excluded);
|
||||
}
|
||||
|
||||
|
||||
/// 추천 생성 (새로운 추천 엔진 활용)
|
||||
Future<void> generateRecommendation({List<Restaurant>? excludedRestaurants}) async {
|
||||
Future<void> generateRecommendation({
|
||||
List<Restaurant>? excludedRestaurants,
|
||||
}) async {
|
||||
state = state.copyWith(isLoading: true);
|
||||
|
||||
|
||||
try {
|
||||
// 현재 위치 가져오기
|
||||
final location = await _ref.read(currentLocationProvider.future);
|
||||
@@ -216,21 +242,27 @@ class EnhancedRecommendationNotifier extends StateNotifier<RecommendationState>
|
||||
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 maxDistanceNormal = await _ref.read(
|
||||
maxDistanceNormalProvider.future,
|
||||
);
|
||||
final selectedCategory = _ref.read(selectedCategoryProvider);
|
||||
final categories = selectedCategory != null ? [selectedCategory] : <String>[];
|
||||
|
||||
final categories = selectedCategory != null
|
||||
? [selectedCategory]
|
||||
: <String>[];
|
||||
|
||||
// 제외 리스트 포함한 식당 필터링
|
||||
final availableRestaurants = excludedRestaurants != null
|
||||
? allRestaurants.where((r) => !excludedRestaurants.any((ex) => ex.id == r.id)).toList()
|
||||
? allRestaurants
|
||||
.where((r) => !excludedRestaurants.any((ex) => ex.id == r.id))
|
||||
.toList()
|
||||
: allRestaurants;
|
||||
|
||||
|
||||
// 추천 설정 구성
|
||||
final config = RecommendationConfig(
|
||||
userLatitude: location.latitude,
|
||||
@@ -240,14 +272,15 @@ class EnhancedRecommendationNotifier extends StateNotifier<RecommendationState>
|
||||
userSettings: userSettings,
|
||||
weather: weather,
|
||||
);
|
||||
|
||||
|
||||
// 추천 엔진 사용
|
||||
final selectedRestaurant = await _recommendationEngine.generateRecommendation(
|
||||
allRestaurants: availableRestaurants,
|
||||
recentVisits: allVisitRecords,
|
||||
config: config,
|
||||
);
|
||||
|
||||
final selectedRestaurant = await _recommendationEngine
|
||||
.generateRecommendation(
|
||||
allRestaurants: availableRestaurants,
|
||||
recentVisits: allVisitRecords,
|
||||
config: config,
|
||||
);
|
||||
|
||||
if (selectedRestaurant != null) {
|
||||
// 추천 기록 저장
|
||||
final record = RecommendationRecord(
|
||||
@@ -257,28 +290,22 @@ class EnhancedRecommendationNotifier extends StateNotifier<RecommendationState>
|
||||
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,
|
||||
);
|
||||
state = state.copyWith(error: '조건에 맞는 맛집이 없습니다', isLoading: false);
|
||||
}
|
||||
} catch (e) {
|
||||
state = state.copyWith(
|
||||
error: e.toString(),
|
||||
isLoading: false,
|
||||
);
|
||||
state = state.copyWith(error: e.toString(), isLoading: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// 추천 초기화
|
||||
void resetRecommendation() {
|
||||
state = const RecommendationState();
|
||||
@@ -286,33 +313,39 @@ class EnhancedRecommendationNotifier extends StateNotifier<RecommendationState>
|
||||
}
|
||||
|
||||
/// 향상된 추천 Provider
|
||||
final enhancedRecommendationProvider =
|
||||
StateNotifierProvider<EnhancedRecommendationNotifier, RecommendationState>((ref) {
|
||||
return EnhancedRecommendationNotifier(ref);
|
||||
});
|
||||
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
|
||||
restaurantsNotVisitedInDaysProvider(daysToExclude).future,
|
||||
);
|
||||
|
||||
|
||||
return recentlyVisited.length;
|
||||
});
|
||||
|
||||
/// 카테고리별 추천 통계 Provider
|
||||
final recommendationStatsByCategoryProvider = FutureProvider<Map<String, int>>((ref) async {
|
||||
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);
|
||||
final restaurant = await ref.watch(
|
||||
restaurantProvider(record.restaurantId).future,
|
||||
);
|
||||
if (restaurant != null) {
|
||||
stats[restaurant.category] = (stats[restaurant.category] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return stats;
|
||||
});
|
||||
|
||||
@@ -320,22 +353,26 @@ final recommendationStatsByCategoryProvider = FutureProvider<Map<String, int>>((
|
||||
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();
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
@@ -12,7 +12,10 @@ final restaurantListProvider = StreamProvider<List<Restaurant>>((ref) {
|
||||
});
|
||||
|
||||
/// 특정 맛집 Provider
|
||||
final restaurantProvider = FutureProvider.family<Restaurant?, String>((ref, id) async {
|
||||
final restaurantProvider = FutureProvider.family<Restaurant?, String>((
|
||||
ref,
|
||||
id,
|
||||
) async {
|
||||
final repository = ref.watch(restaurantRepositoryProvider);
|
||||
return repository.getRestaurantById(id);
|
||||
});
|
||||
@@ -43,7 +46,7 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
required DataSource source,
|
||||
}) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
final restaurant = Restaurant(
|
||||
id: const Uuid().v4(),
|
||||
@@ -71,7 +74,7 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
/// 맛집 수정
|
||||
Future<void> updateRestaurant(Restaurant restaurant) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
final updated = Restaurant(
|
||||
id: restaurant.id,
|
||||
@@ -100,7 +103,7 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
/// 맛집 삭제
|
||||
Future<void> deleteRestaurant(String id) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
await _repository.deleteRestaurant(id);
|
||||
state = const AsyncValue.data(null);
|
||||
@@ -110,7 +113,10 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
}
|
||||
|
||||
/// 마지막 방문일 업데이트
|
||||
Future<void> updateLastVisitDate(String restaurantId, DateTime visitDate) async {
|
||||
Future<void> updateLastVisitDate(
|
||||
String restaurantId,
|
||||
DateTime visitDate,
|
||||
) async {
|
||||
try {
|
||||
await _repository.updateLastVisitDate(restaurantId, visitDate);
|
||||
} catch (e, stack) {
|
||||
@@ -121,7 +127,7 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
/// 네이버 지도 URL로부터 맛집 추가
|
||||
Future<Restaurant> addRestaurantFromUrl(String url) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
final restaurant = await _repository.addRestaurantFromUrl(url);
|
||||
state = const AsyncValue.data(null);
|
||||
@@ -135,7 +141,7 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
/// 미리 생성된 Restaurant 객체를 직접 추가
|
||||
Future<void> addRestaurantDirect(Restaurant restaurant) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
await _repository.addRestaurant(restaurant);
|
||||
state = const AsyncValue.data(null);
|
||||
@@ -147,38 +153,46 @@ class RestaurantNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
}
|
||||
|
||||
/// RestaurantNotifier Provider
|
||||
final restaurantNotifierProvider = StateNotifierProvider<RestaurantNotifier, AsyncValue<void>>((ref) {
|
||||
final repository = ref.watch(restaurantRepositoryProvider);
|
||||
return RestaurantNotifier(repository);
|
||||
});
|
||||
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,
|
||||
);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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) => '');
|
||||
@@ -187,37 +201,45 @@ final searchQueryProvider = StateProvider<String>((ref) => '');
|
||||
final selectedCategoryProvider = StateProvider<String?>((ref) => null);
|
||||
|
||||
/// 필터링된 맛집 목록 Provider (검색 + 카테고리)
|
||||
final filteredRestaurantsProvider = StreamProvider<List<Restaurant>>((ref) async* {
|
||||
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.description?.toLowerCase().contains(lowercaseQuery) ??
|
||||
false) ||
|
||||
restaurant.category.toLowerCase().contains(lowercaseQuery);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
|
||||
// 카테고리 필터 적용
|
||||
if (selectedCategory != null) {
|
||||
filtered = filtered.where((restaurant) {
|
||||
// 정확한 일치 또는 부분 일치 확인
|
||||
// restaurant.category가 "음식점>한식>백반/한정식" 형태일 때
|
||||
// selectedCategory가 "백반/한정식"이면 매칭
|
||||
return restaurant.category == selectedCategory ||
|
||||
restaurant.category.contains(selectedCategory) ||
|
||||
CategoryMapper.normalizeNaverCategory(restaurant.category, restaurant.subCategory) == selectedCategory ||
|
||||
CategoryMapper.getDisplayName(restaurant.category) == selectedCategory;
|
||||
return restaurant.category == selectedCategory ||
|
||||
restaurant.category.contains(selectedCategory) ||
|
||||
CategoryMapper.normalizeNaverCategory(
|
||||
restaurant.category,
|
||||
restaurant.subCategory,
|
||||
) ==
|
||||
selectedCategory ||
|
||||
CategoryMapper.getDisplayName(restaurant.category) ==
|
||||
selectedCategory;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
|
||||
yield filtered;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -170,10 +170,11 @@ class SettingsNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
}
|
||||
|
||||
/// SettingsNotifier Provider
|
||||
final settingsNotifierProvider = StateNotifierProvider<SettingsNotifier, AsyncValue<void>>((ref) {
|
||||
final repository = ref.watch(settingsRepositoryProvider);
|
||||
return SettingsNotifier(repository);
|
||||
});
|
||||
final settingsNotifierProvider =
|
||||
StateNotifierProvider<SettingsNotifier, AsyncValue<void>>((ref) {
|
||||
final repository = ref.watch(settingsRepositoryProvider);
|
||||
return SettingsNotifier(repository);
|
||||
});
|
||||
|
||||
/// 설정 프리셋
|
||||
enum SettingsPreset {
|
||||
@@ -210,16 +211,20 @@ enum SettingsPreset {
|
||||
}
|
||||
|
||||
/// 프리셋 적용 Provider
|
||||
final applyPresetProvider = Provider.family<Future<void>, SettingsPreset>((ref, preset) async {
|
||||
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);
|
||||
final currentLocationProvider =
|
||||
StateProvider<({double latitude, double longitude})?>((ref) => null);
|
||||
|
||||
/// 선호 카테고리 Provider
|
||||
final preferredCategoriesProvider = StateProvider<List<String>>((ref) => []);
|
||||
@@ -241,8 +246,10 @@ 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 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);
|
||||
@@ -261,4 +268,4 @@ final allSettingsProvider = Provider<Map<String, dynamic>>((ref) {
|
||||
'excludedCategories': excludedCategories,
|
||||
'language': language,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,29 +12,36 @@ final visitRecordsProvider = StreamProvider<List<VisitRecord>>((ref) {
|
||||
});
|
||||
|
||||
/// 날짜별 방문 기록 Provider
|
||||
final visitRecordsByDateProvider = FutureProvider.family<List<VisitRecord>, DateTime>((ref, date) async {
|
||||
final repository = ref.watch(visitRepositoryProvider);
|
||||
return repository.getVisitRecordsByDate(date);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
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));
|
||||
VisitNotifier(this._repository, this._ref)
|
||||
: super(const AsyncValue.data(null));
|
||||
|
||||
/// 방문 기록 추가
|
||||
Future<void> addVisitRecord({
|
||||
@@ -43,7 +50,7 @@ class VisitNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
bool isConfirmed = false,
|
||||
}) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
final visitRecord = VisitRecord(
|
||||
id: const Uuid().v4(),
|
||||
@@ -54,11 +61,11 @@ class VisitNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
);
|
||||
|
||||
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);
|
||||
@@ -68,7 +75,7 @@ class VisitNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
/// 방문 확인
|
||||
Future<void> confirmVisit(String visitRecordId) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
await _repository.confirmVisit(visitRecordId);
|
||||
state = const AsyncValue.data(null);
|
||||
@@ -80,7 +87,7 @@ class VisitNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
/// 방문 기록 삭제
|
||||
Future<void> deleteVisitRecord(String id) async {
|
||||
state = const AsyncValue.loading();
|
||||
|
||||
|
||||
try {
|
||||
await _repository.deleteVisitRecord(id);
|
||||
state = const AsyncValue.data(null);
|
||||
@@ -96,7 +103,7 @@ class VisitNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
}) async {
|
||||
// 추천 시간으로부터 1.5시간 후를 방문 시간으로 설정
|
||||
final visitTime = recommendationTime.add(const Duration(minutes: 90));
|
||||
|
||||
|
||||
await addVisitRecord(
|
||||
restaurantId: restaurantId,
|
||||
visitDate: visitTime,
|
||||
@@ -106,109 +113,138 @@ class VisitNotifier extends StateNotifier<AsyncValue<void>> {
|
||||
}
|
||||
|
||||
/// VisitNotifier Provider
|
||||
final visitNotifierProvider = StateNotifierProvider<VisitNotifier, AsyncValue<void>>((ref) {
|
||||
final repository = ref.watch(visitRepositoryProvider);
|
||||
return VisitNotifier(repository, ref);
|
||||
});
|
||||
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 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));
|
||||
});
|
||||
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 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;
|
||||
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();
|
||||
});
|
||||
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, // 오래된순
|
||||
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),
|
||||
);
|
||||
});
|
||||
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 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;
|
||||
final restaurant = restaurantsAsync
|
||||
.where((r) => r.id == record.restaurantId)
|
||||
.firstOrNull;
|
||||
if (restaurant != null) {
|
||||
categoryCount[restaurant.category] = (categoryCount[restaurant.category] ?? 0) + 1;
|
||||
categoryCount[restaurant.category] =
|
||||
(categoryCount[restaurant.category] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return categoryCount;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:lunchpick/presentation/providers/location_provider.dart';
|
||||
final weatherProvider = FutureProvider<WeatherInfo>((ref) async {
|
||||
final repository = ref.watch(weatherRepositoryProvider);
|
||||
final location = await ref.watch(currentLocationProvider.future);
|
||||
|
||||
|
||||
if (location == null) {
|
||||
throw Exception('위치 정보를 가져올 수 없습니다');
|
||||
}
|
||||
@@ -37,12 +37,13 @@ class WeatherNotifier extends StateNotifier<AsyncValue<WeatherInfo>> {
|
||||
final WeatherRepository _repository;
|
||||
final Ref _ref;
|
||||
|
||||
WeatherNotifier(this._repository, this._ref) : super(const AsyncValue.loading());
|
||||
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) {
|
||||
@@ -86,7 +87,8 @@ class WeatherNotifier extends StateNotifier<AsyncValue<WeatherInfo>> {
|
||||
}
|
||||
|
||||
/// WeatherNotifier Provider
|
||||
final weatherNotifierProvider = StateNotifierProvider<WeatherNotifier, AsyncValue<WeatherInfo>>((ref) {
|
||||
final repository = ref.watch(weatherRepositoryProvider);
|
||||
return WeatherNotifier(repository, ref);
|
||||
});
|
||||
final weatherNotifierProvider =
|
||||
StateNotifierProvider<WeatherNotifier, AsyncValue<WeatherInfo>>((ref) {
|
||||
final repository = ref.watch(weatherRepositoryProvider);
|
||||
return WeatherNotifier(repository, ref);
|
||||
});
|
||||
|
||||
@@ -67,9 +67,7 @@ class RestaurantFormValidator {
|
||||
}
|
||||
|
||||
// 전화번호 패턴: 02-1234-5678, 010-1234-5678 등
|
||||
final phoneRegex = RegExp(
|
||||
r'^0\d{1,2}-?\d{3,4}-?\d{4}$',
|
||||
);
|
||||
final phoneRegex = RegExp(r'^0\d{1,2}-?\d{3,4}-?\d{4}$');
|
||||
|
||||
if (!phoneRegex.hasMatch(phoneNumber.replaceAll(' ', ''))) {
|
||||
return '올바른 전화번호 형식이 아닙니다';
|
||||
@@ -100,7 +98,7 @@ class RestaurantFormValidator {
|
||||
|
||||
// 허용된 카테고리 목록 (필요시 추가)
|
||||
// final allowedCategories = [
|
||||
// '한식', '중식', '일식', '양식', '아시안',
|
||||
// '한식', '중식', '일식', '양식', '아시안',
|
||||
// '카페', '디저트', '분식', '패스트푸드', '기타'
|
||||
// ];
|
||||
|
||||
@@ -119,8 +117,8 @@ class RestaurantFormValidator {
|
||||
/// 필수 필드만 검증
|
||||
static bool hasRequiredFields(RestaurantFormData formData) {
|
||||
return formData.name.isNotEmpty &&
|
||||
formData.category.isNotEmpty &&
|
||||
formData.roadAddress.isNotEmpty;
|
||||
formData.category.isNotEmpty &&
|
||||
formData.roadAddress.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,11 +140,11 @@ class FormFieldErrors {
|
||||
this.phoneNumber,
|
||||
});
|
||||
|
||||
bool get hasErrors =>
|
||||
name != null ||
|
||||
category != null ||
|
||||
roadAddress != null ||
|
||||
latitude != null ||
|
||||
bool get hasErrors =>
|
||||
name != null ||
|
||||
category != null ||
|
||||
roadAddress != null ||
|
||||
latitude != null ||
|
||||
longitude != null ||
|
||||
phoneNumber != null;
|
||||
|
||||
@@ -160,4 +158,4 @@ class FormFieldErrors {
|
||||
if (phoneNumber != null) map['phoneNumber'] = phoneNumber!;
|
||||
return map;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,33 +3,46 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../domain/entities/restaurant.dart';
|
||||
import '../providers/di_providers.dart';
|
||||
import '../providers/restaurant_provider.dart';
|
||||
|
||||
/// 식당 추가 화면의 상태 모델
|
||||
class AddRestaurantState {
|
||||
final bool isLoading;
|
||||
final bool isSearching;
|
||||
final String? errorMessage;
|
||||
final Restaurant? fetchedRestaurantData;
|
||||
final RestaurantFormData formData;
|
||||
final List<Restaurant> searchResults;
|
||||
|
||||
const AddRestaurantState({
|
||||
this.isLoading = false,
|
||||
this.isSearching = false,
|
||||
this.errorMessage,
|
||||
this.fetchedRestaurantData,
|
||||
required this.formData,
|
||||
this.searchResults = const [],
|
||||
});
|
||||
|
||||
AddRestaurantState copyWith({
|
||||
bool? isLoading,
|
||||
bool? isSearching,
|
||||
String? errorMessage,
|
||||
Restaurant? fetchedRestaurantData,
|
||||
RestaurantFormData? formData,
|
||||
List<Restaurant>? searchResults,
|
||||
bool clearFetchedRestaurant = false,
|
||||
bool clearError = false,
|
||||
}) {
|
||||
return AddRestaurantState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
fetchedRestaurantData: fetchedRestaurantData ?? this.fetchedRestaurantData,
|
||||
isSearching: isSearching ?? this.isSearching,
|
||||
errorMessage: clearError ? null : (errorMessage ?? this.errorMessage),
|
||||
fetchedRestaurantData: clearFetchedRestaurant
|
||||
? null
|
||||
: (fetchedRestaurantData ?? this.fetchedRestaurantData),
|
||||
formData: formData ?? this.formData,
|
||||
searchResults: searchResults ?? this.searchResults,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -156,7 +169,12 @@ class AddRestaurantViewModel extends StateNotifier<AddRestaurantState> {
|
||||
final Ref _ref;
|
||||
|
||||
AddRestaurantViewModel(this._ref)
|
||||
: super(const AddRestaurantState(formData: RestaurantFormData()));
|
||||
: super(const AddRestaurantState(formData: RestaurantFormData()));
|
||||
|
||||
/// 상태 초기화
|
||||
void reset() {
|
||||
state = const AddRestaurantState(formData: RestaurantFormData());
|
||||
}
|
||||
|
||||
/// 네이버 URL로부터 식당 정보 가져오기
|
||||
Future<void> fetchFromNaverUrl(String url) async {
|
||||
@@ -165,11 +183,11 @@ class AddRestaurantViewModel extends StateNotifier<AddRestaurantState> {
|
||||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(isLoading: true, errorMessage: null);
|
||||
state = state.copyWith(isLoading: true, clearError: true);
|
||||
|
||||
try {
|
||||
final notifier = _ref.read(restaurantNotifierProvider.notifier);
|
||||
final restaurant = await notifier.addRestaurantFromUrl(url);
|
||||
final repository = _ref.read(restaurantRepositoryProvider);
|
||||
final restaurant = await repository.previewRestaurantFromUrl(url);
|
||||
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
@@ -177,42 +195,83 @@ class AddRestaurantViewModel extends StateNotifier<AddRestaurantState> {
|
||||
formData: RestaurantFormData.fromRestaurant(restaurant),
|
||||
);
|
||||
} catch (e) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: e.toString(),
|
||||
);
|
||||
state = state.copyWith(isLoading: false, errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/// 네이버 검색으로 식당 목록 검색
|
||||
Future<void> searchRestaurants(
|
||||
String query, {
|
||||
double? latitude,
|
||||
double? longitude,
|
||||
}) async {
|
||||
if (query.trim().isEmpty) {
|
||||
state = state.copyWith(
|
||||
errorMessage: '검색어를 입력해주세요.',
|
||||
searchResults: const [],
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
state = state.copyWith(isSearching: true, clearError: true);
|
||||
|
||||
try {
|
||||
final repository = _ref.read(restaurantRepositoryProvider);
|
||||
final results = await repository.searchRestaurantsFromNaver(
|
||||
query: query,
|
||||
latitude: latitude,
|
||||
longitude: longitude,
|
||||
);
|
||||
state = state.copyWith(isSearching: false, searchResults: results);
|
||||
} catch (e) {
|
||||
state = state.copyWith(isSearching: false, errorMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/// 검색 결과 선택
|
||||
void selectSearchResult(Restaurant restaurant) {
|
||||
state = state.copyWith(
|
||||
fetchedRestaurantData: restaurant,
|
||||
formData: RestaurantFormData.fromRestaurant(restaurant),
|
||||
clearError: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// 식당 정보 저장
|
||||
Future<bool> saveRestaurant() async {
|
||||
final notifier = _ref.read(restaurantNotifierProvider.notifier);
|
||||
|
||||
try {
|
||||
state = state.copyWith(isLoading: true, clearError: true);
|
||||
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
|
||||
subCategory: state.formData.subCategory.isEmpty
|
||||
? state.formData.category
|
||||
: state.formData.subCategory,
|
||||
description: state.formData.description.isEmpty
|
||||
? null
|
||||
description: state.formData.description.isEmpty
|
||||
? null
|
||||
: state.formData.description,
|
||||
phoneNumber: state.formData.phoneNumber.isEmpty
|
||||
? null
|
||||
phoneNumber: state.formData.phoneNumber.isEmpty
|
||||
? null
|
||||
: state.formData.phoneNumber,
|
||||
roadAddress: state.formData.roadAddress,
|
||||
jibunAddress: state.formData.jibunAddress.isEmpty
|
||||
? 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,
|
||||
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 {
|
||||
@@ -221,9 +280,10 @@ class AddRestaurantViewModel extends StateNotifier<AddRestaurantState> {
|
||||
}
|
||||
|
||||
await notifier.addRestaurantDirect(restaurantToSave);
|
||||
state = state.copyWith(isLoading: false);
|
||||
return true;
|
||||
} catch (e) {
|
||||
state = state.copyWith(errorMessage: e.toString());
|
||||
state = state.copyWith(isLoading: false, errorMessage: e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -235,12 +295,13 @@ class AddRestaurantViewModel extends StateNotifier<AddRestaurantState> {
|
||||
|
||||
/// 에러 메시지 초기화
|
||||
void clearError() {
|
||||
state = state.copyWith(errorMessage: null);
|
||||
state = state.copyWith(clearError: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// AddRestaurantViewModel Provider
|
||||
final addRestaurantViewModelProvider =
|
||||
StateNotifierProvider.autoDispose<AddRestaurantViewModel, AddRestaurantState>(
|
||||
(ref) => AddRestaurantViewModel(ref),
|
||||
);
|
||||
StateNotifierProvider.autoDispose<
|
||||
AddRestaurantViewModel,
|
||||
AddRestaurantState
|
||||
>((ref) => AddRestaurantViewModel(ref));
|
||||
|
||||
@@ -26,7 +26,7 @@ class CategorySelector extends ConsumerWidget {
|
||||
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(
|
||||
@@ -39,7 +39,9 @@ class CategorySelector extends ConsumerWidget {
|
||||
context: context,
|
||||
label: '전체',
|
||||
icon: Icons.restaurant_menu,
|
||||
color: isDark ? AppColors.darkPrimary : AppColors.lightPrimary,
|
||||
color: isDark
|
||||
? AppColors.darkPrimary
|
||||
: AppColors.lightPrimary,
|
||||
isSelected: selectedCategory == null,
|
||||
onTap: () => onCategorySelected(null),
|
||||
),
|
||||
@@ -49,7 +51,7 @@ class CategorySelector extends ConsumerWidget {
|
||||
final isSelected = multiSelect
|
||||
? selectedCategories?.contains(category) ?? false
|
||||
: selectedCategory == category;
|
||||
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: _buildCategoryChip(
|
||||
@@ -74,30 +76,26 @@ class CategorySelector extends ConsumerWidget {
|
||||
},
|
||||
loading: () => const SizedBox(
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (error, stack) => const SizedBox(
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Text('카테고리를 불러올 수 없습니다'),
|
||||
),
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -110,7 +108,7 @@ class CategorySelector extends ConsumerWidget {
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
@@ -120,11 +118,11 @@ class CategorySelector extends ConsumerWidget {
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
color: isSelected
|
||||
? color.withOpacity(0.2)
|
||||
: isDark
|
||||
? AppColors.darkSurface
|
||||
: AppColors.lightBackground,
|
||||
: isDark
|
||||
? AppColors.darkSurface
|
||||
: AppColors.lightBackground,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: isSelected ? color : Colors.transparent,
|
||||
@@ -137,21 +135,21 @@ class CategorySelector extends ConsumerWidget {
|
||||
Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: isSelected
|
||||
? color
|
||||
: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
color: isSelected
|
||||
? color
|
||||
: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? color
|
||||
: isDark
|
||||
? AppColors.darkText
|
||||
: AppColors.lightText,
|
||||
color: isSelected
|
||||
? color
|
||||
: isDark
|
||||
? AppColors.darkText
|
||||
: AppColors.lightText,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
@@ -180,7 +178,7 @@ class CategorySelectionDialog extends ConsumerWidget {
|
||||
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(
|
||||
@@ -193,7 +191,9 @@ class CategorySelectionDialog extends ConsumerWidget {
|
||||
subtitle!,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -214,12 +214,14 @@ class CategorySelectionDialog extends ConsumerWidget {
|
||||
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);
|
||||
final updatedCategories = List<String>.from(
|
||||
selectedCategories,
|
||||
);
|
||||
if (isSelected) {
|
||||
updatedCategories.remove(category);
|
||||
} else {
|
||||
@@ -231,12 +233,9 @@ class CategorySelectionDialog extends ConsumerWidget {
|
||||
},
|
||||
),
|
||||
),
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
error: (error, stack) => Center(
|
||||
child: Text('카테고리를 불러올 수 없습니다: $error'),
|
||||
),
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) =>
|
||||
Center(child: Text('카테고리를 불러올 수 없습니다: $error')),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -244,7 +243,9 @@ class CategorySelectionDialog extends ConsumerWidget {
|
||||
child: Text(
|
||||
'취소',
|
||||
style: TextStyle(
|
||||
color: isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||
color: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -274,7 +275,7 @@ class _CategoryGridItem extends StatelessWidget {
|
||||
final color = CategoryMapper.getColor(category);
|
||||
final icon = CategoryMapper.getIcon(category);
|
||||
final displayName = CategoryMapper.getDisplayName(category);
|
||||
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
@@ -284,11 +285,11 @@ class _CategoryGridItem extends StatelessWidget {
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
color: isSelected
|
||||
? color.withOpacity(0.2)
|
||||
: isDark
|
||||
? AppColors.darkCard
|
||||
: AppColors.lightCard,
|
||||
: isDark
|
||||
? AppColors.darkCard
|
||||
: AppColors.lightCard,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isSelected ? color : Colors.transparent,
|
||||
@@ -301,22 +302,22 @@ class _CategoryGridItem extends StatelessWidget {
|
||||
Icon(
|
||||
icon,
|
||||
size: 28,
|
||||
color: isSelected
|
||||
? color
|
||||
: isDark
|
||||
? AppColors.darkTextSecondary
|
||||
: AppColors.lightTextSecondary,
|
||||
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,
|
||||
color: isSelected
|
||||
? color
|
||||
: isDark
|
||||
? AppColors.darkText
|
||||
: AppColors.lightText,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
@@ -329,4 +330,4 @@ class _CategoryGridItem extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user