fix(ad): 네이티브 템플릿 높이 보정
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||||
import 'package:lunchpick/core/constants/app_colors.dart';
|
import 'package:lunchpick/core/constants/app_colors.dart';
|
||||||
@@ -18,7 +19,7 @@ class NativeAdPlaceholder extends StatefulWidget {
|
|||||||
const NativeAdPlaceholder({
|
const NativeAdPlaceholder({
|
||||||
super.key,
|
super.key,
|
||||||
this.margin,
|
this.margin,
|
||||||
this.height = 200,
|
this.height = 360,
|
||||||
this.refreshInterval = const Duration(minutes: 2),
|
this.refreshInterval = const Duration(minutes: 2),
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
});
|
});
|
||||||
@@ -155,21 +156,29 @@ class _NativeAdPlaceholderState extends State<NativeAdPlaceholder> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||||
|
final containerHeight = _resolveContainerHeight();
|
||||||
|
|
||||||
if (!AdHelper.isMobilePlatform || !widget.enabled) {
|
if (!AdHelper.isMobilePlatform || !widget.enabled) {
|
||||||
return _buildPlaceholder(isDark, isLoading: false);
|
return _buildPlaceholder(
|
||||||
|
isDark,
|
||||||
|
containerHeight: containerHeight,
|
||||||
|
isLoading: false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return AnimatedSwitcher(
|
return AnimatedSwitcher(
|
||||||
duration: const Duration(milliseconds: 250),
|
duration: const Duration(milliseconds: 250),
|
||||||
child: _isLoaded && _nativeAd != null
|
child: _isLoaded && _nativeAd != null
|
||||||
? _buildAdView(isDark)
|
? _buildAdView(isDark, containerHeight)
|
||||||
: _buildPlaceholder(isDark, isLoading: _isLoading),
|
: _buildPlaceholder(
|
||||||
|
isDark,
|
||||||
|
containerHeight: containerHeight,
|
||||||
|
isLoading: _isLoading,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAdView(bool isDark) {
|
Widget _buildAdView(bool isDark, double containerHeight) {
|
||||||
final containerHeight = max(widget.height, 200.0);
|
|
||||||
return Container(
|
return Container(
|
||||||
key: const ValueKey('nativeAdLoaded'),
|
key: const ValueKey('nativeAdLoaded'),
|
||||||
margin: widget.margin ?? EdgeInsets.zero,
|
margin: widget.margin ?? EdgeInsets.zero,
|
||||||
@@ -180,8 +189,11 @@ class _NativeAdPlaceholderState extends State<NativeAdPlaceholder> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPlaceholder(bool isDark, {required bool isLoading}) {
|
Widget _buildPlaceholder(
|
||||||
final containerHeight = max(widget.height, 200.0);
|
bool isDark, {
|
||||||
|
required double containerHeight,
|
||||||
|
required bool isLoading,
|
||||||
|
}) {
|
||||||
return Container(
|
return Container(
|
||||||
key: const ValueKey('nativeAdPlaceholder'),
|
key: const ValueKey('nativeAdPlaceholder'),
|
||||||
margin: widget.margin ?? EdgeInsets.zero,
|
margin: widget.margin ?? EdgeInsets.zero,
|
||||||
@@ -205,6 +217,18 @@ class _NativeAdPlaceholderState extends State<NativeAdPlaceholder> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double _resolveContainerHeight() {
|
||||||
|
final platformMinHeight = switch (defaultTargetPlatform) {
|
||||||
|
TargetPlatform.iOS => 402.0,
|
||||||
|
TargetPlatform.android => 350.0,
|
||||||
|
_ => 320.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 네이티브 템플릿(Medium) 기본 레이아웃이 플랫폼별로 350~402dp를 요구해
|
||||||
|
// 호출자가 지정한 높이보다 작을 경우 클리핑을 막기 위해 최소 높이를 강제한다.
|
||||||
|
return max(widget.height, platformMinHeight);
|
||||||
|
}
|
||||||
|
|
||||||
BoxDecoration _decoration(bool isDark) {
|
BoxDecoration _decoration(bool isDark) {
|
||||||
return BoxDecoration(
|
return BoxDecoration(
|
||||||
color: isDark ? AppColors.darkSurface : Colors.white,
|
color: isDark ? AppColors.darkSurface : Colors.white,
|
||||||
|
|||||||
Reference in New Issue
Block a user