perf(app): 초기화 병렬 처리 및 UI 개선
## 성능 최적화 ### main.dart - 앱 초기화 병렬 처리 (Future.wait 활용) - 광고 SDK, Hive 초기화 동시 실행 - Hive Box 오픈 병렬 처리 - 코드 구조화 (_initializeHive, _initializeNotifications) ### visit_provider.dart - allLastVisitDatesProvider 추가 - 리스트 화면에서 N+1 쿼리 방지 - 모든 맛집의 마지막 방문일 일괄 조회 ## UI 개선 ### 각 화면 리팩토링 - AppDimensions 상수 적용 - 스켈레톤 로더 적용 - 코드 정리 및 일관성 개선
This commit is contained in:
@@ -22,14 +22,28 @@ import 'data/sample/sample_data_initializer.dart';
|
|||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
if (AdHelper.isMobilePlatform) {
|
// Initialize timezone (동기, 빠름)
|
||||||
await MobileAds.instance.initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize timezone
|
|
||||||
tz.initializeTimeZones();
|
tz.initializeTimeZones();
|
||||||
|
|
||||||
// Initialize Hive
|
// 광고 SDK와 Hive 초기화를 병렬 처리
|
||||||
|
await Future.wait([
|
||||||
|
if (AdHelper.isMobilePlatform) MobileAds.instance.initialize(),
|
||||||
|
_initializeHive(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Hive 초기화 후 병렬 처리 가능한 작업들
|
||||||
|
await Future.wait([
|
||||||
|
SampleDataInitializer.seedInitialData(),
|
||||||
|
_initializeNotifications(),
|
||||||
|
AdaptiveTheme.getThemeMode(),
|
||||||
|
]).then((results) {
|
||||||
|
final savedThemeMode = results[2] as AdaptiveThemeMode?;
|
||||||
|
runApp(ProviderScope(child: LunchPickApp(savedThemeMode: savedThemeMode)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hive 초기화 및 Box 오픈
|
||||||
|
Future<void> _initializeHive() async {
|
||||||
await Hive.initFlutter();
|
await Hive.initFlutter();
|
||||||
|
|
||||||
// Register Hive Adapters
|
// Register Hive Adapters
|
||||||
@@ -39,24 +53,21 @@ void main() async {
|
|||||||
Hive.registerAdapter(RecommendationRecordAdapter());
|
Hive.registerAdapter(RecommendationRecordAdapter());
|
||||||
Hive.registerAdapter(UserSettingsAdapter());
|
Hive.registerAdapter(UserSettingsAdapter());
|
||||||
|
|
||||||
// Open Hive Boxes
|
// Open Hive Boxes (병렬 오픈)
|
||||||
await Hive.openBox<Restaurant>(AppConstants.restaurantBox);
|
await Future.wait([
|
||||||
await Hive.openBox<VisitRecord>(AppConstants.visitRecordBox);
|
Hive.openBox<Restaurant>(AppConstants.restaurantBox),
|
||||||
await Hive.openBox<RecommendationRecord>(AppConstants.recommendationBox);
|
Hive.openBox<VisitRecord>(AppConstants.visitRecordBox),
|
||||||
await Hive.openBox(AppConstants.settingsBox);
|
Hive.openBox<RecommendationRecord>(AppConstants.recommendationBox),
|
||||||
await Hive.openBox<UserSettings>('user_settings');
|
Hive.openBox(AppConstants.settingsBox),
|
||||||
await SampleDataInitializer.seedInitialData();
|
Hive.openBox<UserSettings>('user_settings'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize Notification Service (only for non-web platforms)
|
/// 알림 서비스 초기화 (비-웹 플랫폼)
|
||||||
if (!kIsWeb) {
|
Future<void> _initializeNotifications() async {
|
||||||
final notificationService = NotificationService();
|
if (kIsWeb) return;
|
||||||
await notificationService.ensureInitialized(requestPermission: true);
|
final notificationService = NotificationService();
|
||||||
}
|
await notificationService.ensureInitialized(requestPermission: true);
|
||||||
|
|
||||||
// Get saved theme mode
|
|
||||||
final savedThemeMode = await AdaptiveTheme.getThemeMode();
|
|
||||||
|
|
||||||
runApp(ProviderScope(child: LunchPickApp(savedThemeMode: savedThemeMode)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LunchPickApp extends StatelessWidget {
|
class LunchPickApp extends StatelessWidget {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:table_calendar/table_calendar.dart';
|
import 'package:table_calendar/table_calendar.dart';
|
||||||
import '../../../core/constants/app_colors.dart';
|
import '../../../core/constants/app_colors.dart';
|
||||||
import '../../../core/constants/app_typography.dart';
|
import '../../../core/constants/app_typography.dart';
|
||||||
|
import '../../../core/widgets/info_row.dart';
|
||||||
import '../../../domain/entities/restaurant.dart';
|
import '../../../domain/entities/restaurant.dart';
|
||||||
import '../../../domain/entities/recommendation_record.dart';
|
import '../../../domain/entities/recommendation_record.dart';
|
||||||
import '../../../domain/entities/visit_record.dart';
|
import '../../../domain/entities/visit_record.dart';
|
||||||
@@ -607,18 +608,25 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_buildInfoRow('주소', restaurant.roadAddress, isDark),
|
InfoRow(
|
||||||
|
label: '주소',
|
||||||
|
value: restaurant.roadAddress,
|
||||||
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
|
),
|
||||||
if (visitTime != null)
|
if (visitTime != null)
|
||||||
_buildInfoRow(
|
InfoRow(
|
||||||
isVisitConfirmed ? '방문 완료' : '방문 예정',
|
label: isVisitConfirmed ? '방문 완료' : '방문 예정',
|
||||||
_formatFullDateTime(visitTime),
|
value: _formatFullDateTime(visitTime),
|
||||||
isDark,
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
),
|
),
|
||||||
if (recoTime != null)
|
if (recoTime != null)
|
||||||
_buildInfoRow(
|
InfoRow(
|
||||||
'추천 시각',
|
label: '추천 시각',
|
||||||
_formatFullDateTime(recoTime),
|
value: _formatFullDateTime(recoTime),
|
||||||
isDark,
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Wrap(
|
Wrap(
|
||||||
@@ -703,23 +711,6 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildInfoRow(String label, String value, bool isDark) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 80,
|
|
||||||
child: Text(label, style: AppTypography.caption(isDark)),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(child: Text(value, style: AppTypography.body2(isDark))),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _showRestaurantDetailDialog(
|
Future<void> _showRestaurantDetailDialog(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
bool isDark,
|
bool isDark,
|
||||||
@@ -737,18 +728,39 @@ class _CalendarScreenState extends ConsumerState<CalendarScreen>
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_buildInfoRow(
|
InfoRow(
|
||||||
'카테고리',
|
label: '카테고리',
|
||||||
'${restaurant.category} > ${restaurant.subCategory}',
|
value: '${restaurant.category} > ${restaurant.subCategory}',
|
||||||
isDark,
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
),
|
),
|
||||||
if (restaurant.phoneNumber != null)
|
if (restaurant.phoneNumber != null)
|
||||||
_buildInfoRow('전화번호', restaurant.phoneNumber!, isDark),
|
InfoRow(
|
||||||
_buildInfoRow('도로명', restaurant.roadAddress, isDark),
|
label: '전화번호',
|
||||||
_buildInfoRow('지번', restaurant.jibunAddress, isDark),
|
value: restaurant.phoneNumber!,
|
||||||
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
|
),
|
||||||
|
InfoRow(
|
||||||
|
label: '도로명',
|
||||||
|
value: restaurant.roadAddress,
|
||||||
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
|
),
|
||||||
|
InfoRow(
|
||||||
|
label: '지번',
|
||||||
|
value: restaurant.jibunAddress,
|
||||||
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
|
),
|
||||||
if (restaurant.description != null &&
|
if (restaurant.description != null &&
|
||||||
restaurant.description!.isNotEmpty)
|
restaurant.description!.isNotEmpty)
|
||||||
_buildInfoRow('메모', restaurant.description!, isDark),
|
InfoRow(
|
||||||
|
label: '메모',
|
||||||
|
value: restaurant.description!,
|
||||||
|
isDark: isDark,
|
||||||
|
horizontal: true,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../../core/constants/app_colors.dart';
|
import '../../../core/constants/app_colors.dart';
|
||||||
|
import '../../../core/constants/app_dimensions.dart';
|
||||||
import '../../../core/constants/app_typography.dart';
|
import '../../../core/constants/app_typography.dart';
|
||||||
import '../../../core/utils/category_mapper.dart';
|
import '../../../core/utils/category_mapper.dart';
|
||||||
import '../../../domain/entities/restaurant.dart';
|
import '../../../domain/entities/restaurant.dart';
|
||||||
@@ -306,8 +308,8 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
|||||||
child: Slider(
|
child: Slider(
|
||||||
value: _distanceValue,
|
value: _distanceValue,
|
||||||
min: 100,
|
min: 100,
|
||||||
max: 2000,
|
max: AppDimensions.maxSearchDistance,
|
||||||
divisions: 19,
|
divisions: AppDimensions.distanceSliderDivisions,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() => _distanceValue = value);
|
setState(() => _distanceValue = value);
|
||||||
},
|
},
|
||||||
@@ -739,6 +741,9 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
|||||||
}) async {
|
}) async {
|
||||||
if (_isProcessingRecommendation) return;
|
if (_isProcessingRecommendation) return;
|
||||||
|
|
||||||
|
// 버튼 터치 햅틱 피드백
|
||||||
|
HapticFeedback.mediumImpact();
|
||||||
|
|
||||||
if (!isReroll) {
|
if (!isReroll) {
|
||||||
_excludedRestaurantIds.clear();
|
_excludedRestaurantIds.clear();
|
||||||
}
|
}
|
||||||
@@ -769,6 +774,10 @@ class _RandomSelectionScreenState extends ConsumerState<RandomSelectionScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
|
|
||||||
|
// 추천 결과 햅틱 피드백
|
||||||
|
HapticFeedback.heavyImpact();
|
||||||
|
|
||||||
await _showRecommendationDialog(candidate, recommendedAt: recommendedAt);
|
await _showRecommendationDialog(candidate, recommendedAt: recommendedAt);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
_showSnack('추천을 준비하는 중 문제가 발생했습니다.', type: _SnackType.error);
|
_showSnack('추천을 준비하는 중 문제가 발생했습니다.', type: _SnackType.error);
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import '../../../core/constants/app_colors.dart';
|
import '../../../core/constants/app_colors.dart';
|
||||||
|
import '../../../core/constants/app_dimensions.dart';
|
||||||
import '../../../core/constants/app_typography.dart';
|
import '../../../core/constants/app_typography.dart';
|
||||||
|
import '../../../core/widgets/skeleton_loader.dart';
|
||||||
import '../../../core/utils/category_mapper.dart';
|
import '../../../core/utils/category_mapper.dart';
|
||||||
import '../../../core/utils/app_logger.dart';
|
import '../../../core/utils/app_logger.dart';
|
||||||
import '../../providers/restaurant_provider.dart';
|
import '../../providers/restaurant_provider.dart';
|
||||||
import '../../providers/settings_provider.dart';
|
import '../../providers/settings_provider.dart';
|
||||||
|
import '../../providers/visit_provider.dart';
|
||||||
import '../../widgets/category_selector.dart';
|
import '../../widgets/category_selector.dart';
|
||||||
import '../../widgets/native_ad_placeholder.dart';
|
import '../../widgets/native_ad_placeholder.dart';
|
||||||
import 'manual_restaurant_input_screen.dart';
|
import 'manual_restaurant_input_screen.dart';
|
||||||
@@ -40,6 +43,8 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
|||||||
.maybeWhen(data: (value) => value, orElse: () => false);
|
.maybeWhen(data: (value) => value, orElse: () => false);
|
||||||
final isFiltered = searchQuery.isNotEmpty || selectedCategory != null;
|
final isFiltered = searchQuery.isNotEmpty || selectedCategory != null;
|
||||||
final restaurantsAsync = ref.watch(sortedRestaurantsByDistanceProvider);
|
final restaurantsAsync = ref.watch(sortedRestaurantsByDistanceProvider);
|
||||||
|
final lastVisitDates =
|
||||||
|
ref.watch(allLastVisitDatesProvider).valueOrNull ?? {};
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: isDark
|
backgroundColor: isDark
|
||||||
@@ -70,6 +75,7 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
|||||||
if (_isSearching) ...[
|
if (_isSearching) ...[
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
|
tooltip: '검색 닫기',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSearching = false;
|
_isSearching = false;
|
||||||
@@ -81,6 +87,7 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
|||||||
] else ...[
|
] else ...[
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.search),
|
icon: const Icon(Icons.search),
|
||||||
|
tooltip: '맛집 검색',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSearching = true;
|
_isSearching = true;
|
||||||
@@ -149,8 +156,8 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
|||||||
return _buildEmptyState(isDark);
|
return _buildEmptyState(isDark);
|
||||||
}
|
}
|
||||||
|
|
||||||
const adInterval = 6; // 5리스트 후 1광고
|
const adInterval = AppDimensions.adInterval;
|
||||||
const adOffset = 5; // 1~5 리스트 이후 6 광고 시작
|
const adOffset = AppDimensions.adOffset;
|
||||||
final adCount = (items.length ~/ adOffset);
|
final adCount = (items.length ~/ adOffset);
|
||||||
final totalCount = items.length + adCount;
|
final totalCount = items.length + adCount;
|
||||||
|
|
||||||
@@ -180,48 +187,70 @@ class _RestaurantListScreenState extends ConsumerState<RestaurantListScreen> {
|
|||||||
return RestaurantCard(
|
return RestaurantCard(
|
||||||
restaurant: item.restaurant,
|
restaurant: item.restaurant,
|
||||||
distanceKm: item.distanceKm,
|
distanceKm: item.distanceKm,
|
||||||
|
lastVisitDate: lastVisitDates[item.restaurant.id],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
loading: () {
|
loading: () {
|
||||||
AppLogger.debug('[restaurant_list_ui] loading...');
|
AppLogger.debug('[restaurant_list_ui] loading...');
|
||||||
return const Center(
|
return const RestaurantListSkeleton();
|
||||||
child: CircularProgressIndicator(
|
|
||||||
color: AppColors.lightPrimary,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
error: (error, stack) => Center(
|
error: (error, stack) => Center(
|
||||||
child: Column(
|
child: Padding(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
padding: const EdgeInsets.all(AppDimensions.paddingDefault),
|
||||||
children: [
|
child: Column(
|
||||||
Icon(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
Icons.error_outline,
|
children: [
|
||||||
size: 64,
|
Icon(
|
||||||
color: isDark
|
Icons.error_outline,
|
||||||
? AppColors.darkError
|
size: AppDimensions.iconXxl,
|
||||||
: AppColors.lightError,
|
color: isDark
|
||||||
),
|
? AppColors.darkError
|
||||||
const SizedBox(height: 16),
|
: AppColors.lightError,
|
||||||
Text('오류가 발생했습니다', style: AppTypography.heading2(isDark)),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: AppDimensions.paddingDefault),
|
||||||
Text(
|
Text('오류가 발생했습니다', style: AppTypography.heading2(isDark)),
|
||||||
error.toString(),
|
const SizedBox(height: AppDimensions.paddingSm),
|
||||||
style: AppTypography.body2(isDark),
|
Text(
|
||||||
textAlign: TextAlign.center,
|
error.toString(),
|
||||||
),
|
style: AppTypography.body2(isDark),
|
||||||
],
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 3,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
const SizedBox(height: AppDimensions.paddingLg),
|
||||||
|
ElevatedButton.icon(
|
||||||
|
onPressed: () =>
|
||||||
|
ref.invalidate(sortedRestaurantsByDistanceProvider),
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: AppColors.lightPrimary,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: AppDimensions.paddingXl,
|
||||||
|
vertical: AppDimensions.paddingMd,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
label: const Text('다시 시도'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: Semantics(
|
||||||
onPressed: _showAddOptions,
|
label: '맛집 추가하기',
|
||||||
backgroundColor: AppColors.lightPrimary,
|
button: true,
|
||||||
child: const Icon(Icons.add, color: Colors.white),
|
child: FloatingActionButton(
|
||||||
|
onPressed: _showAddOptions,
|
||||||
|
tooltip: '맛집 추가',
|
||||||
|
backgroundColor: AppColors.lightPrimary,
|
||||||
|
child: const Icon(Icons.add, color: Colors.white),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,28 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:lunchpick/core/constants/app_colors.dart';
|
import 'package:lunchpick/core/constants/app_colors.dart';
|
||||||
import 'package:lunchpick/core/constants/app_typography.dart';
|
import 'package:lunchpick/core/constants/app_typography.dart';
|
||||||
|
import 'package:lunchpick/core/widgets/info_row.dart';
|
||||||
import 'package:lunchpick/domain/entities/restaurant.dart';
|
import 'package:lunchpick/domain/entities/restaurant.dart';
|
||||||
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
|
import 'package:lunchpick/presentation/providers/restaurant_provider.dart';
|
||||||
import 'package:lunchpick/presentation/providers/visit_provider.dart';
|
|
||||||
import 'edit_restaurant_dialog.dart';
|
import 'edit_restaurant_dialog.dart';
|
||||||
|
|
||||||
|
/// 맛집 카드 위젯
|
||||||
|
/// [lastVisitDate]를 외부에서 주입받아 리스트 렌더링 최적화
|
||||||
class RestaurantCard extends ConsumerWidget {
|
class RestaurantCard extends ConsumerWidget {
|
||||||
final Restaurant restaurant;
|
final Restaurant restaurant;
|
||||||
final double? distanceKm;
|
final double? distanceKm;
|
||||||
|
final DateTime? lastVisitDate;
|
||||||
|
|
||||||
const RestaurantCard({super.key, required this.restaurant, this.distanceKm});
|
const RestaurantCard({
|
||||||
|
super.key,
|
||||||
|
required this.restaurant,
|
||||||
|
this.distanceKm,
|
||||||
|
this.lastVisitDate,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
final lastVisitAsync = ref.watch(lastVisitDateProvider(restaurant.id));
|
|
||||||
|
|
||||||
return Card(
|
return Card(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
@@ -177,39 +184,26 @@ class RestaurantCard extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
|
|
||||||
// 마지막 방문일
|
// 마지막 방문일
|
||||||
lastVisitAsync.when(
|
if (lastVisitDate != null)
|
||||||
data: (lastVisit) {
|
Padding(
|
||||||
if (lastVisit != null) {
|
padding: const EdgeInsets.only(top: 8),
|
||||||
final daysSinceVisit = DateTime.now()
|
child: Row(
|
||||||
.difference(lastVisit)
|
children: [
|
||||||
.inDays;
|
Icon(
|
||||||
return Padding(
|
Icons.schedule,
|
||||||
padding: const EdgeInsets.only(top: 8),
|
size: 16,
|
||||||
child: Row(
|
color: isDark
|
||||||
children: [
|
? AppColors.darkTextSecondary
|
||||||
Icon(
|
: AppColors.lightTextSecondary,
|
||||||
Icons.schedule,
|
|
||||||
size: 16,
|
|
||||||
color: isDark
|
|
||||||
? AppColors.darkTextSecondary
|
|
||||||
: AppColors.lightTextSecondary,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text(
|
|
||||||
daysSinceVisit == 0
|
|
||||||
? '오늘 방문'
|
|
||||||
: '$daysSinceVisit일 전 방문',
|
|
||||||
style: AppTypography.caption(isDark),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
const SizedBox(width: 4),
|
||||||
}
|
Text(
|
||||||
return const SizedBox.shrink();
|
_formatLastVisit(lastVisitDate!),
|
||||||
},
|
style: AppTypography.caption(isDark),
|
||||||
loading: () => const SizedBox.shrink(),
|
),
|
||||||
error: (_, __) => const SizedBox.shrink(),
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -240,6 +234,11 @@ class RestaurantCard extends ConsumerWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _formatLastVisit(DateTime date) {
|
||||||
|
final daysSinceVisit = DateTime.now().difference(date).inDays;
|
||||||
|
return daysSinceVisit == 0 ? '오늘 방문' : '$daysSinceVisit일 전 방문';
|
||||||
|
}
|
||||||
|
|
||||||
void _showRestaurantDetail(BuildContext context, bool isDark) {
|
void _showRestaurantDetail(BuildContext context, bool isDark) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -252,22 +251,22 @@ class RestaurantCard extends ConsumerWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_buildDetailRow(
|
InfoRow(
|
||||||
'카테고리',
|
label: '카테고리',
|
||||||
'${restaurant.category} > ${restaurant.subCategory}',
|
value: '${restaurant.category} > ${restaurant.subCategory}',
|
||||||
isDark,
|
isDark: isDark,
|
||||||
),
|
),
|
||||||
if (restaurant.description != null)
|
if (restaurant.description != null)
|
||||||
_buildDetailRow('설명', restaurant.description!, isDark),
|
InfoRow(label: '설명', value: restaurant.description!, isDark: isDark),
|
||||||
if (restaurant.phoneNumber != null)
|
if (restaurant.phoneNumber != null)
|
||||||
_buildDetailRow('전화번호', restaurant.phoneNumber!, isDark),
|
InfoRow(label: '전화번호', value: restaurant.phoneNumber!, isDark: isDark),
|
||||||
_buildDetailRow('도로명 주소', restaurant.roadAddress, isDark),
|
InfoRow(label: '도로명 주소', value: restaurant.roadAddress, isDark: isDark),
|
||||||
_buildDetailRow('지번 주소', restaurant.jibunAddress, isDark),
|
InfoRow(label: '지번 주소', value: restaurant.jibunAddress, isDark: isDark),
|
||||||
if (restaurant.lastVisitDate != null)
|
if (restaurant.lastVisitDate != null)
|
||||||
_buildDetailRow(
|
InfoRow(
|
||||||
'마지막 방문',
|
label: '마지막 방문',
|
||||||
'${restaurant.lastVisitDate!.year}년 ${restaurant.lastVisitDate!.month}월 ${restaurant.lastVisitDate!.day}일',
|
value: '${restaurant.lastVisitDate!.year}년 ${restaurant.lastVisitDate!.month}월 ${restaurant.lastVisitDate!.day}일',
|
||||||
isDark,
|
isDark: isDark,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -281,20 +280,6 @@ class RestaurantCard extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDetailRow(String label, String value, bool isDark) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(label, style: AppTypography.caption(isDark)),
|
|
||||||
const SizedBox(height: 2),
|
|
||||||
Text(value, style: AppTypography.body2(isDark)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleMenuAction(
|
void _handleMenuAction(
|
||||||
_RestaurantMenuAction action,
|
_RestaurantMenuAction action,
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
|
|||||||
@@ -15,10 +15,8 @@ class SplashScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SplashScreenState extends State<SplashScreen>
|
class _SplashScreenState extends State<SplashScreen>
|
||||||
with TickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late List<AnimationController> _foodControllers;
|
late AnimationController _animationController;
|
||||||
late AnimationController _questionMarkController;
|
|
||||||
late AnimationController _centerIconController;
|
|
||||||
List<Offset>? _iconPositions;
|
List<Offset>? _iconPositions;
|
||||||
Size? _lastScreenSize;
|
Size? _lastScreenSize;
|
||||||
|
|
||||||
@@ -42,24 +40,9 @@ class _SplashScreenState extends State<SplashScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _initializeAnimations() {
|
void _initializeAnimations() {
|
||||||
// 음식 아이콘 애니메이션 (여러 개)
|
// 단일 컨트롤러로 모든 애니메이션 제어 (메모리 최적화)
|
||||||
_foodControllers = List.generate(
|
_animationController = AnimationController(
|
||||||
foodIcons.length,
|
duration: const Duration(seconds: 2),
|
||||||
(index) => AnimationController(
|
|
||||||
duration: Duration(seconds: 2 + index % 3),
|
|
||||||
vsync: this,
|
|
||||||
)..repeat(reverse: true),
|
|
||||||
);
|
|
||||||
|
|
||||||
// 물음표 애니메이션
|
|
||||||
_questionMarkController = AnimationController(
|
|
||||||
duration: const Duration(milliseconds: 500),
|
|
||||||
vsync: this,
|
|
||||||
)..repeat();
|
|
||||||
|
|
||||||
// 중앙 아이콘 애니메이션
|
|
||||||
_centerIconController = AnimationController(
|
|
||||||
duration: const Duration(seconds: 1),
|
|
||||||
vsync: this,
|
vsync: this,
|
||||||
)..repeat(reverse: true);
|
)..repeat(reverse: true);
|
||||||
}
|
}
|
||||||
@@ -142,9 +125,9 @@ class _SplashScreenState extends State<SplashScreen>
|
|||||||
children: [
|
children: [
|
||||||
// 선택 아이콘
|
// 선택 아이콘
|
||||||
ScaleTransition(
|
ScaleTransition(
|
||||||
scale: Tween(begin: 0.8, end: 1.2).animate(
|
scale: Tween(begin: 0.9, end: 1.1).animate(
|
||||||
CurvedAnimation(
|
CurvedAnimation(
|
||||||
parent: _centerIconController,
|
parent: _animationController,
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -164,11 +147,11 @@ class _SplashScreenState extends State<SplashScreen>
|
|||||||
children: [
|
children: [
|
||||||
Text('오늘 뭐 먹Z', style: AppTypography.heading1(isDark)),
|
Text('오늘 뭐 먹Z', style: AppTypography.heading1(isDark)),
|
||||||
AnimatedBuilder(
|
AnimatedBuilder(
|
||||||
animation: _questionMarkController,
|
animation: _animationController,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
final questionMarks =
|
final questionMarks =
|
||||||
'?' *
|
'?' *
|
||||||
(((_questionMarkController.value * 3).floor() % 3) +
|
(((_animationController.value * 3).floor() % 3) +
|
||||||
1);
|
1);
|
||||||
return Text(
|
return Text(
|
||||||
questionMarks,
|
questionMarks,
|
||||||
@@ -217,29 +200,30 @@ class _SplashScreenState extends State<SplashScreen>
|
|||||||
|
|
||||||
return List.generate(foodIcons.length, (index) {
|
return List.generate(foodIcons.length, (index) {
|
||||||
final position = _iconPositions![index];
|
final position = _iconPositions![index];
|
||||||
|
// 각 아이콘마다 위상(phase)을 다르게 적용
|
||||||
|
final phase = index / foodIcons.length;
|
||||||
|
|
||||||
return Positioned(
|
return Positioned(
|
||||||
left: position.dx,
|
left: position.dx,
|
||||||
top: position.dy,
|
top: position.dy,
|
||||||
child: FadeTransition(
|
child: AnimatedBuilder(
|
||||||
opacity: Tween(begin: 0.2, end: 0.8).animate(
|
animation: _animationController,
|
||||||
CurvedAnimation(
|
builder: (context, child) {
|
||||||
parent: _foodControllers[index],
|
// 위상 차이로 각 아이콘이 다른 타이밍에 애니메이션
|
||||||
curve: Curves.easeInOut,
|
final value =
|
||||||
),
|
((_animationController.value + phase) % 1.0 - 0.5).abs() * 2;
|
||||||
),
|
return Opacity(
|
||||||
child: ScaleTransition(
|
opacity: 0.2 + value * 0.4,
|
||||||
scale: Tween(begin: 0.5, end: 1.5).animate(
|
child: Transform.scale(
|
||||||
CurvedAnimation(
|
scale: 0.7 + value * 0.5,
|
||||||
parent: _foodControllers[index],
|
child: child,
|
||||||
curve: Curves.easeInOut,
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
child: Icon(
|
},
|
||||||
foodIcons[index],
|
child: Icon(
|
||||||
size: 40,
|
foodIcons[index],
|
||||||
color: AppColors.lightPrimary.withOpacity(0.3),
|
size: 40,
|
||||||
),
|
color: AppColors.lightPrimary.withValues(alpha: 0.3),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -274,11 +258,7 @@ class _SplashScreenState extends State<SplashScreen>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
for (final controller in _foodControllers) {
|
_animationController.dispose();
|
||||||
controller.dispose();
|
|
||||||
}
|
|
||||||
_questionMarkController.dispose();
|
|
||||||
_centerIconController.dispose();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,6 +157,23 @@ final lastVisitDateProvider = FutureProvider.family<DateTime?, String>((
|
|||||||
return repository.getLastVisitDate(restaurantId);
|
return repository.getLastVisitDate(restaurantId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// 모든 맛집의 마지막 방문일을 한 번에 조회 (리스트 최적화용)
|
||||||
|
final allLastVisitDatesProvider =
|
||||||
|
FutureProvider<Map<String, DateTime?>>((ref) async {
|
||||||
|
final records = await ref.watch(visitRecordsProvider.future);
|
||||||
|
|
||||||
|
// restaurantId별 가장 최근 방문일 계산
|
||||||
|
final lastVisitMap = <String, DateTime>{};
|
||||||
|
for (final record in records) {
|
||||||
|
final existing = lastVisitMap[record.restaurantId];
|
||||||
|
if (existing == null || record.visitDate.isAfter(existing)) {
|
||||||
|
lastVisitMap[record.restaurantId] = record.visitDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastVisitMap;
|
||||||
|
});
|
||||||
|
|
||||||
/// 기간별 방문 기록 Provider
|
/// 기간별 방문 기록 Provider
|
||||||
final visitRecordsByPeriodProvider =
|
final visitRecordsByPeriodProvider =
|
||||||
FutureProvider.family<
|
FutureProvider.family<
|
||||||
|
|||||||
@@ -144,19 +144,22 @@ class _NativeAdPlaceholderState extends State<NativeAdPlaceholder> {
|
|||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
return NativeTemplateStyle(
|
return NativeTemplateStyle(
|
||||||
templateType: templateType,
|
templateType: templateType,
|
||||||
mainBackgroundColor: isDark ? AppColors.darkSurface : Colors.white,
|
mainBackgroundColor:
|
||||||
|
isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||||
cornerRadius: 0,
|
cornerRadius: 0,
|
||||||
callToActionTextStyle: NativeTemplateTextStyle(
|
callToActionTextStyle: NativeTemplateTextStyle(
|
||||||
textColor: Colors.white,
|
textColor: AppColors.lightSurface,
|
||||||
backgroundColor: AppColors.lightPrimary,
|
backgroundColor: AppColors.lightPrimary,
|
||||||
style: NativeTemplateFontStyle.bold,
|
style: NativeTemplateFontStyle.bold,
|
||||||
),
|
),
|
||||||
primaryTextStyle: NativeTemplateTextStyle(
|
primaryTextStyle: NativeTemplateTextStyle(
|
||||||
textColor: isDark ? Colors.white : Colors.black87,
|
textColor:
|
||||||
|
isDark ? AppColors.darkTextPrimary : AppColors.lightTextPrimary,
|
||||||
style: NativeTemplateFontStyle.bold,
|
style: NativeTemplateFontStyle.bold,
|
||||||
),
|
),
|
||||||
secondaryTextStyle: NativeTemplateTextStyle(
|
secondaryTextStyle: NativeTemplateTextStyle(
|
||||||
textColor: isDark ? Colors.white70 : Colors.black54,
|
textColor:
|
||||||
|
isDark ? AppColors.darkTextSecondary : AppColors.lightTextSecondary,
|
||||||
style: NativeTemplateFontStyle.normal,
|
style: NativeTemplateFontStyle.normal,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -250,14 +253,15 @@ class _NativeAdPlaceholderState extends State<NativeAdPlaceholder> {
|
|||||||
|
|
||||||
BoxDecoration _decoration(bool isDark) {
|
BoxDecoration _decoration(bool isDark) {
|
||||||
return BoxDecoration(
|
return BoxDecoration(
|
||||||
color: isDark ? AppColors.darkSurface : Colors.white,
|
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
color: isDark ? AppColors.darkDivider : AppColors.lightDivider,
|
||||||
width: 2,
|
width: 2,
|
||||||
),
|
),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: (isDark ? Colors.black : Colors.grey).withOpacity(0.08),
|
color: (isDark ? AppColors.darkBackground : AppColors.lightDivider)
|
||||||
|
.withValues(alpha: 0.3),
|
||||||
blurRadius: 8,
|
blurRadius: 8,
|
||||||
offset: const Offset(0, 4),
|
offset: const Offset(0, 4),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user