11import 'dart:async' ;
2- import 'dart:io' ;
3-
4- import 'package:flutter/services.dart' ;
52
3+ import 'flutter_pangle_ads_platform_interface.dart' ;
64import 'event/ad_event_handler.dart' ;
75
86export 'event/ad_event_handler.dart' ;
@@ -12,31 +10,15 @@ export 'view/ad_feed_widget.dart';
1210
1311/// 穿山甲广告插件
1412class FlutterPangleAds {
15- // 方法通道
16- static const MethodChannel _methodChannel =
17- const MethodChannel ('flutter_pangle_ads' );
18- // 事件通道
19- static const EventChannel _eventChannel =
20- const EventChannel ('flutter_pangle_ads_event' );
13+ static FlutterPangleAdsPlatform get _platform =>
14+ FlutterPangleAdsPlatform .instance;
2115
2216 /// 请求应用跟踪透明度授权(仅 iOS)
23- static Future <bool > get requestIDFA async {
24- if (Platform .isIOS) {
25- final bool result = await _methodChannel.invokeMethod ('requestIDFA' );
26- return result;
27- }
28- return true ;
29- }
17+ static Future <bool > get requestIDFA => _platform.requestIDFA ();
3018
3119 /// 动态请求相关权限(仅 Android)
32- static Future <bool > get requestPermissionIfNecessary async {
33- if (Platform .isAndroid) {
34- final bool result =
35- await _methodChannel.invokeMethod ('requestPermissionIfNecessary' );
36- return result;
37- }
38- return true ;
39- }
20+ static Future <bool > get requestPermissionIfNecessary =>
21+ _platform.requestPermissionIfNecessary ();
4022
4123 /// 初始化广告
4224 /// [appId] 应用ID
@@ -50,37 +32,23 @@ class FlutterPangleAds {
5032 bool supportMultiProcess = false ,
5133 bool allowShowNotify = true ,
5234 List <int > directDownloadNetworkType = const [],
53- }) async {
54- final bool result = await _methodChannel.invokeMethod (
55- 'initAd' ,
56- {
57- 'appId' : appId,
58- 'useTextureView' : useTextureView,
59- 'supportMultiProcess' : supportMultiProcess,
60- 'allowShowNotify' : allowShowNotify,
61- 'directDownloadNetworkType' : directDownloadNetworkType,
62- },
35+ }) {
36+ return _platform.initAd (
37+ appId,
38+ useTextureView: useTextureView,
39+ supportMultiProcess: supportMultiProcess,
40+ allowShowNotify: allowShowNotify,
41+ directDownloadNetworkType: directDownloadNetworkType,
6342 );
64- print (
65- "🎉🎉🎉 FlutterAds ==> 初始化完成,推荐使用 GroMore Pro 版本,获得更高的收益:https://flutterads.top/" );
66- return result;
6743 }
6844
6945 /// 展示开屏广告
7046 /// [posId] 广告位 id
7147 /// [logo] 如果传值则展示底部logo,不传不展示,则全屏展示
7248 /// [timeout] 加载超时时间
7349 static Future <bool > showSplashAd (String posId,
74- {String ? logo, double timeout = 3.5 }) async {
75- final bool result = await _methodChannel.invokeMethod (
76- 'showSplashAd' ,
77- {
78- 'posId' : posId,
79- 'logo' : logo,
80- 'timeout' : timeout,
81- },
82- );
83- return result;
50+ {String ? logo, double timeout = 3.5 }) {
51+ return _platform.showSplashAd (posId, logo: logo, timeout: timeout);
8452 }
8553
8654 /// 展示激励视频广告
@@ -91,28 +59,15 @@ class FlutterPangleAds {
9159 String posId, {
9260 String ? customData,
9361 String ? userId,
94- }) async {
95- final bool result = await _methodChannel.invokeMethod (
96- 'showRewardVideoAd' ,
97- {
98- 'posId' : posId,
99- 'customData' : customData,
100- 'userId' : userId,
101- },
102- );
103- return result;
62+ }) {
63+ return _platform.showRewardVideoAd (posId,
64+ customData: customData, userId: userId);
10465 }
10566
10667 /// 展示全屏视频、新插屏广告
10768 /// [posId] 广告位 id
108- static Future <bool > showFullScreenVideoAd (String posId) async {
109- final bool result = await _methodChannel.invokeMethod (
110- 'showFullScreenVideoAd' ,
111- {
112- 'posId' : posId,
113- },
114- );
115- return result;
69+ static Future <bool > showFullScreenVideoAd (String posId) {
70+ return _platform.showFullScreenVideoAd (posId);
11671 }
11772
11873 /// 加载信息流广告列表
@@ -121,48 +76,26 @@ class FlutterPangleAds {
12176 /// [height] 高度
12277 /// [count] 获取广告数量,建议 1~3 个
12378 static Future <List <int >> loadFeedAd (String posId,
124- {int width = 375 , int height = 0 , int count = 1 }) async {
125- final List <dynamic > result = await _methodChannel.invokeMethod (
126- 'loadFeedAd' ,
127- {
128- 'posId' : posId,
129- 'width' : width,
130- 'height' : height,
131- 'count' : count,
132- },
133- );
134- return List <int >.from (result);
79+ {int width = 375 , int height = 0 , int count = 1 }) {
80+ return _platform.loadFeedAd (posId,
81+ width: width, height: height, count: count);
13582 }
13683
13784 /// 清除信息流广告列表
13885 /// [list] 信息流广告 id 列表
139- static Future <bool > clearFeedAd (List <int > list) async {
140- final bool result = await _methodChannel.invokeMethod (
141- 'clearFeedAd' ,
142- {
143- 'list' : list,
144- },
145- );
146- return result;
86+ static Future <bool > clearFeedAd (List <int > list) {
87+ return _platform.clearFeedAd (list);
14788 }
14889
14990 ///事件回调
15091 ///@params onData 事件回调
151- static Future <void > onEventListener (
152- OnAdEventListener onAdEventListener) async {
153- _eventChannel.receiveBroadcastStream ().listen ((data) {
154- hanleAdEvent (data, onAdEventListener);
155- });
92+ static Future <void > onEventListener (OnAdEventListener onAdEventListener) {
93+ return _platform.onEventListener (onAdEventListener);
15694 }
15795
15896 /// 设置个性化推荐
15997 /// @params personalAdsType,不传或传空或传非01值没任何影响,默认不屏蔽, 0屏蔽个性化推荐广告, 1不屏蔽个性化推荐广告
160- static setUserExtData ({required String personalAdsType}) async {
161- await _methodChannel.invokeMethod (
162- 'setUserExtData' ,
163- {
164- 'personalAdsType' : personalAdsType,
165- },
166- );
98+ static Future <void > setUserExtData ({required String personalAdsType}) {
99+ return _platform.setUserExtData (personalAdsType: personalAdsType);
167100 }
168101}
0 commit comments