import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import '../config/config.dart'; // ================== 기존 코드 (전체 주석 처리) ================== class AdBannerWidget extends StatefulWidget { const AdBannerWidget({Key? key}) : super(key: key); @override State createState() => _AdBannerWidgetState(); } class _AdBannerWidgetState extends State { BannerAd? _bannerAd; // 광고 객체 @override void initState() { super.initState(); _initBannerAd(); } @override void dispose() { _bannerAd?.dispose(); super.dispose(); } /// 배너 광고를 초기화 & 로드 void _initBannerAd() { _bannerAd = BannerAd( size: AdSize.banner, // 배너 사이즈(고정) adUnitId: Config.adUnitId, // 광고 단위 ID (Config에서 직접 가져옴) listener: BannerAdListener( onAdLoaded: (Ad ad) { // 로드 성공 시: _bannerAd를 그대로 두면 됨. setState(() {/* 굳이 아무 것도 안 해도 됨 */}); }, onAdFailedToLoad: (Ad ad, LoadAdError error) { // 실패 시: 자원 정리 & null 처리 ad.dispose(); setState(() { _bannerAd = null; }); }, ), request: const AdRequest(), ); // 실제 로드 시작 _bannerAd!.load(); } @override Widget build(BuildContext context) { // 로딩 전/실패 시 _bannerAd가 null → 빈 위젯 반환 if (_bannerAd == null) { return const SizedBox.shrink(); } // 로딩 완료 시 Container에 AdWidget으로 표시 return Container( color: Colors.white, // 배경색 흰색으로 고정 width: _bannerAd!.size.width.toDouble(), height: _bannerAd!.size.height.toDouble(), child: AdWidget(ad: _bannerAd!), ); } } // ================== 임시/빈 컴포넌트 ================== // class AdBannerWidget extends StatelessWidget { // const AdBannerWidget({Key? key}) : super(key: key); // @override // Widget build(BuildContext context) { // // (예시) 50dp 높이의 빈 영역을 차지 // // or return SizedBox.shrink() 로 아예 공간을 안 쓰는 방법도 가능 // return const SizedBox( // height: 50, // 원하는 높이 // child: ColoredBox(color: Colors.white), // 배경 흰색 // ); // } // }