adpopcornssp_flutter 1.0.13 copy "adpopcornssp_flutter: ^1.0.13" to clipboard
adpopcornssp_flutter: ^1.0.13 copied to clipboard

AdPopcornSSP Flutter plugin project.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io' show Platform;

import 'package:flutter/services.dart';
import 'package:adpopcornssp_flutter/adpopcornssp_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  static const MethodChannel androidBannerChannel = const MethodChannel('adpopcornssp/BANNER_320x50');
  static const MethodChannel iosBannerChannel = const MethodChannel('adpopcornssp/iOS_BANNER_320x50');

  static const MethodChannel androidNativeChannel = const MethodChannel('adpopcornssp/NATIVE_TEMPLATE');
  static const MethodChannel iosNativeChannel = const MethodChannel('adpopcornssp/iOS_NATIVE_TEMPLATE');

  
  @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) {
      AdPopcornSSP.init('663451319');
      // 전면 비디오 연동
      AdPopcornSSP.loadInterstitial('663451319', 'INTERSTITIAL');
      AdPopcornSSP.interstitialAdLoadSuccessListener = (placementId) {
        //AdPopcornSSP.showInterstitial('663451319', placementId);
      };

      // 전면 비디오 연동
      AdPopcornSSP.loadInterstitialVideo('663451319', 'VIDEO');
      AdPopcornSSP.interstitialVideoAdLoadSuccessListener = (placementId) {
       //  AdPopcornSSP.showInterstitialVideo('663451319', placementId);
      };

      // 리워드 비디오 연동
      AdPopcornSSP.loadRewardVideo('663451319', 'REWARD_VIDEO');
      AdPopcornSSP.rewardVideoAdLoadSuccessListener = (placementId) {
        //AdPopcornSSP.showRewardVideo('663451319', placementId);
      };
      
      // 비디오 믹스 연동
      AdPopcornSSP.loadVideoMix('663451319', 'REWARD_VIDEO');
      AdPopcornSSP.videoMixAdLoadSuccessListener = (placementId) {
        //AdPopcornSSP.showVideoMix('663451319', placementId);
      };

      // 배너, 네이티브 이벤트 채널 연동
      androidBannerChannel.setMethodCallHandler(_eventHandleMethod);
      androidNativeChannel.setMethodCallHandler(_eventHandleMethod);
    } else if (Platform.isIOS) {
      AdPopcornSSP.init('397261446');

      // 전면 연동
      AdPopcornSSP.loadInterstitial('397261446', 'iOS_INTERSTITIAL');
      AdPopcornSSP.interstitialAdLoadSuccessListener = (placementId) {
      //  AdPopcornSSP.showInterstitial('397261446', placementId);
      };

      // 전면 비디오 연동
      AdPopcornSSP.loadInterstitialVideo('397261446', 'iOS_VIDEO');
      AdPopcornSSP.interstitialVideoAdLoadSuccessListener = (placementId) {
        //AdPopcornSSP.showInterstitialVideo('397261446', placementId);
      };

      // 리워드 비디오 연동
      AdPopcornSSP.loadRewardVideo('397261446', 'iOS_REWARD_VIDEO');
      AdPopcornSSP.rewardVideoAdLoadSuccessListener = (placementId) {
        //AdPopcornSSP.showRewardVideo('397261446', placementId);
      };
      
      // 비디오 믹스 연동
      AdPopcornSSP.loadVideoMix('397261446', 'iOS_REWARD_VIDEO');
      AdPopcornSSP.videoMixAdLoadSuccessListener = (placementId) {
        AdPopcornSSP.showVideoMix('397261446', placementId);
      };

      // 배너, 네이티브 이벤트 채널 연동
      iosBannerChannel.setMethodCallHandler(_eventHandleMethod);
      iosNativeChannel.setMethodCallHandler(_eventHandleMethod);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('AdPopcornSSP Demo'),
        ),
        body: _body(),
      ),
    );
  }
  
  Widget _body() {
    return ListView(
          children: [
            _setNativeView(),
            _setBannerView(),
          ],
        );
  }
  
  Widget _setBannerView() {
    const String viewType = 'AdPopcornSSPBannerView';
    if (Platform.isAndroid) {
      final Map<String, dynamic> creationParams = <String, dynamic>
      {'appKey':'663451319', 'placementId':'BANNER_320x50', 'bannerSize':'320x50'};
      return Container(
        width: double.maxFinite,
        height:50,
        child: AndroidView(
          viewType: viewType,
          layoutDirection: TextDirection.ltr,
          creationParams: creationParams,
          creationParamsCodec: const StandardMessageCodec(),
        ),
      );
    }
    else if (Platform.isIOS) {
      final Map<String, dynamic> creationParams = <String, dynamic>
      {'appKey':'397261446', 'placementId':'iOS_BANNER_320x50', 'bannerSize':'320x50'};
      return Container(
        width: double.maxFinite,
        height:50,
        child: UiKitView(
          viewType: viewType,
          layoutDirection: TextDirection.ltr,
          creationParams: creationParams,
          creationParamsCodec: const StandardMessageCodec(),
        ),
      );
    }
    else{
      return Container(
        width: double.maxFinite,
        height: 1
      );
    }
  }
  Widget _setNativeView() {
    const String viewType = 'AdPopcornSSPNativeView';
    if (Platform.isAndroid) {
      final Map<String, dynamic> creationParams = <String, dynamic>
      {'appKey':'436579265', 'placementId':'5Z0zysQ2S0EtyGb'};
      return Container(
        width: 300,
        height:280,
        child: AndroidView(
          viewType: viewType,
          layoutDirection: TextDirection.ltr,
          creationParams: creationParams,
          creationParamsCodec: const StandardMessageCodec(),
        ),
      );
    }
    else if (Platform.isIOS) {
      final Map<String, dynamic> creationParams = <String, dynamic>
      {'appKey':'537048423', 'placementId':'Q4KfnX4XPBg1uzL'};
      return Container(
        height: 60,
        child: UiKitView(
          viewType: viewType,
          layoutDirection: TextDirection.ltr,
          creationParams: creationParams,
          creationParamsCodec: const StandardMessageCodec(),
        ),
      );
    }
    else{
      return Container(
          width: double.maxFinite,
          height: 1
      );
    }
  }

    static Future<dynamic> _eventHandleMethod(MethodCall call) {
      print('_eventHandleMethod: ${call.method}, ${call.arguments}');
      final Map<dynamic, dynamic> arguments = call.arguments;
      final String method = call.method;

      final String placementId = arguments['placementId'];
      if (method == 'APSSPBannerViewLoadSuccess') {
        print('main.dart APSSPBannerViewLoadSuccess');
      } else if (method == 'APSSPBannerViewLoadFail') {
        final int errorCode = arguments['errorCode'];
        print('main.dart APSSPBannerViewLoadFail');
      } else if (method == 'APSSPBannerViewClicked') {
        print('main.dart APSSPBannerViewClicked');
      } else if (method == 'APSSPNativeAdLoadSuccess') {
        print('main.dart APSSPNativeAdLoadSuccess');
      } else if (method == 'APSSPNativeAdLoadFail') {
        final int errorCode = arguments['errorCode'];
        print('main.dart APSSPNativeAdLoadFail');
      } else if (method == 'APSSPNativeAdImpression') {
        print('main.dart APSSPNativeAdImpression');
      } else if (method == 'APSSPNativeAdClicked') {
        print('main.dart APSSPNativeAdClicked');
      }
      return Future<dynamic>.value(null);
    }
}
1
likes
130
points
233
downloads

Publisher

unverified uploader

Weekly Downloads

AdPopcornSSP Flutter plugin project.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on adpopcornssp_flutter

Packages that implement adpopcornssp_flutter