fix(ad): 스크린샷 모드에서 네이티브 광고 비활성화

This commit is contained in:
JiWoong Sul
2025-12-04 16:29:32 +09:00
parent 04b1c3e987
commit bcc26f5e79
11 changed files with 1037 additions and 230 deletions

View File

@@ -8,8 +8,17 @@ import 'package:lunchpick/presentation/widgets/native_ad_placeholder.dart';
class VisitStatistics extends ConsumerWidget {
final DateTime selectedMonth;
final List<DateTime> availableMonths;
final void Function(DateTime month) onMonthChanged;
final bool adsEnabled;
const VisitStatistics({super.key, required this.selectedMonth});
const VisitStatistics({
super.key,
required this.selectedMonth,
required this.availableMonths,
required this.onMonthChanged,
this.adsEnabled = true,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -47,7 +56,7 @@ class VisitStatistics extends ConsumerWidget {
),
const SizedBox(height: 16),
const NativeAdPlaceholder(height: 360),
NativeAdPlaceholder(height: 360, enabled: adsEnabled),
const SizedBox(height: 16),
// 주간 통계 차트
@@ -66,6 +75,8 @@ class VisitStatistics extends ConsumerWidget {
AsyncValue<Map<String, int>> categoryStatsAsync,
bool isDark,
) {
final monthList = _normalizeMonths();
return Card(
color: isDark ? AppColors.darkSurface : AppColors.lightSurface,
elevation: 2,
@@ -75,10 +86,7 @@ class VisitStatistics extends ConsumerWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${selectedMonth.month}월 방문 통계',
style: AppTypography.heading2(isDark),
),
_buildMonthSelector(monthList, isDark),
const SizedBox(height: 16),
statsAsync.when(
data: (stats) {
@@ -357,4 +365,79 @@ class VisitStatistics extends ConsumerWidget {
],
);
}
Widget _buildMonthSelector(List<DateTime> months, bool isDark) {
final currentMonth = DateTime(selectedMonth.year, selectedMonth.month, 1);
final monthIndex = months.indexWhere(
(month) => _isSameMonth(month, currentMonth),
);
final resolvedIndex = monthIndex == -1 ? 0 : monthIndex;
final hasPrevious = resolvedIndex < months.length - 1;
final hasNext = resolvedIndex > 0;
return Row(
children: [
Expanded(
child: Text(
'${_formatMonth(currentMonth)} 방문 통계',
style: AppTypography.heading2(isDark),
overflow: TextOverflow.ellipsis,
),
),
IconButton(
onPressed: hasPrevious
? () => onMonthChanged(months[resolvedIndex + 1])
: null,
icon: const Icon(Icons.chevron_left),
),
DropdownButtonHideUnderline(
child: DropdownButton<DateTime>(
value: months[resolvedIndex],
onChanged: (month) {
if (month != null) {
onMonthChanged(month);
}
},
items: months
.map(
(month) => DropdownMenuItem(
value: month,
child: Text(_formatMonth(month)),
),
)
.toList(),
),
),
IconButton(
onPressed: hasNext
? () => onMonthChanged(months[resolvedIndex - 1])
: null,
icon: const Icon(Icons.chevron_right),
),
],
);
}
List<DateTime> _normalizeMonths() {
final normalized =
availableMonths
.map((month) => DateTime(month.year, month.month, 1))
.toSet()
.toList()
..sort((a, b) => b.compareTo(a));
final currentMonth = DateTime(selectedMonth.year, selectedMonth.month, 1);
final exists = normalized.any((month) => _isSameMonth(month, currentMonth));
if (!exists) {
normalized.insert(0, currentMonth);
}
return normalized;
}
bool _isSameMonth(DateTime a, DateTime b) =>
a.year == b.year && a.month == b.month;
String _formatMonth(DateTime month) =>
'${month.year}.${month.month.toString().padLeft(2, '0')}';
}