优化代码逻辑
This commit is contained in:
parent
e834f3b943
commit
eea39e2ada
@ -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'
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 = (
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
89
example/lib/splash_page.dart
Normal file
89
example/lib/splash_page.dart
Normal 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,
|
||||
));
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -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:
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<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;
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -1,7 +1,5 @@
|
||||
part of 'flutter_union_ad.dart';
|
||||
|
||||
/// @Description: dart类作用描述
|
||||
|
||||
///显示
|
||||
typedef TOnShow = void Function();
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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"]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user