feat: adopt material 3 theme and billing adjustments

This commit is contained in:
JiWoong Sul
2025-09-16 14:30:14 +09:00
parent a01d9092ba
commit 44850a53cc
85 changed files with 2957 additions and 2776 deletions

View File

@@ -2,13 +2,17 @@ import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'dart:io' show Platform;
import 'glassmorphism_card.dart';
import 'dart:async';
// Glass 제거: Material 3 Card 사용
import '../main.dart' show enableAdMob;
import '../theme/ui_constants.dart';
/// 구글 네이티브 광고 위젯 (AdMob NativeAd)
/// SRP에 따라 광고 전용 위젯으로 분리
class NativeAdWidget extends StatefulWidget {
const NativeAdWidget({Key? key}) : super(key: key);
final bool useOuterPadding; // true이면 외부에서 페이지 패딩을 제공
const NativeAdWidget({Key? key, this.useOuterPadding = false})
: super(key: key);
@override
State<NativeAdWidget> createState() => _NativeAdWidgetState();
@@ -19,6 +23,7 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
bool _isLoaded = false;
String? _error;
bool _isAdLoading = false; // 광고 로드 중복 방지 플래그
Timer? _refreshTimer; // 주기적 리프레시 타이머
@override
void initState() {
@@ -43,24 +48,66 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
return;
}
_nativeAd = NativeAd(
adUnitId: _testAdUnitId(), // 실제 광고 단위 ID
factoryId: 'listTile', // Android/iOS 모두 동일하게 맞춰야 함
request: const AdRequest(),
listener: NativeAdListener(
onAdLoaded: (ad) {
setState(() {
_isLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
ad.dispose();
setState(() {
_error = error.message;
});
},
),
)..load();
try {
// 기존 광고 해제 및 상태 초기화
_refreshTimer?.cancel();
_nativeAd?.dispose();
_error = null;
_isLoaded = false;
_nativeAd = NativeAd(
adUnitId: _testAdUnitId(), // 실제 광고 단위 ID
// 네이티브 템플릿을 사용하면 NativeAdFactory 등록 없이도 동작합니다.
nativeTemplateStyle: NativeTemplateStyle(
templateType: TemplateType.small,
mainBackgroundColor: const Color(0x00000000),
cornerRadius: 12,
),
request: const AdRequest(),
listener: NativeAdListener(
onAdLoaded: (ad) {
setState(() {
_isLoaded = true;
});
_scheduleRefresh();
},
onAdFailedToLoad: (ad, error) {
ad.dispose();
setState(() {
_error = error.message;
});
// 실패 시에도 일정 시간 후 재시도
_scheduleRefresh();
},
),
)..load();
} catch (e) {
// 템플릿 미지원 등 예외 시 광고를 비활성화하고 크래시 방지
setState(() {
_error = e.toString();
});
_scheduleRefresh();
}
}
/// 30초 후 새 광고로 교체
void _scheduleRefresh() {
_refreshTimer?.cancel();
_refreshTimer = Timer(const Duration(seconds: 30), _refreshAd);
}
void _refreshAd() {
if (!mounted) return;
// 다음 로드를 위해 상태 초기화 후 새 광고 요청
try {
_nativeAd?.dispose();
} catch (_) {}
setState(() {
_nativeAd = null;
_isLoaded = false;
_error = null;
});
_loadAd();
}
/// 광고 단위 ID 반환 함수
@@ -79,19 +126,25 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
@override
void dispose() {
_nativeAd?.dispose();
_refreshTimer?.cancel();
super.dispose();
}
/// 웹용 광고 플레이스홀더 위젯
Widget _buildWebPlaceholder() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: GlassmorphismCard(
borderRadius: 16,
blur: 10,
opacity: 0.1,
padding: EdgeInsets.symmetric(
horizontal:
widget.useOuterPadding ? 0 : UIConstants.pageHorizontalPadding,
vertical: UIConstants.adVerticalPadding,
),
child: Card(
elevation: 1,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: Container(
height: 80,
height: UIConstants.adCardHeight,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row(
children: [
@@ -99,13 +152,16 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
width: 64,
height: 64,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(8),
color: Theme.of(context)
.colorScheme
.surfaceContainerHighest
.withValues(alpha: 0.5),
borderRadius: BorderRadius.zero,
),
child: const Center(
child: Center(
child: Icon(
Icons.ad_units,
color: Colors.grey,
color: Theme.of(context).colorScheme.onSurfaceVariant,
size: 32,
),
),
@@ -120,8 +176,11 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
height: 14,
width: 120,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(4),
color: Theme.of(context)
.colorScheme
.surfaceContainerHighest
.withValues(alpha: 0.5),
borderRadius: BorderRadius.zero,
),
),
const SizedBox(height: 8),
@@ -129,8 +188,11 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
height: 10,
width: 180,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(4),
color: Theme.of(context)
.colorScheme
.surfaceContainerHighest
.withValues(alpha: 0.4),
borderRadius: BorderRadius.zero,
),
),
],
@@ -140,15 +202,18 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
width: 60,
height: 24,
decoration: BoxDecoration(
color: Colors.blue[100],
borderRadius: BorderRadius.circular(12),
color: Theme.of(context)
.colorScheme
.primary
.withValues(alpha: 0.15),
borderRadius: BorderRadius.zero,
),
child: const Center(
child: Center(
child: Text(
'광고영역',
'ads',
style: TextStyle(
fontSize: 12,
color: Colors.blue,
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
@@ -179,27 +244,29 @@ class _NativeAdWidgetState extends State<NativeAdWidget> {
}
if (_error != null) {
// 광고 로드 실패 시 빈 공간 반환
return const SizedBox.shrink();
// 실패 시에도 동일 높이의 플레이스홀더를 유지하여 레이아웃 점프 방지
return _buildWebPlaceholder();
}
if (!_isLoaded) {
// 광고 로딩 중 로딩 인디케이터 표시
return const Padding(
padding: EdgeInsets.symmetric(vertical: 12),
child: Center(child: CircularProgressIndicator()),
);
// 로딩 중에도 실제 광고와 동일한 높이의 스켈레톤을 유지
return _buildWebPlaceholder();
}
// 광고 정상 노출
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
child: GlassmorphismCard(
borderRadius: 16,
blur: 10,
opacity: 0.1,
padding: EdgeInsets.symmetric(
horizontal:
widget.useOuterPadding ? 0 : UIConstants.pageHorizontalPadding,
vertical: UIConstants.adVerticalPadding,
),
child: Card(
elevation: 1,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: SizedBox(
height: 80, // 네이티브 광고 높이 조정
height: UIConstants.adCardHeight,
child: AdWidget(ad: _nativeAd!),
),
),