优化代码逻辑
This commit is contained in:
parent
e834f3b943
commit
eea39e2ada
@ -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'
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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 = (
|
||||||
|
@ -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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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> {
|
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:
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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] 本次竞胜方渠道ID,类型为Integer。必填。 [FlutterTencentAdADNID]
|
/// [adnId] 本次竞胜方渠道ID,类型为Integer。必填。 [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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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"]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user