1- import 'dart:async' ;
21import 'dart:io' ;
3-
4- import 'package:flutter/services.dart' ;
5-
2+ import 'flutter_gromore_ads_platform_interface.dart' ;
63import 'event/ad_event_handler.dart' ;
74
85export 'event/ad_event_handler.dart' ;
96export 'view/ad_banner_widget.dart' ;
107
118/// GroMore 广告插件
129class FlutterGromoreAds {
13- // 方法通道
14- static const MethodChannel _methodChannel =
15- MethodChannel ('flutter_gromore_ads' );
16- // 事件通道
17- static const EventChannel _eventChannel =
18- EventChannel ('flutter_gromore_ads_event' );
19-
2010 ///事件回调
2111 ///@params onData 事件回调
2212 static Future <void > onEventListener (
2313 OnAdEventListener onAdEventListener) async {
24- _eventChannel. receiveBroadcastStream ().listen ((data) {
14+ FlutterGromoreAdsPlatform .instance. getEventStream ().listen ((data) {
2515 hanleAdEvent (data, onAdEventListener);
2616 });
2717 }
2818
2919 /// 请求应用跟踪透明度授权(仅 iOS)
3020 static Future <bool > get requestIDFA async {
3121 if (Platform .isIOS) {
32- final bool result = await _methodChannel.invokeMethod ('requestIDFA' );
33- return result;
22+ return FlutterGromoreAdsPlatform .instance.requestIDFA ();
3423 }
3524 return true ;
3625 }
3726
3827 /// 动态请求相关权限(仅 Android)
3928 static Future <bool > get requestPermissionIfNecessary async {
4029 if (Platform .isAndroid) {
41- final bool result =
42- await _methodChannel.invokeMethod ('requestPermissionIfNecessary' );
43- return result;
30+ return FlutterGromoreAdsPlatform .instance.requestPermissionIfNecessary ();
4431 }
4532 return true ;
4633 }
@@ -50,44 +37,30 @@ class FlutterGromoreAds {
5037 /// [config] 配置文件名称
5138 /// [limitPersonalAds] 是否限制个性化广告,0:不限制 1:限制
5239 static Future <bool > initAd (String appId,
53- {String ? config, int limitPersonalAds = 0 }) async {
54- final bool result = await _methodChannel.invokeMethod (
55- 'initAd' ,
56- {
57- 'appId' : appId,
58- 'config' : config,
59- 'limitPersonalAds' : limitPersonalAds,
60- },
40+ {String ? config, int limitPersonalAds = 0 }) {
41+ return FlutterGromoreAdsPlatform .instance.initAd (
42+ appId,
43+ config: config,
44+ limitPersonalAds: limitPersonalAds,
6145 );
62- print (
63- "🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/" );
64- return result;
6546 }
6647
6748 /// 展示开屏广告
6849 /// [posId] 广告位 id
6950 /// [logo] 如果传值则展示底部logo,不传不展示,则全屏展示
7051 /// [timeout] 加载超时时间
7152 static Future <bool > showSplashAd (String posId,
72- {String ? logo, double timeout = 3.5 }) async {
73- final bool result = await _methodChannel.invokeMethod (
74- 'showSplashAd' ,
75- {
76- 'posId' : posId,
77- 'logo' : logo,
78- 'timeout' : timeout,
79- },
53+ {String ? logo, double timeout = 3.5 }) {
54+ return FlutterGromoreAdsPlatform .instance.showSplashAd (
55+ posId,
56+ logo: logo,
57+ timeout: timeout,
8058 );
81- return result;
8259 }
8360
8461 /// 展示插屏广告
8562 /// [posId] 广告位 id
86- static Future <bool > showInterstitialAd (String posId) async {
87- final bool result = await _methodChannel.invokeMethod (
88- 'showInterstitialAd' ,
89- {'posId' : posId},
90- );
91- return result;
63+ static Future <bool > showInterstitialAd (String posId) {
64+ return FlutterGromoreAdsPlatform .instance.showInterstitialAd (posId);
9265 }
9366}
0 commit comments