feat(ads): ad id config with test/real switch via dart-define

This commit is contained in:
2026-06-13 13:46:44 +09:00
parent 947d5566a2
commit eb258c7324
+56
View File
@@ -0,0 +1,56 @@
// lib/services/ad_config.dart
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
/// Ad-unit and app IDs. Dev/test builds use Google's official sample IDs,
/// which serve real test ads and never trigger an AdMob policy strike. The
/// owner replaces the `_real*` constants (and the two native manifests'
/// APPLICATION_ID) with the AdMob console values for release.
///
/// `--dart-define=USE_TEST_ADS=true` forces test IDs even in a release build,
/// for store-review smoke tests on real devices.
class AdConfig {
static const _forceTest =
bool.fromEnvironment('USE_TEST_ADS', defaultValue: false);
static bool get useTestIds => kDebugMode || _forceTest;
// --- Google official test ad units ---
static const _testInterstitialAndroid =
'ca-app-pub-3940256099942544/1033173712';
static const _testInterstitialIos =
'ca-app-pub-3940256099942544/4411468910';
static const _testRewardedAndroid =
'ca-app-pub-3940256099942544/5224354917';
static const _testRewardedIos = 'ca-app-pub-3940256099942544/1712485313';
static const _testBannerAndroid = 'ca-app-pub-3940256099942544/6300978111';
static const _testBannerIos = 'ca-app-pub-3940256099942544/2934735716';
// --- Owner replaces these with real AdMob console unit IDs ---
static const _realInterstitialAndroid = 'TODO_REAL_INTERSTITIAL_ANDROID';
static const _realInterstitialIos = 'TODO_REAL_INTERSTITIAL_IOS';
static const _realRewardedAndroid = 'TODO_REAL_REWARDED_ANDROID';
static const _realRewardedIos = 'TODO_REAL_REWARDED_IOS';
static const _realBannerAndroid = 'TODO_REAL_BANNER_ANDROID';
static const _realBannerIos = 'TODO_REAL_BANNER_IOS';
static String _pick(String testA, String testI, String realA, String realI) {
final android = useTestIds ? testA : realA;
final ios = useTestIds ? testI : realI;
return Platform.isAndroid ? android : ios;
}
static String get interstitial => _pick(_testInterstitialAndroid,
_testInterstitialIos, _realInterstitialAndroid, _realInterstitialIos);
static String get rewarded => _pick(_testRewardedAndroid, _testRewardedIos,
_realRewardedAndroid, _realRewardedIos);
static String get banner => _pick(
_testBannerAndroid, _testBannerIos, _realBannerAndroid, _realBannerIos);
/// Non-consumable product id for the "remove ads" purchase. Must match the
/// product created in App Store Connect and Google Play Console.
static const removeAdsProductId = 'remove_ads';
}