优化代码逻辑

This commit is contained in:
Jin857 2024-11-25 17:53:47 +08:00
parent e834f3b943
commit eea39e2ada
15 changed files with 362 additions and 384 deletions

View File

@ -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'
}

View File

@ -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
}
}
}

View File

@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="FlutterAds"
android:label="SsgfUnionAd"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity

View File

@ -480,7 +480,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = YG7N79K85N;
DEVELOPMENT_TEAM = C7SQQ4J3QK;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
@ -660,7 +660,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = YG7N79K85N;
DEVELOPMENT_TEAM = C7SQQ4J3QK;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
@ -683,7 +683,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = YG7N79K85N;
DEVELOPMENT_TEAM = C7SQQ4J3QK;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (

View File

@ -1,82 +1,31 @@
import 'dart:io';
/// 广
class AdsConfig {
/// Logo
static String get logo {
if (Platform.isAndroid) {
return 'flutterads_logo';
} else {
return 'LaunchImage';
}
}
static String androidAppId = "1208618114";
static String iosAppId = "1208619454";
/// Logo 2
static String get logo2 {
if (Platform.isAndroid) {
return 'flutterads_logo2';
} else {
return 'LaunchImage2';
}
}
static String androidSplashId = "1122289510576542";
static String iosSplashId = "7142786521331351";
/// App id
static String get appId {
return Platform.isAndroid ? '1204814627' : '1204814641';
}
/// 广id
static String get splashId {
return Platform.isAndroid ? '4046660274345204' : '1046662224832381';
}
/// 广id
static String get interstitialId {
return Platform.isAndroid ? '1066865274941328' : '7046066294830767';
}
static String androidInterstitialId = "1066865274941328";
static String iosInterstitialId = "7046066294830767";
/// 广id
static String get interstitialFullScreenVideoId {
if (Platform.isAndroid) {
return '3012521499614895';
} else {
return '3092322459911886';
}
}
static String androidInterstitialFullScreenVideoId = "3012521499614895";
static String iosInterstitialFullScreenVideoId = "3092322459911886";
/// 广id
static String get interstitialRewardVideoId {
if (Platform.isAndroid) {
return '2052820580637311';
} else {
return '9022927550132316';
}
}
static String androidInterstitialRewardVideoId = "2052820580637311";
static String iosInterstitialRewardVideoId = "9022927550132316";
/// 广id
static String get rewardVideoId {
if (Platform.isAndroid) {
return '6086667264144219';
} else {
return '3066367234238599';
}
}
static String androidRewardVideoId = "7162486540988491";
static String iosRewardVideoId = "6102886561536594";
/// Banner 广id
static String get bannerId {
if (Platform.isAndroid) {
return '5086068204047616';
} else {
return '7026465284342149';
}
}
static String androidBannerId = "5086068204047616";
static String iosBannerId = "7026465284342149";
/// 广id
static String get feedId {
if (Platform.isAndroid) {
return '7036167274246466';
} else {
return '8076264204347078';
}
}
static String androidFeedId = "7036167274246466";
static String iosFeedId = "8076264204347078";
}

View File

@ -1,31 +1,133 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:union_ad_ssgf/flutter_union_ad.dart';
import 'package:union_ad_ssgf_example/ads_config.dart';
//
String _result = '';
import 'package:union_ad_ssgf_example/splash_page.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
final bool initAD;
const HomePage({super.key, required this.initAD});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
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<HomePage> {
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<HomePage> {
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<HomePage> {
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<HomePage> {
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<HomePage> {
);
}
/// 广
Future<void> setAdEvent() async {
setState(() {
_adEvent = '设置成功';
});
}
///
Future<void> requestIDFA() async {
bool result = false;
_adEvent = '请求广告标识符:$result';
setState(() {});
}
/// 广
/// [state] 0: 1:
Future<void> setPersonalizedAd(int state) async {
bool result = false;
_adEvent = '设置个性化广告:$result';
setState(() {});
}
/// 广
Future<void> showInterstitialAd(
String posId, {
bool showFullScreenVideo = false,
bool showRewardVideo = false,
}) async {
setState(() {});
}
Future<void> showInterstitialAd() async {}
/// 广
Future<void> showRewardVideoAd() async {
try {
bool result = false;
_result = "展示激励视频广告${result ? '成功' : '失败'}";
} on PlatformException catch (e) {
_result =
"展示激励视频广告失败 code:${e.code} msg:${e.message} details:${e.details}";
}
setState(() {});
///
Future<void> version() async {
String result = await FlutterUnionAd.getSDKVersion();
debugPrint("广告SDK 版本 $result");
setState(() {
adVersion = result;
});
}
}
/// 广
/// [logo] logo
Future<void> 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<void> showSplashAd(context) async {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) {
return SplashPage(
isBidding: false,
androidId: AdsConfig.androidSplashId,
iosId: AdsConfig.iosSplashId,
);
},
),
);
}
/// 广
Future<void> 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,
);
}

