diff --git a/android/build.gradle b/android/build.gradle index da58a20..6cd5e53 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -89,12 +89,11 @@ android { dependencies { // compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") - implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' // 广告 SDK https://central.sonatype.com/artifact/com.qq.e.union/union/versions - implementation 'com.qq.e.union:union:4.580.1450' + implementation 'com.qq.e.union:union:4.610.1480' } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index e24471c..bd5d45d 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,7 +1,6 @@ plugins { id "com.android.application" id "kotlin-android" - // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id "dev.flutter.flutter-gradle-plugin" } @@ -35,36 +34,18 @@ android { } defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - // applicationId = "com.example.union_ad_ssgf_example" - applicationId = "com.banjixiaoguanjia.app" - // You can update the following values to match your application needs. - // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + applicationId = "com.example.union_ad_ssgf_example" minSdk = flutter.minSdkVersion targetSdk = flutter.targetSdkVersion versionCode = flutterVersionCode.toInteger() versionName = flutterVersionName } - - //签名信息 - signingConfigs { - release { - storeFile new File("${project.projectDir}/keystore/flutterads_key.jks") - storePassword "FlutterAds" - keyAlias 'FlutterAdsQQ' - keyPassword "FlutterAds" - // 2个版本的签名 - v1SigningEnabled true - v2SigningEnabled true - } - } - buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.release + // signingConfig signingConfigs.release } } } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 3ca558e..5a47b50 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ createState() => _HomePageState(); } class _HomePageState extends State { - String _adEvent = ''; + String adVersion = ''; + StreamSubscription? _adViewStream; + + @override + void dispose() { + _adViewStream?.cancel(); + super.dispose(); + } @override void initState() { super.initState(); - setAdEvent(); + version(); + _adViewStream = FlutterUnionAdStream.initAdStream( + //激励广告 + flutterTencentadRewardCallBack: FlutterUnionAdRewardCallBack( + onShow: () { + print("激励广告显示"); + }, + onClick: () { + print("激励广告点击"); + }, + onFail: (code, message) { + print("激励广告失败 $code $message"); + }, + onClose: () { + print("激励广告关闭"); + }, + onReady: () async { + print("激励广告预加载准备就绪"); + await FlutterUnionAd.showRewardVideoAd(); + }, + onUnReady: () { + print("激励广告预加载未准备就绪"); + }, + onVerify: (transId, rewardName, rewardAmount) { + print("激励广告奖励 $transId $rewardName $rewardAmount"); + }, + onExpose: () { + print("激励广告曝光"); + }, + onFinish: () { + print("激励广告完成"); + }, + onECPM: (ecpmLevel, ecpm) async { + print("激励广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm"); + //规则 自己根据业务处理 + if (ecpm > 0) { + //竞胜出价,类型为Integer + //最大竞败方出价,类型为Integer + await FlutterUnionAd.showRewardVideoAd( + result: FlutterUnioAdBiddingResult().success(ecpm, 0)); + } else { + //竞胜方出价(单位:分),类型为Integer + //优量汇广告竞败原因 FlutterTencentAdBiddingLossReason + //竞胜方渠道ID FlutterTencentAdADNID + await FlutterUnionAd.showRewardVideoAd( + result: FlutterUnioAdBiddingResult().fail( + 1000, + FlutterTencentAdBiddingLossReason.LOW_PRICE, + FlutterTencentAdADNID.othoerADN)); + } + }, + ), + flutterTencentadInteractionCallBack: FlutterUnionAdInteractionCallBack( + onShow: () { + print("插屏广告显示"); + }, + onClick: () { + print("插屏广告点击"); + }, + onFail: (code, message) { + print("插屏广告失败 $code $message"); + }, + onClose: () { + print("插屏广告关闭"); + }, + onExpose: () { + print("插屏广告曝光"); + }, + onReady: () async { + print("插屏广告预加载准备就绪"); + await FlutterUnionAd.showUnifiedInterstitialAD(); + }, + onUnReady: () { + print("插屏广告预加载未准备就绪"); + }, + onVerify: (transId, rewardName, rewardAmount) { + print("插屏广告奖励凭证id $transId"); + }, + onECPM: (ecpmLevel, ecpm) async { + print("插屏广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm"); + //规则 自己根据业务处理 + if (ecpm > 0) { + //竞胜出价,类型为Integer + //最大竞败方出价,类型为Integer + await FlutterUnionAd.showUnifiedInterstitialAD( + result: FlutterUnioAdBiddingResult().success(ecpm, 0)); + } else { + //竞胜方出价(单位:分),类型为Integer + //优量汇广告竞败原因 FlutterTencentAdBiddingLossReason + //竞胜方渠道ID FlutterTencentAdADNID + await FlutterUnionAd.showUnifiedInterstitialAD( + result: FlutterUnioAdBiddingResult().fail( + 1000, + FlutterTencentAdBiddingLossReason.LOW_PRICE, + FlutterTencentAdADNID.othoerADN)); + } + }, + ), + ); } @override Widget build(BuildContext context) { - TextStyle style = const TextStyle(fontSize: 12); return Scaffold( appBar: AppBar( title: const Text('Union AD plugin'), @@ -35,58 +137,17 @@ class _HomePageState extends State { padding: const EdgeInsets.all(10), child: Column( children: [ - const SizedBox(height: 10), - Text('Result: $_result'), - const SizedBox(height: 10), - Text('onAdEvent: $_adEvent'), + Text('初始化: ${widget.initAD}'), + Text('当前版本: $adVersion'), const SizedBox(height: 20), Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.center, children: [ - ElevatedButton( - child: Text( - '初始化', - style: style, - ), - onPressed: () {}, - ), - const SizedBox(height: 20), - ElevatedButton( - child: Text( - '请求跟踪授权', - style: style, - ), - onPressed: () { - requestIDFA(); - }, - ), - const SizedBox(height: 20), - ElevatedButton( - child: Text( - '个性化广告', - style: style, - ), - onPressed: () { - setPersonalizedAd(1); - }, - ), - ], - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - child: const Text('开屏(Logo2)'), - onPressed: () { - showSplashAd(AdsConfig.logo2); - setState(() {}); - }, - ), const SizedBox(height: 20), ElevatedButton( child: const Text('开屏(全屏)'), onPressed: () { - showSplashAd(); + showSplashAd(context); setState(() {}); }, ), @@ -98,17 +159,14 @@ class _HomePageState extends State { ElevatedButton( child: const Text('插屏广告'), onPressed: () { - showInterstitialAd(AdsConfig.interstitialId); + showInterstitialAd(); }, ), const SizedBox(height: 20), ElevatedButton( child: const Text('插全屏广告'), onPressed: () { - showInterstitialAd( - AdsConfig.interstitialFullScreenVideoId, - showFullScreenVideo: true, - ); + showInterstitialAd(); }, ), ], @@ -119,11 +177,7 @@ class _HomePageState extends State { ElevatedButton( child: const Text('插屏激励'), onPressed: () { - showInterstitialAd( - AdsConfig.interstitialRewardVideoId, - showFullScreenVideo: true, - showRewardVideo: true, - ); + showInterstitialAd(); }, ), const SizedBox(height: 20), @@ -138,23 +192,11 @@ class _HomePageState extends State { const SizedBox(height: 20), ElevatedButton( child: const Text('信息流'), - onPressed: () { - // Navigator.push( - // context, - // MaterialPageRoute( - // builder: (context) => FeedPage(),)); - }, + onPressed: () {}, ), const SizedBox(height: 20), const Center(child: Text('👇🏻 Banner 广告 👇🏻')), const SizedBox(height: 10), - // AdBannerWidget( - // posId: AdsConfig.bannerId, - // width: 300, - // height: 80, - // interval: 0, - // show: true, - // ), const SizedBox(height: 10), ], ), @@ -163,57 +205,53 @@ class _HomePageState extends State { ); } - /// 设置广告监听 - Future setAdEvent() async { - setState(() { - _adEvent = '设置成功'; - }); - } - - /// 请求应用跟踪透明度授权 - Future requestIDFA() async { - bool result = false; - _adEvent = '请求广告标识符:$result'; - setState(() {}); - } - - /// 设置个性化广告 - /// [state] 0:不限制 1:限制 - Future setPersonalizedAd(int state) async { - bool result = false; - _adEvent = '设置个性化广告:$result'; - setState(() {}); - } - /// 展示插屏广告 - Future showInterstitialAd( - String posId, { - bool showFullScreenVideo = false, - bool showRewardVideo = false, - }) async { - setState(() {}); - } + Future showInterstitialAd() async {} - /// 展示激励视频广告 - Future showRewardVideoAd() async { - try { - bool result = false; - _result = "展示激励视频广告${result ? '成功' : '失败'}"; - } on PlatformException catch (e) { - _result = - "展示激励视频广告失败 code:${e.code} msg:${e.message} details:${e.details}"; - } - setState(() {}); + /// 当前版本 + Future version() async { + String result = await FlutterUnionAd.getSDKVersion(); + debugPrint("广告SDK 版本 $result"); + setState(() { + adVersion = result; + }); } } /// 展示开屏广告 -/// [logo] 展示如果传递则展示logo,不传递不展示 -Future showSplashAd([String? logo]) async { - try { - bool result = false; - _result = "展示开屏广告${result ? '成功' : '失败'}"; - } on PlatformException catch (e) { - _result = "展示开屏广告失败 code:${e.code} msg:${e.message} details:${e.details}"; - } +Future showSplashAd(context) async { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) { + return SplashPage( + isBidding: false, + androidId: AdsConfig.androidSplashId, + iosId: AdsConfig.iosSplashId, + ); + }, + ), + ); +} + +/// 展示激励视频广告 +Future showRewardVideoAd() async { + await FlutterUnionAd.loadRewardVideoAd( + //android广告id + androidId: AdsConfig.androidRewardVideoId, + //ios广告id + iosId: AdsConfig.iosRewardVideoId, + //用户id + userID: "123", + //奖励 + rewardName: "100金币", + //奖励数 + rewardAmount: 100, + //扩展参数 服务器回调使用 + customData: "", + //下载二次确认弹窗 默认false + downloadConfirm: true, + //开启竞价 + isBidding: true, + ); } diff --git a/example/lib/main.dart b/example/lib/main.dart index f5927b2..b25241a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,7 @@ +import 'dart:async'; import 'package:flutter/material.dart'; import 'package:union_ad_ssgf/flutter_union_ad.dart'; -import 'dart:async'; +import 'package:union_ad_ssgf_example/ads_config.dart'; import 'package:union_ad_ssgf_example/home_page.dart'; void main() { @@ -16,37 +17,32 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { + bool initAd = false; @override void initState() { super.initState(); - init().then((value) { - print("<---- { value : $value } ---->"); - }); + init(); } @override Widget build(BuildContext context) { - return const MaterialApp( - home: HomePage(), + return MaterialApp( + home: HomePage(initAD: initAd), ); } /// 初始化广告 SDK - Future init() async { + Future init() async { bool result = await FlutterUnionAd.register( - androidId: "1200310001", - // androidId - iosId: "1202937154", - // iosId - debug: true, - // 是否显示日志log - personalized: FlutterTencentadPersonalized.show, - // 是否显示个性化推荐广告 + androidId: AdsConfig.androidAppId, + iosId: AdsConfig.iosAppId, + debug: true, // 是否显示日志log + personalized: FlutterTencentadPersonalized.show, // 是否显示个性化推荐广告 channelId: FlutterTencentadChannel.tencent, //渠道id ); - print("------>>>> $result"); - print("----->> result: $result"); debugPrint("广告SDK 初始化${result ? '成功' : '失败'}"); - return result; + setState(() { + initAd = result; + }); } } diff --git a/example/lib/splash_page.dart b/example/lib/splash_page.dart new file mode 100644 index 0000000..142c220 --- /dev/null +++ b/example/lib/splash_page.dart @@ -0,0 +1,89 @@ +import 'package:flutter/material.dart'; +import 'package:union_ad_ssgf/flutter_union_ad.dart'; + +// ignore: must_be_immutable +class SplashPage extends StatefulWidget { + bool isBidding; + String androidId; + String iosId; + + SplashPage({ + super.key, + required this.isBidding, + required this.androidId, + required this.iosId, + }); + + @override + State createState() => _SplashPageState(); +} + +class _SplashPageState extends State { + final FlutterUnioAdBiddingController _bidding = + FlutterUnioAdBiddingController(); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Container( + color: Colors.red, + child: FlutterUnionAd.splashAdView( + // android广告id + androidId: widget.androidId, + // ios广告id + iosId: widget.iosId, + // 设置开屏广告从请求到展示所花的最大时长(并不是指广告曝光时长),取值范围为[1500, 5000]ms + fetchDelay: 3000, + // 下载二次确认弹窗 默认false + downloadConfirm: true, + // 是否开启竞价 默认不开启 + isBidding: widget.isBidding, + // 竞价结果回传 + bidding: _bidding, + // 广告回调 + callBack: FlutterUnionAdSplashCallBack( + onShow: () { + print("开屏广告显示"); + }, + onADTick: (time) { + print("开屏广告倒计时剩余时间 $time"); + }, + onClick: () { + print("开屏广告点击"); + }, + onClose: () { + print("开屏广告关闭"); + Navigator.pop(context); + }, + onExpose: () { + print("开屏广告曝光"); + }, + onFail: (code, message) { + print("开屏广告失败 $code $message"); + Navigator.pop(context); + }, + onECPM: (ecpmLevel, ecpm) { + print("开屏广告竞价 ecpmLevel=$ecpmLevel ecpm=$ecpm"); + // 规则 自己根据业务处理 + if (ecpm > 0) { + // 竞胜出价,类型为Integer + // 最大竞败方出价,类型为Integer + _bidding.biddingResult( + FlutterUnioAdBiddingResult().success(ecpm, 0)); + } else { + // 竞胜方出价(单位:分),类型为Integer + // 优量汇广告竞败原因 FlutterTencentAdBiddingLossReason + // 竞胜方渠道ID FlutterTencentAdADNID + _bidding.biddingResult(FlutterUnioAdBiddingResult().fail( + 1000, + FlutterTencentAdBiddingLossReason.LOW_PRICE, + FlutterTencentAdADNID.othoerADN, + )); + } + }, + ), + ), + ), + ); + } +} diff --git a/lib/banner/banner_ad_view.dart b/lib/banner/banner_ad_view.dart index 96ec2e3..46e572d 100644 --- a/lib/banner/banner_ad_view.dart +++ b/lib/banner/banner_ad_view.dart @@ -31,12 +31,10 @@ class BannerAdView extends StatefulWidget { class _BannerAdViewState extends State { final String _viewType = "com.example.union_ad_ssgf/BannerAdView"; - MethodChannel? _channel; - + //广告是否显示 bool _isShowAd = true; - double _width = 0; double _height = 0; @@ -90,16 +88,16 @@ class _BannerAdViewState extends State { } } - //注册cannel + // 注册 cannel void _registerChannel(int id) { _channel = MethodChannel("${_viewType}_$id"); _channel?.setMethodCallHandler(_platformCallHandler); widget.bidding?.init(_channel); } - //监听原生view传值 + // 监听原生view传值 Future _platformCallHandler(MethodCall call) async { - print("${call.method} ==== ${call.arguments}"); + debugPrint("${call.method} ==== ${call.arguments}"); switch (call.method) { //显示广告 case FlutterTencentadMethod.onShow: diff --git a/lib/express/express_ad_view.dart b/lib/express/express_ad_view.dart index 089b430..a9bd8d5 100644 --- a/lib/express/express_ad_view.dart +++ b/lib/express/express_ad_view.dart @@ -31,12 +31,10 @@ class ExpressAdView extends StatefulWidget { class _ExpressAdViewState extends State { final String _viewType = "com.example.union_ad_ssgf/NativeExpressAdView"; - MethodChannel? _channel; - //广告是否显示 bool _isShowAd = true; - + double _width = 0; double _height = 0; diff --git a/lib/flutter_unio_ad_bidding_controller.dart b/lib/flutter_unio_ad_bidding_controller.dart index f987006..7938582 100644 --- a/lib/flutter_unio_ad_bidding_controller.dart +++ b/lib/flutter_unio_ad_bidding_controller.dart @@ -1,22 +1,21 @@ part of 'flutter_union_ad.dart'; -/// @Description: 优量汇竞价 +/// 优量汇竞价 class FlutterUnioAdBiddingController { late MethodChannel? _methodChannel; - init(MethodChannel? method) { _methodChannel = method; } - //回传竞价结果 - void biddingResult(FlutterTencentBiddingResult result) { - //竞价成功 + // 回传竞价结果 + void biddingResult(FlutterUnioAdBiddingResult result) { + // 竞价成功 if (result.isSuccess) { _methodChannel?.invokeMethod('biddingSucceeded', { 'expectCostPrice': result.expectCostPrice, 'highestLossPrice': result.highestLossPrice, }); - //竞价失败 + // 竞价失败 } else { _methodChannel?.invokeMethod('biddingSucceeded', { 'winPrice': result.winPrice, @@ -27,46 +26,41 @@ class FlutterUnioAdBiddingController { } } -class FlutterTencentBiddingResult { +class FlutterUnioAdBiddingResult { int? expectCostPrice; int? highestLossPrice; int? winPrice; int? lossReason; String? adnId; - bool isSuccess = true; + FlutterUnioAdBiddingResult(); - FlutterTencentBiddingResult(); - - ///竞价成功 - /// + /// 竞价成功 ///[expectCostPrice] 竞胜出价,类型为Integer - /// ///[highestLossPrice] 最大竞败方出价,类型为Integer - FlutterTencentBiddingResult success( - int expectCostPrice, int highestLossPrice) { - this.isSuccess = true; + FlutterUnioAdBiddingResult success( + int expectCostPrice, + int highestLossPrice, + ) { + isSuccess = true; this.expectCostPrice = expectCostPrice; this.highestLossPrice = highestLossPrice; return this; } - ///竞价失败 - /// + /// 竞价失败 /// [winPrice] 本次竞胜方出价(单位:分),类型为Integer。选填 - /// /// [lossReason] 优量汇广告竞败原因,类型为Integer。必填 [FlutterTencentAdBiddingLossReason] - /// /// [adnId] 本次竞胜方渠道ID,类型为Integer。必填。 [FlutterTencentAdADNID] - FlutterTencentBiddingResult fail(int winPrice, int lossReason, String adnId) { - this.isSuccess = false; + FlutterUnioAdBiddingResult fail(int winPrice, int lossReason, String adnId) { + isSuccess = false; this.winPrice = winPrice; this.lossReason = lossReason; this.adnId = adnId; return this; } - FlutterTencentBiddingResult.fromJson(Map json) { + FlutterUnioAdBiddingResult.fromJson(Map json) { expectCostPrice = json['expectCostPrice']; highestLossPrice = json['highestLossPrice']; winPrice = json['winPrice']; @@ -75,13 +69,13 @@ class FlutterTencentBiddingResult { } Map toJson() { - final Map data = new Map(); - data['isSuccess'] = this.isSuccess; - data['expectCostPrice'] = this.expectCostPrice; - data['highestLossPrice'] = this.highestLossPrice; - data['winPrice'] = this.winPrice; - data['lossReason'] = this.lossReason; - data['adnId'] = this.adnId; + final Map data = {}; + data['isSuccess'] = isSuccess; + data['expectCostPrice'] = expectCostPrice; + data['highestLossPrice'] = highestLossPrice; + data['winPrice'] = winPrice; + data['lossReason'] = lossReason; + data['adnId'] = adnId; return data; } } diff --git a/lib/flutter_union_ad.dart b/lib/flutter_union_ad.dart index 17c7103..0b5d40d 100644 --- a/lib/flutter_union_ad.dart +++ b/lib/flutter_union_ad.dart @@ -2,33 +2,24 @@ export 'flutter_union_ad_stream.dart'; export 'flutter_union_ad_code.dart.dart'; import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:union_ad_ssgf/banner/banner_ad_view.dart'; import 'package:union_ad_ssgf/splash/splash_ad_view.dart'; import 'flutter_union_ad_code.dart.dart'; - import 'express/express_ad_view.dart'; part 'flutter_union_ad_callback.dart'; - part 'flutter_unio_ad_bidding_controller.dart'; class FlutterUnionAd { static const MethodChannel _channel = MethodChannel('flutter_union_ad'); - /// - /// # SDK注册初始化 - /// + /// SDK注册初始化 /// [androidId] androidId 必填 - /// /// [iosId] iosId 必填 - /// /// [channelId] channelId 渠道id [FlutterTencentadChannel] - /// /// [personalized] personalized 是否开启个性化广告 [FlutterTencentadPersonalized] - /// static Future register({ required String androidId, required String iosId, @@ -45,32 +36,20 @@ class FlutterUnionAd { }); } - /// - /// # 获取SDK版本号 - /// + /// 获取SDK版本号 static Future getSDKVersion() async { return await _channel.invokeMethod("getSDKVersion"); } - /// - /// # 激励视频广告预加载 - /// - /// [androidId] android广告ID - /// - /// [iosId] ios广告ID - /// + /// 激励视频广告预加载 + /// [androidId] android 广告ID + /// [iosId] ios 广告ID /// [rewardName] 奖励名称 - /// /// [rewardAmount] 奖励金额 - /// /// [userID] 用户id - /// /// [customData] 扩展参数,服务器回调使用 - /// /// [downloadConfirm] 下载二次确认弹窗 默认false - /// /// [videoMuted] 是否静音 默认false - /// /// [isBidding] 是否开启竞价模式 默认false static Future loadRewardVideoAd({ required String androidId, @@ -96,29 +75,23 @@ class FlutterUnionAd { }); } - /// - /// # 显示激励广告 - /// - /// [result] 竞价成功、失败后调用 [FlutterTencentBiddingResult] ,isBidding = true时必传 - static Future showRewardVideoAd( - {FlutterTencentBiddingResult? result}) async { + /// 显示激励广告 + /// [result] 竞价成功、失败后调用 [FlutterUnioAdBiddingResult] ,isBidding = true时必传 + static Future showRewardVideoAd({ + FlutterUnioAdBiddingResult? result, + }) async { return await _channel.invokeMethod( - "showRewardVideoAd", result?.toJson() ?? {}); + "showRewardVideoAd", + result?.toJson() ?? {}, + ); } - /// - /// # 预加载插屏广告 - /// + /// 预加载插屏广告 /// [androidId] android广告ID - /// /// [iosId] ios广告ID - /// - /// [isFullScreen] 是否全屏 - /// + /// [isFullScreen] 是否全屏 /// [downloadConfirm] 下载二次确认弹窗 默认false - /// /// [isBidding] 是否开启竞价模式 默认false - /// static Future loadUnifiedInterstitialAD({ required String androidId, required String iosId, @@ -135,37 +108,27 @@ class FlutterUnionAd { }); } - /// - /// # 显示新模板渲染插屏 - /// - /// - /// [result] 竞价成功、失败后调用 [FlutterTencentBiddingResult] ,isBidding = true时必传 - /// - static Future showUnifiedInterstitialAD( - {FlutterTencentBiddingResult? result}) async { + /// 显示新模板渲染插屏 + /// [result] 竞价成功、失败后调用 [FlutterUnioAdBiddingResult] ,isBidding = true时必传 + static Future showUnifiedInterstitialAD({ + FlutterUnioAdBiddingResult? result, + }) async { return await _channel.invokeMethod( - "showInterstitialAD", result?.toJson() ?? {}); + "showInterstitialAD", + result?.toJson() ?? {}, + ); } /// - /// # banner广告 - /// + /// banner广告 /// [androidId] android广告ID - /// /// [iosId] ios广告ID - /// /// [viewWidth] 广告宽 单位dp - /// /// [viewHeight] 广告高 单位dp 宽高比应该为6.4:1 - /// - /// [FlutterTencentAdBannerCallBack] 广告回调 - /// + /// [FlutterUnionAdBannerCallBack] 广告回调 /// [downloadConfirm] 下载二次确认弹窗 默认false - /// /// [isBidding] 是否开启竞价模式 默认false - /// - /// [bidding] 竞价成功、失败后调用 [FlutterTencentAdBiddingController] ,isBidding = true时必传 - /// + /// [bidding] 竞价成功、失败后调用 [FlutterUnioAdBiddingController] ,isBidding = true时必传 static Widget bannerAdView({ required String androidId, required String iosId, @@ -188,25 +151,14 @@ class FlutterUnionAd { ); } - /// - /// # 开屏广告 - /// + /// 开屏广告 /// [androidId] android广告ID - /// /// [iosId] ios广告ID - /// - /// [fetchDelay] 设置开屏广告从请求到展示所花的最大时长(并不是指广告曝光时长), - /// 取值范围为[1500, 5000]ms。如果需要使用默认值,可以调用上一个构造方法, - /// 或者给 fetchDelay 设为0。 - /// - /// [FlutterTencentAdSplashCallBack] 广告回调 - /// + /// [fetchDelay] 设置开屏广告从请求到展示所花的最大时长(并不是指广告曝光时长),取值范围为[1500, 5000]ms。如果需要使用默认值,可以调用上一个构造方法,或者给 fetchDelay 设为0。 + /// [FlutterUnionAdSplashCallBack] 广告回调 /// [downloadConfirm] 下载二次确认弹窗 默认false - /// /// [isBidding] 是否开启竞价模式 默认false - /// - /// [bidding] 竞价成功、失败后调用 [FlutterTencentAdBiddingController] ,isBidding = true时必传 - /// + /// [bidding] 竞价成功、失败后调用 [FlutterUnioAdBiddingController] ,isBidding = true时必传 static Widget splashAdView({ required String androidId, required String iosId, @@ -227,25 +179,15 @@ class FlutterUnionAd { ); } - /// - /// # 动态信息流/横幅/视频贴片广告 - /// + /// 动态信息流/横幅/视频贴片广告 /// [androidId] android广告ID - /// /// [iosId] ios广告ID - /// /// [viewWidth] 广告宽 单位dp - /// /// [viewHeight] 广告高 单位dp - /// - /// [FlutterTencentAdExpressCallBack] 回调事件 - /// + /// [FlutterUnionAdExpressCallBack] 回调事件 /// [downloadConfirm] 下载二次确认弹窗 默认false - /// /// [isBidding] 是否开启竞价模式 默认false - /// - /// [bidding] 竞价成功、失败后调用 [FlutterTencentAdBiddingController] ,isBidding = true时必传 - /// + /// [bidding] 竞价成功、失败后调用 [FlutterUnioAdBiddingController] ,isBidding = true时必传 static Widget expressAdView({ required String androidId, required String iosId, diff --git a/lib/flutter_union_ad_callback.dart b/lib/flutter_union_ad_callback.dart index ee21c7e..476bd7a 100644 --- a/lib/flutter_union_ad_callback.dart +++ b/lib/flutter_union_ad_callback.dart @@ -1,7 +1,5 @@ part of 'flutter_union_ad.dart'; -/// @Description: dart类作用描述 - ///显示 typedef TOnShow = void Function(); diff --git a/lib/flutter_union_ad_stream.dart b/lib/flutter_union_ad_stream.dart index 907c082..9b3d981 100644 --- a/lib/flutter_union_ad_stream.dart +++ b/lib/flutter_union_ad_stream.dart @@ -1,7 +1,5 @@ import 'dart:async'; - import 'package:flutter/services.dart'; - import 'flutter_union_ad.dart'; /// @Description: dart类作用描述 @@ -9,15 +7,13 @@ const EventChannel tencentAdEventEvent = EventChannel("com.example.union_ad_ssgf/adevent"); class FlutterUnionAdStream { - /// - /// # 注册stream监听原生返回的信息 + /// 注册stream监听原生返回的信息 /// [rewardAdCallBack] 激励广告回调 /// [interactionAdCallBack] 插屏广告回调 - /// static StreamSubscription initAdStream( {FlutterUnionAdRewardCallBack? flutterTencentadRewardCallBack, FlutterUnionAdInteractionCallBack? flutterTencentadInteractionCallBack}) { - StreamSubscription _adStream = + StreamSubscription adStream = tencentAdEventEvent.receiveBroadcastStream().listen((data) { switch (data[FlutterUnionAdCode.adType]) { ///激励广告 @@ -134,7 +130,7 @@ class FlutterUnionAdStream { break; } }); - return _adStream; + return adStream; } static void deleteAdStream(StreamSubscription stream) { diff --git a/lib/splash/splash_ad_view.dart b/lib/splash/splash_ad_view.dart index 83437cf..58ae9e1 100644 --- a/lib/splash/splash_ad_view.dart +++ b/lib/splash/splash_ad_view.dart @@ -32,7 +32,7 @@ class _SplashAdViewState extends State { MethodChannel? _channel; - //广告是否显示 + // 广告是否显示 bool _isShowAd = true; @override @@ -82,14 +82,14 @@ class _SplashAdViewState extends State { } } - //注册cannel + // 注册cannel void _registerChannel(int id) { _channel = MethodChannel("${_viewType}_$id"); _channel?.setMethodCallHandler(_platformCallHandler); widget.bidding?.init(_channel); } - //监听原生view传值 + // 监听原生view传值 Future _platformCallHandler(MethodCall call) async { switch (call.method) { //显示广告 @@ -101,11 +101,11 @@ class _SplashAdViewState extends State { }); } break; - //关闭 + // 关闭 case FlutterTencentadMethod.onClose: widget.callBack?.onClose!(); break; - //广告加载失败 + // 广告加载失败 case FlutterTencentadMethod.onFail: if (mounted) { setState(() { @@ -115,19 +115,19 @@ class _SplashAdViewState extends State { Map map = call.arguments; widget.callBack?.onFail!(map["code"], map["message"]); break; - //点击 + // 点击 case FlutterTencentadMethod.onClick: widget.callBack?.onClick!(); break; - //曝光 + // 曝光 case FlutterTencentadMethod.onExpose: widget.callBack?.onExpose!(); break; - //倒计时 + // 倒计时 case FlutterTencentadMethod.onADTick: widget.callBack?.onADTick!(call.arguments); break; - //竞价 + // 竞价 case FlutterTencentadMethod.onECPM: Map map = call.arguments; widget.callBack?.onECPM!(map["ecpmLevel"], map["ecpm"]);