### Complete Appodeal SDK Configuration Example Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/configuration.md A comprehensive example demonstrating how to initialize the Appodeal SDK, set up consent, configure ad types, user data, and callbacks. This is typically called during app startup. ```dart import 'package:flutter/foundation.dart'; import 'package:stack_appodeal_flutter/stack_appodeal_flutter.dart'; class AppodealConfig { static void configure() { _configureTestMode(); _setupConsent(); _initializeSDK(); _setupBannerConfig(); _setupUserData(); _setupCallbacks(); } static void _configureTestMode() { if (kDebugMode) { Appodeal.setTesting(true); Appodeal.setLogLevel(Appodeal.LogLevelVerbose); } } static void _setupConsent() { Appodeal.ConsentForm.loadAndShowIfRequired( appKey: 'YOUR_APP_KEY', tagForUnderAgeOfConsent: false, ); } static void _initializeSDK() { Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, ], onInitializationFinished: (errors) { if (errors?.isEmpty ?? true) { print('✓ SDK Ready'); } }, ); // Disable auto-cache for manual control Appodeal.setAutoCache(AppodealAdType.Interstitial, false); Appodeal.setAutoCache(AppodealAdType.RewardedVideo, false); } static void _setupBannerConfig() { Appodeal.setSmartBanners(true); Appodeal.setTabletBanners(true); Appodeal.setBannerAnimation(false); Appodeal.setUseSafeArea(true); } static void _setupUserData() { Appodeal.setUserId('user_123'); Appodeal.setCustomFilter('level', 10); Appodeal.setCustomFilter('premium', false); Appodeal.setExtraData('install_date', '2024-01-15'); } static void _setupCallbacks() { Appodeal.setBannerCallbacks( onBannerLoaded: (isPre) => print('Banner ready'), ); Appodeal.setInterstitialCallbacks( onInterstitialClosed: () => Appodeal.cache(AppodealAdType.Interstitial), ); Appodeal.setAdRevenueCallbacks( onAdRevenueReceive: (revenue) { print('Revenue: ${revenue.currency} ${revenue.revenue}'); }, ); } } // Call during app startup void main() { AppodealConfig.configure(); runApp(MyApp()); } ``` -------------------------------- ### Example Error Handling for Appodeal Initialization Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Provides a complete example of initializing the Appodeal SDK with error handling. This includes checking for errors and displaying a user-friendly message upon failure. ```dart void _initializeWithErrorHandling() { Appodeal.initialize( appKey: 'INVALID_KEY', adTypes: [AppodealAdType.Interstitial], onInitializationFinished: (errors) { if (errors == null || errors.isEmpty) { print('SDK initialized successfully'); _setupAds(); } else { final errorMessages = errors.map((e) => e.description).join(', '); print('Initialization failed: $errorMessages'); // Show user-friendly message _showErrorDialog('Failed to initialize ads. Please try again later.'); } }, ); } ``` -------------------------------- ### Layout with Responsive Sizing Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Provides an example of how to implement responsive banner sizing based on screen width. ```APIDOC ### Layout with Responsive Sizing ```dart class ResponsiveBannerPage extends StatelessWidget { @override Widget build(BuildContext context) { final screenWidth = MediaQuery.of(context).size.width; // Choose banner size based on screen width final bannerSize = screenWidth > 400 ? AppodealBannerSize.MEDIUM_RECTANGLE : AppodealBannerSize.BANNER; return Scaffold( appBar: AppBar(title: Text('Responsive Banners')), body: ListView( children: [ SizedBox(height: 200, child: Container(color: Colors.grey)), AppodealBanner( adSize: bannerSize, placement: "list_item_1", ), SizedBox(height: 200, child: Container(color: Colors.grey)), AppodealBanner( adSize: AppodealBannerSize.BANNER, placement: "list_item_2", ), ], ), ); } } ``` ``` -------------------------------- ### Install Flutter Plugin Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/README.md Run this command in your terminal after updating the pubspec.yaml file to fetch the new dependency. ```bash $ flutter pub get ``` -------------------------------- ### Appodeal SDK Configuration Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Guide to configuring the Appodeal SDK, including initialization parameters, ad type selection, targeting, and privacy settings. ```APIDOC ## Appodeal SDK Configuration ### Description Comprehensive guide to configuring the Appodeal Flutter plugin. ### Key Configuration Areas - **Initialization**: Setting up the app key and initial parameters. - **Ad Types**: Selecting which ad formats to load and manage. - **Caching**: Defining caching strategies for ads. - **Banner Customization**: Options for smart banners, tablet layouts, animations, and rotation. - **User Targeting**: Setting user ID, custom filters, and extra data for ad requests. - **Privacy Compliance**: Configuring settings for COPPA, GDPR, CCPA, and consent. - **Testing & Debugging**: Options for enabling test modes and debugging features. ### Example A complete configuration example demonstrating various settings. ``` -------------------------------- ### Create Appodeal Banner with BANNER Size Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner.md Example of creating an AppodealBanner widget with the standard BANNER ad size and a custom placement. ```dart AppodealBanner( adSize: AppodealBannerSize.BANNER, placement: "main_menu", ) ``` -------------------------------- ### Complete Appodeal Initialization and Consent Flow Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-consent-manager.md A comprehensive example demonstrating the integration of Appodeal consent management and initialization within a Flutter application. It shows how to load and display the consent form, handle its dismissal, and then initialize Appodeal with specified ad types. ```dart import 'package:flutter/material.dart'; import 'package:stack_appodeal_flutter/stack_appodeal_flutter.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @override void initState() { super.initState(); _setupConsentAndAds(); } void _setupConsentAndAds() { // Load and show consent form if required Appodeal.ConsentForm.loadAndShowIfRequired( appKey: 'YOUR_APP_KEY', tagForUnderAgeOfConsent: false, onConsentFormDismissed: (error) { if (error != null) { print('Consent failed: ${error.description}'); } // Proceed to initialize Appodeal _initializeAppodeal(); }, ); } void _initializeAppodeal() { Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, ], onInitializationFinished: (errors) { print('Appodeal initialized'); }, ); } @override Widget build(BuildContext context) { return MaterialApp( home: HomePage(), ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Home')), body: Column( children: [ Expanded( child: Center(child: Text('Main Content')), ), PrivacyButtonWidget(), // Conditionally shown ], ), ); } } class PrivacyButtonWidget extends StatelessWidget { @override Widget build(BuildContext context) { return FutureBuilder( future: Appodeal.ConsentForm.getPrivacyOptionsRequirementStatus(), builder: (context, snapshot) { if (!snapshot.hasData || snapshot.data != PrivacyOptionsRequirementStatus.required) { return SizedBox.shrink(); } return Padding( padding: EdgeInsets.all(16), child: ElevatedButton( onPressed: () { Appodeal.ConsentForm.showPrivacyOptionsForm( onConsentFormDismissed: (error) { if (error != null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Error: ${error.description}')), ); } }, ); }, child: Text('Privacy Options'), ), ); }, ); } } ``` -------------------------------- ### AppodealBanner with BANNER Size Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Example of how to use the BANNER size for an Appodeal banner, typically placed at the bottom of the screen. ```dart AppodealBanner( adSize: AppodealBannerSize.BANNER, placement: "bottom_bar", ) ``` -------------------------------- ### Multiple Banners with Different Sizes Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner.md Demonstrates how to display multiple banners of different sizes within a scrollable view. This example shows a standard banner and a medium rectangle banner. ```dart class AdsPage extends StatelessWidget { @override Widget build(BuildContext context) { return SingleChildScrollView( child: Column( children: [ Text('Content Section 1'), SizedBox(height: 16), // Standard banner AppodealBanner( adSize: AppodealBannerSize.BANNER, placement: "section_1", ), SizedBox(height: 32), Text('Content Section 2'), SizedBox(height: 16), // Medium rectangle Center( child: AppodealBanner( adSize: AppodealBannerSize.MEDIUM_RECTANGLE, placement: "section_2", ), ), SizedBox(height: 32), Text('More Content'), ], ), ); } } ``` -------------------------------- ### Load and Show Consent Form Callback Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Example of handling a potential ConsentError when loading and showing the consent form. The error is returned in the onConsentFormDismissed callback. ```dart Appodeal.ConsentForm.loadAndShowIfRequired( appKey: 'YOUR_APP_KEY', onConsentFormDismissed: (error) { // error is ConsentError? }, ); ``` -------------------------------- ### Consent Error Callback Example Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-consent-manager.md An example of a callback function that handles `ConsentError` objects. This is useful for logging or displaying consent-related errors to the user. ```dart void Function(ConsentError)? onFailure = (error) { print('Consent error: ${error.description}'); }; ``` -------------------------------- ### Get Platform-Specific Ad Type Code Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Retrieves the platform-specific type code for initializing ads. Use this to get the correct code for Android or iOS. ```dart final typeCode = AppodealAdType.Banner.platformType; // Returns: 4 on Android, 4 on iOS ``` -------------------------------- ### Typical Initialization Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Demonstrates how to initialize the Appodeal SDK with a list of desired ad types. ```APIDOC ## Typical Initialization ### Description Initializes the Appodeal SDK with your app key and specifies which ad types to load. ### Method `Appodeal.initialize` ### Parameters - `appKey` (string) - Required - Your Appodeal app key. - `adTypes` (List) - Required - A list of AppodealAdType enums to enable. - `onInitializationFinished` (Function(List?)) - Optional - A callback function that is invoked when initialization is complete. ### Request Example ```dart Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, AppodealAdType.MREC, ], onInitializationFinished: (errors) { if (errors == null || errors.isEmpty) { print('Ads initialized successfully'); } }, ); ``` ``` -------------------------------- ### Initialization Flow Diagram Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Illustrates the possible outcomes of the Appodeal.initialize() method, including success and error paths. ```text Appodeal.initialize() ↓ [Network request to initialize SDK] ↓ ├─ Success → onInitializationFinished(null or []) └─ Error → onInitializationFinished([ApdInitializationError, ...]) ``` -------------------------------- ### Initialize Appodeal with All Ad Types (Not Recommended) Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Demonstrates initializing the Appodeal SDK with AppodealAdType.All. This is not recommended; it's better to explicitly list the ad types you need. ```dart // Better: explicitly list types you need // Appodeal.initialize( // appKey: 'YOUR_APP_KEY', // adTypes: [AppodealAdType.All], // Not recommended // ); ``` -------------------------------- ### Get Banner Name Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Access the string identifier for a banner size. ```dart final sizeName = AppodealBannerSize.BANNER.name; // "BANNER" ``` -------------------------------- ### Get Banner Height Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Access the height property of a predefined banner size. ```dart final bannerHeight = AppodealBannerSize.BANNER.height; // 50 ``` -------------------------------- ### Initialize Appodeal with All Ad Types Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/configuration.md Demonstrates initializing the Appodeal SDK with all available ad types. This is useful for comprehensive ad serving. ```dart // Initialize all types final allTypes = [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, AppodealAdType.MREC, ]; Appodeal.initialize(appKey: 'KEY', adTypes: allTypes); ``` -------------------------------- ### Get Banner Width Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Access the width property of a predefined banner size. ```dart final bannerWidth = AppodealBannerSize.BANNER.width; // 320 ``` -------------------------------- ### initialize Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Initializes the Appodeal SDK with the specified application key and ad types. A callback is provided to handle initialization results, including any errors. ```APIDOC ## initialize ### Description Initializes the Appodeal SDK with the specified application key and ad types. A callback is provided to handle initialization results, including any errors. ### Method `static void initialize` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **appKey** (String) - Required - The Appodeal application key obtained from the dashboard - **adTypes** (List) - Required - List of ad types to initialize (e.g., [AppodealAdType.Interstitial, AppodealAdType.Banner]) - **onInitializationFinished** (Function(List? errors)?) - Optional - Callback invoked when initialization completes, receives list of any initialization errors ### Request Example ```dart Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, ], onInitializationFinished: (errors) { if (errors != null && errors.isNotEmpty) { print('Initialization errors: ${errors.map((e) => e.description).join(", ")} '); } else { print('Appodeal initialized successfully' ); } }, ); ``` ### Response #### Success Response None (Initialization results are handled via the `onInitializationFinished` callback). #### Response Example None ``` -------------------------------- ### Initialization Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Methods for initializing the Appodeal SDK and checking its initialization status. ```APIDOC ## Appodeal.initialize() ### Description Initializes the Appodeal SDK. ### Method `Appodeal.initialize(String appKey, int adTypes, {bool hasConsent = true}) ### Parameters - **appKey** (String) - Your Appodeal app key. - **adTypes** (int) - Bitmask of ad types to initialize (e.g., Appodeal.INTERSTITIAL | Appodeal.BANNER). - **hasConsent** (bool, Optional) - Indicates if the user has given consent. Defaults to true. ``` ```APIDOC ## Appodeal.isInitialized() ### Description Checks if the Appodeal SDK has been initialized. ### Method `Appodeal.isInitialized(int adType) ### Parameters - **adType** (int) - The ad type to check initialization for. ``` -------------------------------- ### Get Bidon Endpoint Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Retrieves the currently configured Bidon environment endpoint. This can be null if no custom endpoint has been set. ```dart static Future getBidonEndpoint() ``` ```dart final endpoint = await Appodeal.getBidonEndpoint(); print('Bidon endpoint: $endpoint'); ``` -------------------------------- ### Configuration Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Methods for configuring SDK settings like testing mode, log level, user ID, and targeting. ```APIDOC ## Appodeal.setTesting() ### Description Enables or disables test mode for ads. ### Method `Appodeal.setTesting(bool testMode) ### Parameters - **testMode** (bool) - True to enable test mode, false to disable. ``` ```APIDOC ## Appodeal.setLogLevel() ### Description Sets the verbosity level for SDK logs. ### Method `Appodeal.setLogLevel(int logLevel) ### Parameters - **logLevel** (int) - The desired log level (e.g., Appodeal.LogLevel.verbose). ``` ```APIDOC ## Appodeal.setUserId() ### Description Sets a custom user identifier for ad targeting and analytics. ### Method `Appodeal.setUserId(String userId) ### Parameters - **userId** (String) - The unique identifier for the user. ``` ```APIDOC ## Appodeal.setCustomFilter() ### Description Sets a custom targeting filter for ads. ### Method `Appodeal.setCustomFilter(Map filter) ### Parameters - **filter** (Map) - A map containing custom targeting parameters. ``` ```APIDOC ## Appodeal.setChildDirectedTreatment() ### Description Sets the child-directed treatment flag for COPPA compliance. ### Method `Appodeal.setChildDirectedTreatment(bool childDirected) ### Parameters - **childDirected** (bool) - True if the content is directed at children, false otherwise. ``` -------------------------------- ### Consent Form Load Callback Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Example of how to handle a ConsentError when loading the consent form. The error is returned in the onConsentFormLoadFailure callback. ```dart Appodeal.ConsentForm.load( appKey: 'YOUR_APP_KEY', onConsentFormLoadSuccess: (status) { }, onConsentFormLoadFailure: (error) { // error is ConsentError }, ); ``` -------------------------------- ### AppodealBanner with MEDIUM_RECTANGLE Size Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Example of using the MEDIUM_RECTANGLE size for a larger, more prominent ad placement within the content area. ```dart Center( child: AppodealBanner( adSize: AppodealBannerSize.MEDIUM_RECTANGLE, placement: "content_area", ), ) ``` -------------------------------- ### Callbacks Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Methods for setting up callbacks for various ad events. ```APIDOC ## Appodeal.setBannerCallbacks() ### Description Sets callbacks for banner ad events. ### Method `Appodeal.setBannerCallbacks(AppodealBannerCallbacks callbacks) ### Parameters - **callbacks** (AppodealBannerCallbacks) - An object containing callback functions for banner events. ``` ```APIDOC ## Appodeal.setInterstitialCallbacks() ### Description Sets callbacks for interstitial ad events. ### Method `Appodeal.setInterstitialCallbacks(AppodealInterstitialCallbacks callbacks) ### Parameters - **callbacks** (AppodealInterstitialCallbacks) - An object containing callback functions for interstitial events. ``` ```APIDOC ## Appodeal.setRewardedVideoCallbacks() ### Description Sets callbacks for rewarded video ad events. ### Method `Appodeal.setRewardedVideoCallbacks(AppodealRewardedVideoCallbacks callbacks) ### Parameters - **callbacks** (AppodealRewardedVideoCallbacks) - An object containing callback functions for rewarded video events. ``` ```APIDOC ## Appodeal.setAdRevenueCallbacks() ### Description Sets callbacks for ad revenue events. ### Method `Appodeal.setAdRevenueCallbacks(AppodealAdRevenueCallbacks callbacks) ### Parameters - **callbacks** (AppodealAdRevenueCallbacks) - An object containing callback functions for revenue events. ``` -------------------------------- ### AppodealPurchaseType Example Usage Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-purchase.md Demonstrates how to declare and access the value of an AppodealPurchaseType enum. This is useful for logging or passing purchase type information. ```dart final purchaseType = AppodealPurchaseType.consumable; print('Purchase type value: ${purchaseType.value}'); // 0 ``` -------------------------------- ### Initialize and Handle Rewarded Video Ads Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Initialize the Appodeal SDK for Rewarded Video ads and set up callbacks to handle user rewards. Rewarded videos allow users to opt-in to watch ads for in-app rewards. ```dart Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [AppodealAdType.RewardedVideo], ); // Show and handle reward Appodeal.setRewardedVideoCallbacks( onRewardedVideoFinished: (amount, reward) { print('User earned $reward: $amount'); }, ); ``` -------------------------------- ### Consent Form Show Callback Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Example of handling a potential ConsentError when showing the consent form. The error is returned in the onConsentFormDismissed callback. ```dart Appodeal.ConsentForm.show( onConsentFormDismissed: (error) { // error is ConsentError? }, ); ``` -------------------------------- ### Appodeal Class API Reference Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Main SDK interface for initialization, ad display, caching, banner configuration, callbacks, event logging, purchase validation, and Bidon configuration. ```APIDOC ## Appodeal Class ### Description Provides the main interface for interacting with the Appodeal SDK in Flutter. ### Methods - **Initialization and Lifecycle Management**: Methods to initialize the SDK and manage its lifecycle. - **Ad Display and Caching**: Functions to display and cache various ad formats. - **Banner Configuration**: Options to configure banner ads, including size and placement. - **Callbacks**: Handlers for ad events and lifecycle changes. - **Event Logging**: Methods for logging SDK events. - **Purchase Validation**: Functionality to validate in-app purchases. - **Bidon Configuration**: Settings for integrating with the Bidon mediation platform. ``` -------------------------------- ### Log Demand Source Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-revenue.md Log the specific demand source within the ad network, for example, 'AdMob' or 'Facebook Audience Network'. ```dart print('Demand Source: ${adRevenue.demandSource}'); ``` -------------------------------- ### Initialize Appodeal SDK Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Initialize the Appodeal SDK with your app key and desired ad types. The onInitializationFinished callback is invoked once initialization is complete. ```dart Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, ], onInitializationFinished: (errors) { if (errors == null || errors.isEmpty) { print('SDK ready'); } }, ); ``` -------------------------------- ### getPredictedEcpm Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Gets the predicted eCPM (effective cost per mille) for a specific ad type. Returns the predicted eCPM value. ```APIDOC ## getPredictedEcpm ### Description Gets the predicted eCPM (effective cost per mille) for a specific ad type. ### Method Signature ```dart static Future getPredictedEcpm(AppodealAdType adType) ``` ### Parameters #### Path Parameters - **adType** (AppodealAdType) - Required - The ad type to get eCPM for ### Returns `Future` - The predicted eCPM value. ### Example ```dart final ecpm = await Appodeal.getPredictedEcpm(AppodealAdType.Banner); print('Predicted eCPM: \$$ecpm'); ``` ``` -------------------------------- ### Dynamically Build Ad Types for Initialization Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/configuration.md Shows how to dynamically build the list of ad types based on certain conditions before initializing the Appodeal SDK. This allows for flexible ad configuration. ```dart // Or build dynamically List _buildAdTypes() { final types = []; if (shouldShowBanners) types.add(AppodealAdType.Banner); if (shouldShowInterstitials) types.add(AppodealAdType.Interstitial); if (shouldShowRewarded) types.add(AppodealAdType.RewardedVideo); return types; } Appodeal.initialize(appKey: 'KEY', adTypes: _buildAdTypes()); ``` -------------------------------- ### Get Flutter SDK Version Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Retrieves the version string of the Appodeal Flutter plugin itself. This is useful for compatibility checks or reporting issues. ```dart final version = Appodeal.getSDKVersion(); print('Appodeal Flutter SDK version: $version'); ``` -------------------------------- ### Appodeal Initialization Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/configuration.md Initializes the Appodeal SDK with your app key and desired ad types. An optional callback can be provided to handle initialization results. ```APIDOC ## Appodeal.initialize ### Description Initializes the Appodeal SDK with your app key and desired ad types. An optional callback can be provided to handle initialization results. ### Method Signature ```dart Appodeal.initialize({ required String appKey, required List adTypes, Function(List? errors)? onInitializationFinished, }) ``` ### Parameters #### Path Parameters * **appKey** (String) - Required - Your Appodeal application key from the dashboard * **adTypes** (List) - Required - List of ad types to initialize * **onInitializationFinished** (Function?) - Optional - Callback when initialization completes ### Request Example ```dart void initializeAppodeal() { Appodeal.initialize( appKey: 'YOUR_APP_KEY_HERE', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, AppodealAdType.MREC, ], onInitializationFinished: (errors) { if (errors == null || errors.isEmpty) { print('✓ Appodeal initialized successfully'); } else { print('✗ Init errors: ${errors.map((e) => e.description).join(", ") }'); } }, ); } ``` ### Response #### Success Response Initialization is asynchronous. The `onInitializationFinished` callback provides the result. #### Response Example ```dart // Inside the onInitializationFinished callback: if (errors == null || errors.isEmpty) { print('✓ Appodeal initialized successfully'); } else { print('✗ Init errors: ${errors.map((e) => e.description).join(", ") }'); } ``` ``` -------------------------------- ### Initialize Appodeal with Ad Types Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Initialize the Appodeal SDK with a list of desired ad types. The `onInitializationFinished` callback provides error information if initialization fails. ```dart Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [ AppodealAdType.Banner, AppodealAdType.Interstitial, AppodealAdType.RewardedVideo, AppodealAdType.MREC, ], onInitializationFinished: (errors) { if (errors == null || errors.isEmpty) { print('Ads initialized successfully'); } }, ); ``` -------------------------------- ### Validate Play Store Purchase Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-purchase.md Validates a Play Store in-app purchase. This example requires `purchaseToken`, `signature`, and `purchaseData` from the `PurchaseDetails` object. ```dart void validatePlayStorePurchase(PurchaseDetails purchaseDetails) { final purchase = AppodealPlayStorePurchase.inapp( orderId: purchaseDetails.purchaseID, price: purchaseDetails.billingClientPurchase?.originalJson ?? '0.00', currency: 'USD', sku: purchaseDetails.productID, purchaseToken: purchaseDetails.billingClientPurchase?.purchaseToken, signature: purchaseDetails.billingClientPurchase?.signature, purchaseData: purchaseDetails.billingClientPurchase?.originalJson, purchaseTimestamp: int.tryParse(purchaseDetails.transactionDate ?? '0') ?? 0, ); Appodeal.validateInAppPurchase( purchase: purchase, onInAppPurchaseValidateSuccess: (purchase, errors) { _deliverProduct(purchase); }, ); } ``` -------------------------------- ### Get User ID from Appodeal Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Retrieves the currently set user identifier. This is useful for debugging or if your application needs to access the user ID. ```dart final userId = await Appodeal.getUserId(); print('Current user ID: $userId'); ``` -------------------------------- ### Initialize and Show Interstitial Ads Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Initialize the Appodeal SDK for Interstitial ads and demonstrate how to show them after checking if they are loaded. Interstitial ads cover the full screen and are best shown at natural transition points. ```dart Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [AppodealAdType.Interstitial], ); // Later, show interstitial if (await Appodeal.isLoaded(AppodealAdType.Interstitial)) { await Appodeal.show(AppodealAdType.Interstitial, 'level_complete'); } ``` -------------------------------- ### Get Privacy Options Requirement Status Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-consent-manager.md Asynchronously retrieves the requirement status for privacy options. Use this to conditionally display privacy-related buttons. ```dart final status = await Appodeal.ConsentForm.getPrivacyOptionsRequirementStatus(); if (status == PrivacyOptionsRequirementStatus.required) { // Show "Privacy Options" or "Do Not Sell" button } ``` -------------------------------- ### Initialize Appodeal with Null Error Check Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Demonstrates how to safely handle potential errors during Appodeal initialization by checking if the errors list is null or empty. ```dart Appodeal.initialize( appKey: 'KEY', adTypes: [AppodealAdType.Banner], onInitializationFinished: (errors) { // Safe to call - errors might be null or empty list if (errors?.isNotEmpty ?? false) { for (final error in errors!) { print(error.description); } } }, ); ``` -------------------------------- ### Check Ad Availability Before Showing Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/README.md Before attempting to show an ad, check if it's ready to be displayed. This prevents errors and improves user experience by only showing ads when available. ```dart final canShow = await Appodeal.canShow(AppodealAdType.Interstitial); if (canShow) { await Appodeal.show(AppodealAdType.Interstitial); } else { print('Ad not ready'); } ``` -------------------------------- ### Handle Privacy Options Errors Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Provides an example of handling errors when showing the privacy options form, displaying user-friendly messages via SnackBars. ```dart void _showPrivacyOptionsWithErrorHandling() { Appodeal.ConsentForm.showPrivacyOptionsForm( onConsentFormDismissed: (error) { if (error != null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Privacy options unavailable: ${error.description}'), duration: Duration(seconds: 3), ), ); } else { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Privacy preferences updated')), ); } }, ); } ``` -------------------------------- ### Dynamic Banner Selection Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Illustrates how to dynamically select an Appodeal banner size based on application logic. ```APIDOC ### Dynamic Banner Selection ```dart class AdWidget extends StatelessWidget { final bool isLargeFormat; const AdWidget({required this.isLargeFormat}); AppodealBannerSize _selectBannerSize() { if (isLargeFormat) { return AppodealBannerSize.MEDIUM_RECTANGLE; } else { return AppodealBannerSize.BANNER; } } @override Widget build(BuildContext context) { final adSize = _selectBannerSize(); return AppodealBanner( adSize: adSize, placement: isLargeFormat ? "featured" : "standard", ); } } ``` ``` -------------------------------- ### Show Privacy Options Form Callback Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Example of handling a potential ConsentError when showing the privacy options form. The error is returned in the onConsentFormDismissed callback. ```dart Appodeal.ConsentForm.showPrivacyOptionsForm( onConsentFormDismissed: (error) { // error is ConsentError? }, ); ``` -------------------------------- ### Showing Ads Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Illustrates how to display different types of Appodeal ads. ```APIDOC ## Showing Ads ### Description Displays various Appodeal ad formats. ### Methods `Appodeal.show(AppodealAdType adType, [String? placement])` ### Parameters - `adType` (AppodealAdType) - Required - The type of ad to show. - `placement` (String) - Optional - The name of the placement for the ad. ### Request Example ```dart // Show interstitial if (await Appodeal.isLoaded(AppodealAdType.Interstitial)) { await Appodeal.show(AppodealAdType.Interstitial, 'placement_name'); } // Show banner await Appodeal.show(AppodealAdType.Banner); // Show rewarded video if (await Appodeal.canShow(AppodealAdType.RewardedVideo)) { await Appodeal.show(AppodealAdType.RewardedVideo, 'watch_for_reward'); } ``` ``` -------------------------------- ### Get Predicted eCPM Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Retrieve the predicted eCPM for a specific ad type using `getPredictedEcpm`. This value can help in understanding potential ad revenue. ```dart final ecpm = await Appodeal.getPredictedEcpm(AppodealAdType.Banner); print('Predicted eCPM: $ecpm'); ``` -------------------------------- ### Basic Banner Widget Implementation Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Demonstrates how to integrate a standard Appodeal banner into a Flutter widget tree, typically at the bottom of the screen. ```dart import 'package:flutter/material.dart'; import 'package:stack_appodeal_flutter/stack_appodeal_flutter.dart'; class MyPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Expanded( child: SingleChildScrollView( child: Text('Page content'), ), ), // Standard banner at bottom AppodealBanner( adSize: AppodealBannerSize.BANNER, placement: "main_content", ), ], ), ); } } ``` -------------------------------- ### Get Platform-Specific Ad Show Code Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Retrieves the platform-specific type code for showing ads. This may differ from `platformType` on iOS for certain ad types. ```dart final showCode = AppodealAdType.Banner.platformShowType; // Returns: 4 on Android, 8 on iOS ``` -------------------------------- ### Check Ad Availability Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Check if specific ad types are initialized and ready to be shown. Use `isInitialized` for general readiness and `canShow` for specific ad types like banners. ```dart final isInterstitialReady = await Appodeal.isInitialized(AppodealAdType.Interstitial); final canShowBanner = await Appodeal.canShow(AppodealAdType.Banner); ``` -------------------------------- ### Show Ad Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Use the `show` method to display an ad of a specified type and placement. It returns `true` if the ad was successfully shown, and `false` otherwise. ```dart final shown = await Appodeal.show(AppodealAdType.Interstitial, 'between_levels'); if (shown) { print('Interstitial displayed'); } else { print('Failed to show interstitial'); } ``` -------------------------------- ### Basic Banner Widget Usage Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Demonstrates how to integrate a standard Appodeal banner into a Flutter widget tree. ```APIDOC ## Usage Examples ### Basic Banner Widget ```dart import 'package:flutter/material.dart'; import 'package:stack_appodeal_flutter/stack_appodeal_flutter.dart'; class MyPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Expanded( child: SingleChildScrollView( child: Text('Page content'), ), ), // Standard banner at bottom AppodealBanner( adSize: AppodealBannerSize.BANNER, placement: "main_content", ), ], ), ); } } ``` ``` -------------------------------- ### Get Native Platform SDK Version Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Asynchronously retrieves the version of the underlying native Appodeal SDK (iOS or Android). This is important for ensuring compatibility between the plugin and the native SDK. ```dart final platformVersion = await Appodeal.getPlatformSdkVersion(); print('Native SDK version: $platformVersion'); ``` -------------------------------- ### cache Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Starts caching ads for the specified ad type. This method is used to manually pre-load ads, typically when auto-caching is disabled or when you want to ensure ads are ready before they are needed. ```APIDOC ## cache ### Description Starts caching ads for the specified ad type. ### Method `static void cache(AppodealAdType adType)` ### Parameters #### Path Parameters - **adType** (AppodealAdType) - Required - The ad type to cache ### Request Example ```dart Appodeal.cache(AppodealAdType.Interstitial); // Preload interstitials ``` ``` -------------------------------- ### Printing AppodealBannerSize Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-banner-size.md Demonstrates how to print the `AppodealBannerSize` object to the console, utilizing the `toString` override for a clear output. ```dart print(AppodealBannerSize.BANNER); // Output: AppodealBannerSize(name: BANNER, width: 320, height: 50) ``` -------------------------------- ### Get Privacy Options Requirement Status Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/README.md Checks the status of privacy options requirements, which indicates whether the user is in a regulated region (e.g., US states for CCPA, EEA for GDPR re-consent). ```APIDOC ## Get Privacy Options Requirement Status ### Description Retrieves the current status of privacy options requirements. This is used to determine if a 'Do Not Sell or Share My Personal Information' button or a GDPR re-consent form should be displayed. ### Method Appodeal.ConsentForm.getPrivacyOptionsRequirementStatus ### Parameters None ### Returns - **status** (PrivacyOptionsRequirementStatus) - The status indicating whether privacy options are required. Possible values are `required`, `notRequired`, and `unknown`. ``` -------------------------------- ### AppodealAdType.None Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal-ad-type.md Represents no ad types. Use for SDK initialization when you only need attribution and session metrics before enabling ads. ```APIDOC ## AppodealAdType.None Constant for SDK initialization without declaring any ad types. Use when you want to run attribution and session metrics before enabling ads. | Property | Android | iOS | |----------|---------|-----| | initCodeAndroid | 0 | — | | initCodeIOS | — | 0 | | imprCodeIOS | — | 0 | **Example:** ```dart // Initialize without ads for analytics only Appodeal.initialize( appKey: 'YOUR_APP_KEY', adTypes: [AppodealAdType.None], ); ``` ``` -------------------------------- ### PrivacyOptionsRequirementStatus Enum Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/types.md Indicates whether a Privacy Options button is required for the user. This status is returned by `AppodealConsentForm.getPrivacyOptionsRequirementStatus()` and helps determine if the user needs to be presented with privacy options, for example, for US opt-out or GDPR re-consent. ```dart enum PrivacyOptionsRequirementStatus { unknown, // Status not yet determined required, // Button is required notRequired // Button is not required } ``` -------------------------------- ### show Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/api-reference/appodeal.md Shows an ad of the specified type with the given placement. Returns true if the ad was shown, false if it could not be shown. ```APIDOC ## show ### Description Shows an ad of the specified type with the given placement. ### Method Signature ```dart static Future show(AppodealAdType adType, [String placement = "default"]) ``` ### Parameters #### Path Parameters - **adType** (AppodealAdType) - Required - The ad type to show - **placement** (String) - Optional - The placement identifier for analytics (defaults to "default") ### Returns `Future` - `true` if the ad was shown, `false` if it could not be shown. ### Example ```dart final shown = await Appodeal.show(AppodealAdType.Interstitial, 'between_levels'); if (shown) { print('Interstitial displayed'); } else { print('Failed to show interstitial'); } ``` ``` -------------------------------- ### Handle In-App Purchase Validation Errors Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/_autodocs/errors.md Provides a comprehensive example of handling validation results, including checking for null or empty error lists, iterating through warnings, and categorizing specific failure conditions like security, validity, or network errors. This function shows how to react to different types of validation outcomes. ```dart void _validatePurchaseWithErrorHandling(AppodealPurchase purchase) { Appodeal.validateInAppPurchase( purchase: purchase, onInAppPurchaseValidateSuccess: (purchase, errors) { if (errors == null || errors.isEmpty) { print('Purchase validated successfully'); _grantItem(purchase); } else { print('Validation warnings:'); for (final error in errors) { print(' - ${error.description}'); } // Might still grant item depending on warning severity _grantItem(purchase); } }, onInAppPurchaseValidateFail: (purchase, errors) { print('Purchase validation failed'); if (errors != null && errors.isNotEmpty) { final errorMessages = errors.map((e) => e.description).toList(); // Categorize errors if (errorMessages.any((e) => e.contains('signature'))) { print('Security error: Purchase appears tampered'); _logSecurityEvent('tampered_purchase', purchase); } if (errorMessages.any((e) => e.contains('expired'))) { print('Validity error: Purchase token expired'); _logValidationEvent('token_expired', purchase); } if (errorMessages.any((e) => e.contains('Network'))) { print('Network error: Retry validation later'); _queueForRetry(purchase); } } // Deny purchase _showErrorMessage('Purchase could not be verified. Please contact support.'); }, ); } ``` -------------------------------- ### Add Appodeal and Mediation Adapters to build.gradle Source: https://github.com/appodeal/appodeal-flutter-plugin/blob/main/README.md Include the Appodeal core SDK and various mediation adapters in your app's build.gradle file to enable ad functionality. ```groovy dependencies { implementation "com.appodeal.ads.sdk:core:4.2.0" // AppLovin MAX implementation "com.applovin.mediation:amazon-tam-adapter:11.3.0.0" implementation "com.applovin.mediation:bidmachine-adapter:3.7.1.0" implementation "com.applovin.mediation:bigoads-adapter:5.6.2.0" implementation "com.applovin.mediation:bytedance-adapter:8.1.0.3.0" implementation "com.applovin.mediation:chartboost-adapter:9.10.2.0" implementation "com.applovin.mediation:facebook-adapter:6.21.0.0" implementation "com.applovin.mediation:fyber-adapter:8.4.1.0" implementation "com.applovin.mediation:google-ad-manager-adapter:24.7.0.0" implementation "com.applovin.mediation:google-adapter:24.7.0.0" implementation "com.applovin.mediation:inmobi-adapter:11.1.0.0" implementation "com.applovin.mediation:ironsource-adapter:9.1.0.0.0" implementation "com.applovin.mediation:mintegral-adapter:17.1.61.0" implementation "com.applovin.mediation:mobilefuse-adapter:1.9.3.0" implementation "com.applovin.mediation:moloco-adapter:4.3.1.0" implementation "com.applovin.mediation:mytarget-adapter:5.47.1.0" implementation "com.applovin.mediation:ogury-presage-adapter:6.2.0.0" implementation "com.applovin.mediation:pubmatic-adapter:4.10.0.0" implementation "com.applovin.mediation:smaato-adapter:22.7.2.3" implementation "com.applovin.mediation:unityads-adapter:4.17.0.0" implementation "com.applovin.mediation:verve-adapter:3.7.1.0" implementation "com.applovin.mediation:vungle-adapter:7.6.1.0" implementation "com.applovin.mediation:yandex-adapter:7.17.0.0" // Level Play implementation "com.unity3d.ads-mediation:admob-adapter:5.2.0" implementation "com.unity3d.ads-mediation:applovin-adapter:5.2.0" implementation "com.unity3d.ads-mediation:bidmachine-adapter:5.7.0" } ```