View File

@ -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<MyApp> {
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<bool> init() async {
Future<void> 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;
});
}
}

View File

@ -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<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
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,
));
}
},
),
),
),
);
}
}

View File

@ -31,12 +31,10 @@ class BannerAdView extends StatefulWidget {
class _BannerAdViewState extends State<BannerAdView> {
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<BannerAdView> {
}
}
//cannel
// cannel
void _registerChannel(int id) {
_channel = MethodChannel("${_viewType}_$id");
_channel?.setMethodCallHandler(_platformCallHandler);
widget.bidding?.init(_channel);
}
//view传值
// view传值
Future<dynamic> _platformCallHandler(MethodCall call) async {
print("${call.method} ==== ${call.arguments}");
debugPrint("${call.method} ==== ${call.arguments}");
switch (call.method) {
//广
case FlutterTencentadMethod.onShow:

View File

@ -31,12 +31,10 @@ class ExpressAdView extends StatefulWidget {
class _ExpressAdViewState extends State<ExpressAdView> {
final String _viewType = "com.example.union_ad_ssgf/NativeExpressAdView";
MethodChannel? _channel;
//广
bool _isShowAd = true;
double _width = 0;
double _height = 0;

View File

@ -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] IDInteger [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<String, dynamic> json) {
FlutterUnioAdBiddingResult.fromJson(Map<String, dynamic> json) {
expectCostPrice = json['expectCostPrice'];
highestLossPrice = json['highestLossPrice'];
winPrice = json['winPrice'];
@ -75,13 +69,13 @@ class FlutterTencentBiddingResult {
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> data = <String, dynamic>{};
data['isSuccess'] = isSuccess;
data['expectCostPrice'] = expectCostPrice;
data['highestLossPrice'] = highestLossPrice;
data['winPrice'] = winPrice;
data['lossReason'] = lossReason;
data['adnId'] = adnId;
return data;
}
}

View File

@ -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<bool> register({
required String androidId,
required String iosId,
@ -45,32 +36,20 @@ class FlutterUnionAd {
});
}
///
/// # SDK版本号
///
/// SDK版本号
static Future<String> 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<bool> loadRewardVideoAd({
required String androidId,
@ -96,29 +75,23 @@ class FlutterUnionAd {
});
}
///
/// # 广
///
/// [result] [FlutterTencentBiddingResult] ,isBidding = true时必传
static Future<bool> showRewardVideoAd(
{FlutterTencentBiddingResult? result}) async {
/// 广
/// [result] [FlutterUnioAdBiddingResult] ,isBidding = true时必传
static Future<bool> 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<bool> loadUnifiedInterstitialAD({
required String androidId,
required String iosId,
@ -135,37 +108,27 @@ class FlutterUnionAd {
});
}
///
/// #
///
///
/// [result] [FlutterTencentBiddingResult] ,isBidding = true时必传
///
static Future<bool> showUnifiedInterstitialAD(
{FlutterTencentBiddingResult? result}) async {
///
/// [result] [FlutterUnioAdBiddingResult] ,isBidding = true时必传
static Future<bool> 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,

View File

@ -1,7 +1,5 @@
part of 'flutter_union_ad.dart';
/// @Description: dart类作用描述
///
typedef TOnShow = void Function();

View File

@ -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) {

View File

@ -32,7 +32,7 @@ class _SplashAdViewState extends State<SplashAdView> {
MethodChannel? _channel;
//广
// 广
bool _isShowAd = true;
@override
@ -82,14 +82,14 @@ class _SplashAdViewState extends State<SplashAdView> {
}
}
//cannel
// cannel
void _registerChannel(int id) {
_channel = MethodChannel("${_viewType}_$id");
_channel?.setMethodCallHandler(_platformCallHandler);
widget.bidding?.init(_channel);
}
//view传值
// view传值
Future<dynamic> _platformCallHandler(MethodCall call) async {
switch (call.method) {
//广
@ -101,11 +101,11 @@ class _SplashAdViewState extends State<SplashAdView> {
});
}
break;
//
//
case FlutterTencentadMethod.onClose:
widget.callBack?.onClose!();
break;
//广
// 广
case FlutterTencentadMethod.onFail:
if (mounted) {
setState(() {
@ -115,19 +115,19 @@ class _SplashAdViewState extends State<SplashAdView> {
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"]);