Dream Monet Flutter SDK
1. Install
Trong pubspec.yaml:
dependencies:
dream_monet_flutter_sdk: ^0.0.9-alpha
2. Setup Application ID KEY
Android
- Đảm bảo
minSdkVersion >= 21,compileSdkVersionmới nhất vàMainActivityđã khai báoandroid:exported. - Thêm App ID của Google Mobile Ads vào
android/app/src/main/AndroidManifest.xml:
<application>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<!-- MainActivity -->
</application>
iOS (Chưa test)
- Thêm
GADApplicationIdentifiervàoios/Runner/Info.plist. - Bổ sung
SKAdNetworkItemstheo hướng dẫn của Google nếu cần attribution.
3. Khởi tạo SDK & Consent
In your splash screen
final DreamMonetSDK sdk = DreamMonetSDK();
Future<void> bootstrap() async {
WidgetsFlutterBinding.ensureInitialized();
await MobileAds.instance.initialize();
final config = SDKConfig(
appId: SampleAdUnits.admobAppId,
isDebugMode: true,
testMode: true
);
await sdk.initialize(config);
final result = await sdk.consentManager.gatherConsent(
testDeviceHashedId: SampleAdUnits.testDeviceId,
debugGeography: DebugGeography.debugGeographyEea,
);
if (!result.isSuccess) throw result.message ?? 'Consent error';
if (!await sdk.consentManager.canRequestAds()) {
throw 'Consent chưa sẵn sàng để request ads';
}
}
4. Tích hợp
Interstitial
late final CommonInterstitialAd _interstitialAd = CommonInterstitialAd(
key: 'demo-interstitial-key',
defaultUnitId: SampleAdUnits.interstitialAdUnit,
);
Future<void> _loadInterstitial() async {
final result = await _interstitialAd.load(context);
}
void _showInterstitial() {
_interstitialAd.show(
context,
_InterstitialCallback(
onShowed: () { /* do something */ },
onFailed: (error) { }
),
timeoutMs: 5000,
);
}
CommonInterstitialAd.loadtrả vềDreamLoadResultđể bạn quyết định flow.
Rewarded
late final CommonRewardedAd _rewardedAd = CommonRewardedAd(
key: 'demo-rewarded-key',
defaultUnitId: SampleAdUnits.rewardedAdUnit,
);
//optional for reward ad
_rewardedAd.setServerSideVerificationOptions(ServerSideVerificationOptions(userId: "hello my feng"));
//load
Future<void> _loadRewarded() async {
final result = await _rewardedAd.load(context);
}
//show
void _showRewarded() {
_rewardedAd.show(
context,
_RewardedCallback(
onShowed: () { /* do something */ },
onFailed: (error) { },
onRewarded: (amount, type) => _log('Rewarded user (+$amount $type)'),
),
timeoutMs: 5000,
);
}
- In App Purchase
- Cấu hình trong
SDKConfigkhi khởi tạo SDK:
final config = SDKConfig(
appId: 'your_app_id',
purchaseConfig: DreamPurchaseConfig(
android: PlatformPurchaseConfig(
consumableIds: ['coin_pack_1', 'coin_pack_2'],
oneTimeProductIds: ['remove_ads'],
subscriptionIds: ['premium_monthly'],
removeAdIds: ['remove_ads'],
),
ios: PlatformPurchaseConfig(
consumableIds: ['coin_pack_1'],
oneTimeProductIds: ['remove_ads'],
subscriptionIds: ['premium_monthly'],
removeAdIds: ['remove_ads'],
),
),
);
final purchase = DreamMonetSDK().purchase;
final price = await purchase.getPrice('product_id');
final currency = await purchase.getCurrency('product_id');
//buy
final result = await purchase.buy('product_id');
if (result == null) {
} else if (result.status == DreamPurchaseStatus.error) {
print('Lỗi: ${result.error?.message}');
} else if (result.isPurchased()){
print('Mua hàng thành công!');
}
// check if remove ad by purchase:
purchase.isRemoveAd // a bool value
purchase.isRemoveAdStream.listen((isRemoveAd) => _log("removed ad")); //stream
6. Ad Revenue Listener
To listen for ad revenue events (e.g., to send data to MMPs like AppsFlyer or Adjust), implement the AdRevenueListener interface and register it with the SDK before initialization.
1. Create a Listener Class
import 'package:dream_monet_flutter_sdk/dream_monet_flutter_sdk.dart';
class MyAppRevenueListener extends AdRevenueListener {
@override
void onAdRevenue(
String adId,
int valueMicros,
String currencyCode,
String precision,
) {
print('Ad Revenue: $valueMicros $currencyCode (Precision: $precision) for Ad Unit: $adId');
// Example: Log to AppsFlyer
// final revenue = valueMicros / 1000000.0;
// Map<String, dynamic> additionalParams = {
// 'adUnitId': adId,
// 'precision': precision,
// };
// appsFlyerSdk.logAdRevenue(revenue, currencyCode, additionalParams);
}
}
2. Register the Listener
Call setAdRevenueListener before initializing the SDK.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Register revenue listener
DreamMonetSDK().setAdRevenueListener(MyAppRevenueListener());
// Initialize SDK
final config = SDKConfig(
// ... your config
);
await DreamMonetSDK().initialize(config);
// ... rest of your app initialization
}
Libraries
- api/common/common_app_open_ad
- api/common/common_interstitial_ad
- api/common/common_native_ad
- api/common/common_native_widget
- api/common/common_rewarded_ad
- consent/consent_manager
- consent/consent_result
- consent/consent_status
- core/config/ad_network_config
- core/config/sdk_config
- core/dream_monet_sdk
- core/models/ad_network_type
- core/models/ad_request
- core/models/ad_type
- dream_monet_flutter_sdk
- Dream Monet Flutter SDK
- factory/ad_factory
- factory/config/ad_config
- factory/config/ad_full_screen_config
- factory/config/ad_global_config
- factory/config/ad_inventory_config
- factory/config/inter_backup_config
- factory/config/single_ad_full_screen_config
- factory/native_ad_factory
- in_app_purchase/dream_in_app_purchase
- in_app_purchase/factory/in_app_purchase_factory
- in_app_purchase/models/dream_product_details
- in_app_purchase/models/dream_product_details_response
- in_app_purchase/models/dream_purchase_details
- in_app_purchase/models/dream_purchase_result
- in_app_purchase/models/dream_purchase_status
- in_app_purchase/platforms/android/dream_android_in_app_purchase
- in_app_purchase/platforms/ios/dream_ios_in_app_purchase
- in_app_purchase/util/dream_purchase
- in_app_purchase/widgets/remove_ad_listener
- interfaces/dream_ad
- interfaces/dream_ad_result
- interfaces/dream_app_open_ad
- interfaces/dream_interstitial_ad
- interfaces/dream_native_ad
- interfaces/dream_rewarded_ad
- inventory/ad_inventory_manager
- inventory/native/native_inventory
- lifecycle/ad_lifecycle_manager
- lifecycle/ad_state_manager
- listeners/adtype/dream_full_screen_ad_listener
- listeners/adtype/dream_interstitial_ad_show_callback
- listeners/adtype/dream_native_ad_listener
- listeners/adtype/dream_rewarded_ad_show_callback
- listeners/base/ad_load_listener
- listeners/base/ad_revenue_listener
- listeners/base/ad_show_listener
- main
- manager/ad_control
- manager/ad_manager
- manager/analytics_manager
- manager/preferences_manager
- manager/remote_config_manager
- networks/admob/admob_dream_app_open_ad
- networks/admob/admob_dream_interstitial_ad
- networks/admob/admob_dream_native_ad
- networks/admob/admob_dream_rewarded_ad
- networks/admob/admob_network
- networks/base/ad_network
- networks/waterfall/waterfall_inter_ad
- networks/waterfall/waterfall_rewarded_ad
- utils/ad_network_detector
- utils/remote_config_value