feat(app): add manual entry and sharing flows

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

View File

@@ -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('저장'),
),
],
),
],
),
),
),
);
}
}

View File

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

View File

@@ -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 ? '가져오기' : '저장',
),
),
],
),
);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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