tapmind_ads_applovin 0.0.6 copy "tapmind_ads_applovin: ^0.0.6" to clipboard
tapmind_ads_applovin: ^0.0.6 copied to clipboard

A Flutter plugin for integrating TapMind ads into your Flutter applications. Supports both Android and iOS platforms.

example/lib/main.dart

import 'dart:async';
import 'dart:io' show Platform;

import 'package:applovin_max/applovin_max.dart';
import 'package:flutter/material.dart';

import 'interstitial_ad.dart';
import 'native_ad.dart';
import 'programmatic_banner.dart';
import 'programmatic_mrec.dart';
import 'rewarded_ad.dart';
import 'scrolled_adview.dart';
import 'utils.dart';
import 'widget_banner.dart';
import 'widget_mrec.dart';

void main() {
  runApp(const MaterialApp(title: 'AppLovin MAX Demo', home: MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // AppLovin MAX configuration
  final String _sdkKey =
      'iIqgM0gm6T2PNNT_gMWAs7CCUaTgf80tqmTxfQOc6TtOn5rSmkSA3h79SGxTS0fkGw6zbDhvZLve_hnfd9eDeX';
  final String _interstitialAdUnitId = Platform.isAndroid
      ? 'eb08a9a43cd7954f'
      : '5f9d2d51bc1ab1e3';
  final String _rewardedAdUnitId = Platform.isAndroid
      ? '0ded93032fd6f774'
      : '59de96ebf9d38a21';
  final String _bannerAdUnitId = Platform.isAndroid
      ? '0a5587ff24614834'
      : 'd4a32c601314b93b';
  final String _mrecAdUnitId = Platform.isAndroid
      ? 'ANDROID_MREC_AD_UNIT_ID'
      : 'IOS_MREC_AD_UNIT_ID';
  final String _nativeAdUnitId = Platform.isAndroid
      ? 'ANDROID_NATIVE_AD_UNIT_ID'
      : 'IOS_NATIVE_AD_UNIT_ID';

  // App state tracking
  bool _isInitialized = false;
  bool _isWidgetBannerShowing = false;
  bool _isWidgetMRecShowing = false;
  bool _isProgrammaticBannerShowing = false;
  bool _isProgrammaticMRecShowing = false;

  // Preloaded widget ad references
  AdViewId? _preloadedBannerId;
  AdViewId? _preloadedMRecId;
  AdViewId? _preloadedBanner2Id;
  AdViewId? _preloadedMRec2Id;

  String _statusText = '';

  @override
  void initState() {
    super.initState();
    _initializePlugin();
  }

  Future<void> _initializePlugin() async {
    _logStatus('Initializing SDK...');

    AppLovinMAX.setTermsAndPrivacyPolicyFlowEnabled(true);
    AppLovinMAX.setPrivacyPolicyUrl('https://your_company_name.com/privacy');
    AppLovinMAX.setTermsOfServiceUrl('https://your_company_name.com/terms');

    MaxConfiguration? configuration = await AppLovinMAX.initialize(_sdkKey);
    if (configuration == null) {
      _logStatus('SDK failed to initialize.');
    } else {
      setState(() => _isInitialized = true);
      _logStatus('SDK Initialized in ${configuration.countryCode}');

      // Optionally preload widget-based banner and MREC ads. Comment out if preloading isn't needed.
      _preloadWidgetAdViews();
    }
  }

  void _preloadWidgetAdViews() async {
    AppLovinMAX.setWidgetAdViewAdListener(
      WidgetAdViewAdListener(
        onAdLoadedCallback: (ad) => _logStatus(
          '${ad.adFormat} ad (${ad.adViewId}) preloaded from ${ad.networkName}',
        ),
        onAdLoadFailedCallback: (adUnitId, error) =>
            _logStatus('Failed to preload $adUnitId: ${error.message}'),
      ),
    );

    _preloadedBannerId = await AppLovinMAX.preloadWidgetAdView(
      _bannerAdUnitId,
      AdFormat.banner,
    );
    _preloadedMRecId = await AppLovinMAX.preloadWidgetAdView(
      _mrecAdUnitId,
      AdFormat.mrec,
    );
    _preloadedBanner2Id = await AppLovinMAX.preloadWidgetAdView(
      _bannerAdUnitId,
      AdFormat.banner,
    );
    _preloadedMRec2Id = await AppLovinMAX.preloadWidgetAdView(
      _mrecAdUnitId,
      AdFormat.mrec,
    );
  }

  void _logStatus(String status) {
    // ignore_for_file: avoid_print
    print(status);
    setState(() => _statusText = status);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 60,
        centerTitle: true,
        title: Container(
          height: 42,
          alignment: Alignment.center,
          child: ColorFiltered(
            colorFilter: const ColorFilter.mode(Colors.black, BlendMode.srcIn),
            child: Image.asset('assets/applovin_logo.png', fit: BoxFit.cover),
          ),
        ),
      ),
      body: Column(
        children: [
          StatusBar(statusText: _statusText),
          AppButton(
            onPressed: _isInitialized
                ? () => AppLovinMAX.showMediationDebugger()
                : null,
            text: 'Mediation Debugger',
          ),
          InterstitialAd(
            adUnitId: _interstitialAdUnitId,
            log: _logStatus,
            isInitialized: _isInitialized,
          ),
          RewardedAd(
            adUnitId: _rewardedAdUnitId,
            log: _logStatus,
            isInitialized: _isInitialized,
          ),
          ProgrammaticBanner(
            adUnitId: _bannerAdUnitId,
            isInitialized: _isInitialized,
            isWidgetBannerShowing: _isWidgetBannerShowing,
            isShowing: _isProgrammaticBannerShowing,
            setShowing: (showing) =>
                setState(() => _isProgrammaticBannerShowing = showing),
            log: _logStatus,
          ),
          ProgrammaticMRec(
            adUnitId: _mrecAdUnitId,
            isInitialized: _isInitialized,
            isWidgetMRecShowing: _isWidgetMRecShowing,
            isShowing: _isProgrammaticMRecShowing,
            setShowing: (showing) =>
                setState(() => _isProgrammaticMRecShowing = showing),
            log: _logStatus,
          ),
          AppButton(
            text: (_isInitialized && _isWidgetBannerShowing)
                ? 'Hide Widget Banner'
                : 'Show Widget Banner',
            onPressed: (_isInitialized && !_isProgrammaticBannerShowing)
                ? () => setState(
                    () => _isWidgetBannerShowing = !_isWidgetBannerShowing,
                  )
                : null,
          ),
          AppButton(
            text: (_isInitialized && _isWidgetMRecShowing)
                ? 'Hide Widget MREC'
                : 'Show Widget MREC',
            onPressed: (_isInitialized && !_isProgrammaticMRecShowing)
                ? () => setState(
                    () => _isWidgetMRecShowing = !_isWidgetMRecShowing,
                  )
                : null,
          ),
          AppButton(
            onPressed: (_isInitialized)
                ? () async => Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) =>
                          NativeAdView(adUnitId: _nativeAdUnitId),
                    ),
                  )
                : null,
            text: 'Show Native Ad',
          ),
          AppButton(
            onPressed: (_isInitialized)
                ? () async => Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => ScrolledAdView(
                        bannerAdUnitId: _bannerAdUnitId,
                        mrecAdUnitId: _mrecAdUnitId,
                        preloadedBannerId: _preloadedBannerId,
                        preloadedMRecId: _preloadedMRecId,
                        preloadedBanner2Id: _preloadedBanner2Id,
                        preloadedMRec2Id: _preloadedMRec2Id,
                      ),
                    ),
                  )
                : null,
            text: 'Show Scrolled Banner/MREC',
          ),
          WidgetBannerAdView(
            adUnitId: _bannerAdUnitId,
            adViewId: _preloadedBannerId,
            isShowing: _isWidgetBannerShowing,
            log: _logStatus,
          ),
          WidgetMRecAdView(
            adUnitId: _mrecAdUnitId,
            adViewId: _preloadedMRecId,
            isShowing: _isWidgetMRecShowing,
            log: _logStatus,
          ),
        ],
      ),
    );
  }
}
0
likes
0
points
185
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for integrating TapMind ads into your Flutter applications. Supports both Android and iOS platforms.

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on tapmind_ads_applovin

Packages that implement tapmind_ads_applovin