优化代码逻辑

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 { dependencies {
// compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") // compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")
implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// 广 SDK https://central.sonatype.com/artifact/com.qq.e.union/union/versions // 广 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 { plugins {
id "com.android.application" id "com.android.application"
id "kotlin-android" id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin" id "dev.flutter.flutter-gradle-plugin"
} }
@ -35,36 +34,18 @@ android {
} }
defaultConfig { 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.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.
minSdk = flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger() versionCode = flutterVersionCode.toInteger()
versionName = flutterVersionName 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 { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // 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"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application <application
android:label="FlutterAds" android:label="SsgfUnionAd"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_launcher">
<activity <activity

View File

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

View File

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

View File

@ -1,31 +1,133 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; 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'; import 'package:union_ad_ssgf_example/ads_config.dart';
import 'package:union_ad_ssgf_example/splash_page.dart';
//
String _result = '';
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({super.key}); final bool initAD;
const HomePage({super.key, required this.initAD});
@override @override
State<HomePage> createState() => _HomePageState(); State<HomePage> createState() => _HomePageState();
} }
class _HomePageState extends State<HomePage> { class _HomePageState extends State<HomePage> {
String _adEvent = ''; String adVersion = '';
StreamSubscription? _adViewStream;
@override
void dispose() {
_adViewStream?.cancel();
super.dispose();
}
@override @override
void initState() { void initState() {
super.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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextStyle style = const TextStyle(fontSize: 12);
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Union AD plugin'), title: const Text('Union AD plugin'),
@ -35,58 +137,17 @@ class _HomePageState extends State<HomePage> {
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Column( child: Column(
children: [ children: [
const SizedBox(height: 10), Text('初始化: ${widget.initAD}'),
Text('Result: $_result'), Text('当前版本: $adVersion'),
const SizedBox(height: 10),
Text('onAdEvent: $_adEvent'),
const SizedBox(height: 20), const SizedBox(height: 20),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.center,
children: [ 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), const SizedBox(height: 20),
ElevatedButton( ElevatedButton(
child: const Text('开屏(全屏)'), child: const Text('开屏(全屏)'),
onPressed: () { onPressed: () {
showSplashAd(); showSplashAd(context);
setState(() {}); setState(() {});
}, },
), ),
@ -98,17 +159,14 @@ class _HomePageState extends State<HomePage> {
ElevatedButton( ElevatedButton(
child: const Text('插屏广告'), child: const Text('插屏广告'),
onPressed: () { onPressed: () {
showInterstitialAd(AdsConfig.interstitialId); showInterstitialAd();
}, },
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
ElevatedButton( ElevatedButton(
child: const Text('插全屏广告'), child: const Text('插全屏广告'),
onPressed: () { onPressed: () {
showInterstitialAd( showInterstitialAd();
AdsConfig.interstitialFullScreenVideoId,
showFullScreenVideo: true,
);
}, },
), ),
], ],
@ -119,11 +177,7 @@ class _HomePageState extends State<HomePage> {
ElevatedButton( ElevatedButton(
child: const Text('插屏激励'), child: const Text('插屏激励'),
onPressed: () { onPressed: () {
showInterstitialAd( showInterstitialAd();
AdsConfig.interstitialRewardVideoId,
showFullScreenVideo: true,
showRewardVideo: true,
);
}, },
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
@ -138,23 +192,11 @@ class _HomePageState extends State<HomePage> {
const SizedBox(height: 20), const SizedBox(height: 20),
ElevatedButton( ElevatedButton(
child: const Text('信息流'), child: const Text('信息流'),
onPressed: () { onPressed: () {},
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => FeedPage(),));
},
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
const Center(child: Text('👇🏻 Banner 广告 👇🏻')), const Center(child: Text('👇🏻 Banner 广告 👇🏻')),
const SizedBox(height: 10), const SizedBox(height: 10),
// AdBannerWidget(
// posId: AdsConfig.bannerId,
// width: 300,
// height: 80,
// interval: 0,
// show: true,
// ),
const SizedBox(height: 10), 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( Future<void> showInterstitialAd() async {}
String posId, {
bool showFullScreenVideo = false,
bool showRewardVideo = false,
}) async {
setState(() {});
}
/// 广 ///
Future<void> showRewardVideoAd() async { Future<void> version() async {
try { String result = await FlutterUnionAd.getSDKVersion();
bool result = false; debugPrint("广告SDK 版本 $result");
_result = "展示激励视频广告${result ? '成功' : '失败'}"; setState(() {
} on PlatformException catch (e) { adVersion = result;
_result = });
"展示激励视频广告失败 code:${e.code} msg:${e.message} details:${e.details}";
}
setState(() {});
} }
} }
/// 广 /// 广
/// [logo] logo Future<void> showSplashAd(context) async {
Future<void> showSplashAd([String? logo]) async { Navigator.push(
try { context,
bool result = false; MaterialPageRoute(
_result = "展示开屏广告${result ? '成功' : '失败'}"; builder: (_) {
} on PlatformException catch (e) { return SplashPage(
_result = "展示开屏广告失败 code:${e.code} msg:${e.message} details:${e.details}"; 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:flutter/material.dart';
import 'package:union_ad_ssgf/flutter_union_ad.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'; import 'package:union_ad_ssgf_example/home_page.dart';
void main() { void main() {
@ -16,37 +17,32 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
bool initAd = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
init().then((value) { init();
print("<---- { value : $value } ---->");
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const MaterialApp( return MaterialApp(
home: HomePage(), home: HomePage(initAD: initAd),
); );
} }
/// 广 SDK /// 广 SDK
Future<bool> init() async { Future<void> init() async {
bool result = await FlutterUnionAd.register( bool result = await FlutterUnionAd.register(
androidId: "1200310001", androidId: AdsConfig.androidAppId,
// androidId iosId: AdsConfig.iosAppId,
iosId: "1202937154", debug: true, // log
// iosId personalized: FlutterTencentadPersonalized.show, // 广
debug: true,
// log
personalized: FlutterTencentadPersonalized.show,
// 广
channelId: FlutterTencentadChannel.tencent, //id channelId: FlutterTencentadChannel.tencent, //id
); );
print("------>>>> $result");
print("----->> result: $result");
debugPrint("广告SDK 初始化${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> { class _BannerAdViewState extends State<BannerAdView> {
final String _viewType = "com.example.union_ad_ssgf/BannerAdView"; final String _viewType = "com.example.union_ad_ssgf/BannerAdView";
MethodChannel? _channel; MethodChannel? _channel;
//广 //广
bool _isShowAd = true; bool _isShowAd = true;
double _width = 0; double _width = 0;
double _height = 0; double _height = 0;
@ -90,16 +88,16 @@ class _BannerAdViewState extends State<BannerAdView> {
} }
} }
//cannel // cannel
void _registerChannel(int id) { void _registerChannel(int id) {
_channel = MethodChannel("${_viewType}_$id"); _channel = MethodChannel("${_viewType}_$id");
_channel?.setMethodCallHandler(_platformCallHandler); _channel?.setMethodCallHandler(_platformCallHandler);
widget.bidding?.init(_channel); widget.bidding?.init(_channel);
} }
//view传值 // view传值
Future<dynamic> _platformCallHandler(MethodCall call) async { Future<dynamic> _platformCallHandler(MethodCall call) async {
print("${call.method} ==== ${call.arguments}"); debugPrint("${call.method} ==== ${call.arguments}");
switch (call.method) { switch (call.method) {
//广 //广
case FlutterTencentadMethod.onShow: case FlutterTencentadMethod.onShow:

View File

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

View File

@ -1,22 +1,21 @@
part of 'flutter_union_ad.dart'; part of 'flutter_union_ad.dart';
/// @Description: ///
class FlutterUnioAdBiddingController { class FlutterUnioAdBiddingController {
late MethodChannel? _methodChannel; late MethodChannel? _methodChannel;
init(MethodChannel? method) { init(MethodChannel? method) {
_methodChannel = method; _methodChannel = method;
} }
// //
void biddingResult(FlutterTencentBiddingResult result) { void biddingResult(FlutterUnioAdBiddingResult result) {
// //
if (result.isSuccess) { if (result.isSuccess) {
_methodChannel?.invokeMethod('biddingSucceeded', { _methodChannel?.invokeMethod('biddingSucceeded', {
'expectCostPrice': result.expectCostPrice, 'expectCostPrice': result.expectCostPrice,
'highestLossPrice': result.highestLossPrice, 'highestLossPrice': result.highestLossPrice,
}); });
// //
} else { } else {
_methodChannel?.invokeMethod('biddingSucceeded', { _methodChannel?.invokeMethod('biddingSucceeded', {
'winPrice': result.winPrice, 'winPrice': result.winPrice,
@ -27,46 +26,41 @@ class FlutterUnioAdBiddingController {
} }
} }
class FlutterTencentBiddingResult { class FlutterUnioAdBiddingResult {
int? expectCostPrice; int? expectCostPrice;
int? highestLossPrice; int? highestLossPrice;
int? winPrice; int? winPrice;
int? lossReason; int? lossReason;
String? adnId; String? adnId;
bool isSuccess = true; bool isSuccess = true;
FlutterUnioAdBiddingResult();
FlutterTencentBiddingResult(); ///
///
///
///[expectCostPrice] Integer ///[expectCostPrice] Integer
///
///[highestLossPrice] Integer ///[highestLossPrice] Integer
FlutterTencentBiddingResult success( FlutterUnioAdBiddingResult success(
int expectCostPrice, int highestLossPrice) { int expectCostPrice,
this.isSuccess = true; int highestLossPrice,
) {
isSuccess = true;
this.expectCostPrice = expectCostPrice; this.expectCostPrice = expectCostPrice;
this.highestLossPrice = highestLossPrice; this.highestLossPrice = highestLossPrice;
return this; return this;
} }
/// ///
///
/// [winPrice] Integer /// [winPrice] Integer
///
/// [lossReason] 广Integer [FlutterTencentAdBiddingLossReason] /// [lossReason] 广Integer [FlutterTencentAdBiddingLossReason]
///
/// [adnId] IDInteger [FlutterTencentAdADNID] /// [adnId] IDInteger [FlutterTencentAdADNID]
FlutterTencentBiddingResult fail(int winPrice, int lossReason, String adnId) { FlutterUnioAdBiddingResult fail(int winPrice, int lossReason, String adnId) {
this.isSuccess = false; isSuccess = false;
this.winPrice = winPrice; this.winPrice = winPrice;
this.lossReason = lossReason; this.lossReason = lossReason;
this.adnId = adnId; this.adnId = adnId;
return this; return this;
} }
FlutterTencentBiddingResult.fromJson(Map<String, dynamic> json) { FlutterUnioAdBiddingResult.fromJson(Map<String, dynamic> json) {
expectCostPrice = json['expectCostPrice']; expectCostPrice = json['expectCostPrice'];
highestLossPrice = json['highestLossPrice']; highestLossPrice = json['highestLossPrice'];
winPrice = json['winPrice']; winPrice = json['winPrice'];
@ -75,13 +69,13 @@ class FlutterTencentBiddingResult {
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>(); final Map<String, dynamic> data = <String, dynamic>{};
data['isSuccess'] = this.isSuccess; data['isSuccess'] = isSuccess;
data['expectCostPrice'] = this.expectCostPrice; data['expectCostPrice'] = expectCostPrice;
data['highestLossPrice'] = this.highestLossPrice; data['highestLossPrice'] = highestLossPrice;
data['winPrice'] = this.winPrice; data['winPrice'] = winPrice;
data['lossReason'] = this.lossReason; data['lossReason'] = lossReason;
data['adnId'] = this.adnId; data['adnId'] = adnId;
return data; return data;
} }
} }

View File

@ -2,33 +2,24 @@ export 'flutter_union_ad_stream.dart';
export 'flutter_union_ad_code.dart.dart'; export 'flutter_union_ad_code.dart.dart';
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:union_ad_ssgf/banner/banner_ad_view.dart'; import 'package:union_ad_ssgf/banner/banner_ad_view.dart';
import 'package:union_ad_ssgf/splash/splash_ad_view.dart'; import 'package:union_ad_ssgf/splash/splash_ad_view.dart';
import 'flutter_union_ad_code.dart.dart'; import 'flutter_union_ad_code.dart.dart';
import 'express/express_ad_view.dart'; import 'express/express_ad_view.dart';
part 'flutter_union_ad_callback.dart'; part 'flutter_union_ad_callback.dart';
part 'flutter_unio_ad_bidding_controller.dart'; part 'flutter_unio_ad_bidding_controller.dart';
class FlutterUnionAd { class FlutterUnionAd {
static const MethodChannel _channel = MethodChannel('flutter_union_ad'); static const MethodChannel _channel = MethodChannel('flutter_union_ad');
/// /// SDK注册初始化
/// # SDK注册初始化
///
/// [androidId] androidId /// [androidId] androidId
///
/// [iosId] iosId /// [iosId] iosId
///
/// [channelId] channelId id [FlutterTencentadChannel] /// [channelId] channelId id [FlutterTencentadChannel]
///
/// [personalized] personalized 广 [FlutterTencentadPersonalized] /// [personalized] personalized 广 [FlutterTencentadPersonalized]
///
static Future<bool> register({ static Future<bool> register({
required String androidId, required String androidId,
required String iosId, required String iosId,
@ -45,32 +36,20 @@ class FlutterUnionAd {
}); });
} }
/// /// SDK版本号
/// # SDK版本号
///
static Future<String> getSDKVersion() async { static Future<String> getSDKVersion() async {
return await _channel.invokeMethod("getSDKVersion"); return await _channel.invokeMethod("getSDKVersion");
} }
/// /// 广
/// # 广 /// [androidId] android 广ID
/// /// [iosId] ios 广ID
/// [androidId] android广告ID
///
/// [iosId] ios广告ID
///
/// [rewardName] /// [rewardName]
///
/// [rewardAmount] /// [rewardAmount]
///
/// [userID] id /// [userID] id
///
/// [customData] 使 /// [customData] 使
///
/// [downloadConfirm] false /// [downloadConfirm] false
///
/// [videoMuted] false /// [videoMuted] false
///
/// [isBidding] false /// [isBidding] false
static Future<bool> loadRewardVideoAd({ static Future<bool> loadRewardVideoAd({
required String androidId, required String androidId,
@ -96,29 +75,23 @@ class FlutterUnionAd {
}); });
} }
/// /// 广
/// # 广 /// [result] [FlutterUnioAdBiddingResult] ,isBidding = true时必传
/// static Future<bool> showRewardVideoAd({
/// [result] [FlutterTencentBiddingResult] ,isBidding = true时必传 FlutterUnioAdBiddingResult? result,
static Future<bool> showRewardVideoAd( }) async {
{FlutterTencentBiddingResult? result}) async {
return await _channel.invokeMethod( return await _channel.invokeMethod(
"showRewardVideoAd", result?.toJson() ?? {}); "showRewardVideoAd",
result?.toJson() ?? {},
);
} }
/// /// 广
/// # 广
///
/// [androidId] android广告ID /// [androidId] android广告ID
///
/// [iosId] ios广告ID /// [iosId] ios广告ID
/// /// [isFullScreen]
/// [isFullScreen]
///
/// [downloadConfirm] false /// [downloadConfirm] false
///
/// [isBidding] false /// [isBidding] false
///
static Future<bool> loadUnifiedInterstitialAD({ static Future<bool> loadUnifiedInterstitialAD({
required String androidId, required String androidId,
required String iosId, required String iosId,
@ -135,37 +108,27 @@ class FlutterUnionAd {
}); });
} }
/// ///
/// # /// [result] [FlutterUnioAdBiddingResult] ,isBidding = true时必传
/// static Future<bool> showUnifiedInterstitialAD({
/// FlutterUnioAdBiddingResult? result,
/// [result] [FlutterTencentBiddingResult] ,isBidding = true时必传 }) async {
///
static Future<bool> showUnifiedInterstitialAD(
{FlutterTencentBiddingResult? result}) async {
return await _channel.invokeMethod( return await _channel.invokeMethod(
"showInterstitialAD", result?.toJson() ?? {}); "showInterstitialAD",
result?.toJson() ?? {},
);
} }
/// ///
/// # banner广告 /// banner广告
///
/// [androidId] android广告ID /// [androidId] android广告ID
///
/// [iosId] ios广告ID /// [iosId] ios广告ID
///
/// [viewWidth] 广 dp /// [viewWidth] 广 dp
///
/// [viewHeight] 广 dp 6.4:1 /// [viewHeight] 广 dp 6.4:1
/// /// [FlutterUnionAdBannerCallBack] 广
/// [FlutterTencentAdBannerCallBack] 广
///
/// [downloadConfirm] false /// [downloadConfirm] false
///
/// [isBidding] false /// [isBidding] false
/// /// [bidding] [FlutterUnioAdBiddingController] ,isBidding = true时必传
/// [bidding] [FlutterTencentAdBiddingController] ,isBidding = true时必传
///
static Widget bannerAdView({ static Widget bannerAdView({
required String androidId, required String androidId,
required String iosId, required String iosId,
@ -188,25 +151,14 @@ class FlutterUnionAd {
); );
} }
/// /// 广
/// # 广
///
/// [androidId] android广告ID /// [androidId] android广告ID
///
/// [iosId] ios广告ID /// [iosId] ios广告ID
/// /// [fetchDelay] 广广[1500, 5000]ms使 fetchDelay 0
/// [fetchDelay] 广广 /// [FlutterUnionAdSplashCallBack] 广
/// [1500, 5000]ms使
/// fetchDelay 0
///
/// [FlutterTencentAdSplashCallBack] 广
///
/// [downloadConfirm] false /// [downloadConfirm] false
///
/// [isBidding] false /// [isBidding] false
/// /// [bidding] [FlutterUnioAdBiddingController] ,isBidding = true时必传
/// [bidding] [FlutterTencentAdBiddingController] ,isBidding = true时必传
///
static Widget splashAdView({ static Widget splashAdView({
required String androidId, required String androidId,
required String iosId, required String iosId,
@ -227,25 +179,15 @@ class FlutterUnionAd {
); );
} }
/// /// //广
/// # //广
///
/// [androidId] android广告ID /// [androidId] android广告ID
///
/// [iosId] ios广告ID /// [iosId] ios广告ID
///
/// [viewWidth] 广 dp /// [viewWidth] 广 dp
///
/// [viewHeight] 广 dp /// [viewHeight] 广 dp
/// /// [FlutterUnionAdExpressCallBack]
/// [FlutterTencentAdExpressCallBack]
///
/// [downloadConfirm] false /// [downloadConfirm] false
///
/// [isBidding] false /// [isBidding] false
/// /// [bidding] [FlutterUnioAdBiddingController] ,isBidding = true时必传
/// [bidding] [FlutterTencentAdBiddingController] ,isBidding = true时必传
///
static Widget expressAdView({ static Widget expressAdView({
required String androidId, required String androidId,
required String iosId, required String iosId,

View File

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

View File

@ -1,7 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'flutter_union_ad.dart'; import 'flutter_union_ad.dart';
/// @Description: dart类作用描述 /// @Description: dart类作用描述
@ -9,15 +7,13 @@ const EventChannel tencentAdEventEvent =
EventChannel("com.example.union_ad_ssgf/adevent"); EventChannel("com.example.union_ad_ssgf/adevent");
class FlutterUnionAdStream { class FlutterUnionAdStream {
/// /// stream监听原生返回的信息
/// # stream监听原生返回的信息
/// [rewardAdCallBack] 广 /// [rewardAdCallBack] 广
/// [interactionAdCallBack] 广 /// [interactionAdCallBack] 广
///
static StreamSubscription initAdStream( static StreamSubscription initAdStream(
{FlutterUnionAdRewardCallBack? flutterTencentadRewardCallBack, {FlutterUnionAdRewardCallBack? flutterTencentadRewardCallBack,
FlutterUnionAdInteractionCallBack? flutterTencentadInteractionCallBack}) { FlutterUnionAdInteractionCallBack? flutterTencentadInteractionCallBack}) {
StreamSubscription _adStream = StreamSubscription adStream =
tencentAdEventEvent.receiveBroadcastStream().listen((data) { tencentAdEventEvent.receiveBroadcastStream().listen((data) {
switch (data[FlutterUnionAdCode.adType]) { switch (data[FlutterUnionAdCode.adType]) {
///广 ///广
@ -134,7 +130,7 @@ class FlutterUnionAdStream {
break; break;
} }
}); });
return _adStream; return adStream;
} }
static void deleteAdStream(StreamSubscription stream) { static void deleteAdStream(StreamSubscription stream) {

View File

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