diff --git a/.gitignore b/.gitignore index 07324f5..c838407 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ build/ shell/ +.idea/ +.vscode/ diff --git a/android/build.gradle b/android/build.gradle index 66923f9..42797a4 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -38,6 +38,9 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { + if (project.android.hasProperty("namespace")) { + namespace = "com.zero.flutter_gromore_ads" + } compileSdk 31 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index fe63a49..8be7f83 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -6,7 +6,7 @@ plugins { android { namespace = "com.zero.flutter_gromore_ads_example" - compileSdk = flutter.compileSdkVersion + compileSdk = 34 ndkVersion = flutter.ndkVersion compileOptions { diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 536165d..8a53adc 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -19,7 +19,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "7.3.0" apply false - id "org.jetbrains.kotlin.android" version "1.7.10" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false } include ":app" diff --git a/example/lib/ads_config.dart b/example/lib/ads_config.dart deleted file mode 100644 index f9080c1..0000000 --- a/example/lib/ads_config.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:io'; - -/// 广告配置信息 -class AdsConfig { - /// 获取 Logo 资源名称 - static String get logo { - if (Platform.isAndroid) { - return 'flutterads_logo'; - } else { - return 'LaunchImage'; - } - } - - /// 获取 Logo 资源名称 2 - static String get logo2 { - if (Platform.isAndroid) { - return 'flutterads_logo2'; - } else { - return 'LaunchImage2'; - } - } - - /// 获取 App id - static String get appId { - return '5324024'; - } - - /// 获取开屏广告位id - static String get splashId => '102420790'; - - /// 获取插屏广告位id 竖屏 - static String get interstitialId => '102421471'; - - /// 获取 Banner 广告位id - static String get bannerId => '102424305'; -} diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart deleted file mode 100644 index cf28255..0000000 --- a/example/lib/home_page.dart +++ /dev/null @@ -1,249 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_gromore_ads/flutter_gromore_ads.dart'; - -import 'ads_config.dart'; -import 'pro_page.dart'; - -/// 首页 -class HomePage extends StatefulWidget { - const HomePage({ - Key? key, - }) : super(key: key); - - @override - State createState() => _HomePageState(); -} - -class _HomePageState extends State { - String _result = ''; - String _adEvent = ''; - @override - void initState() { - setAdEvent(); - init().then((value) { - if (value) { - // showSplashAd(AdsConfig.logo); - } - }); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Flutter GroMore Ads'), - ), - body: SingleChildScrollView( - padding: const EdgeInsets.all(20), - child: Column( - children: [ - const SizedBox(height: 10), - Text('Result: $_result'), - const SizedBox(height: 10), - Text('onAdEvent: $_adEvent'), - const SizedBox(height: 20), - SizedBox( - width: double.maxFinite, - child: ElevatedButton( - child: const Text('初始化'), - onPressed: () { - init(); - }, - ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Flexible( - child: ElevatedButton( - child: const Text('请求应用跟踪授权'), - onPressed: () { - requestIDFA(); - }, - ), - ), - const SizedBox(height: 20), - Flexible( - child: ElevatedButton( - child: const Text('动态请求相关权限'), - onPressed: () { - requestPermissionIfNecessary(); - }, - ), - ), - ], - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - child: const Text('开屏广告(Logo)'), - onPressed: () { - showSplashAd(AdsConfig.logo2); - }, - ), - const SizedBox(height: 20), - ElevatedButton( - child: const Text('开屏广告(全屏)'), - onPressed: () { - showSplashAd(); - }, - ), - ], - ), - const SizedBox(height: 20), - ElevatedButton( - child: const Text('插屏广告'), - onPressed: () { - showInterstitialAd(AdsConfig.interstitialId); - }, - ), - const SizedBox(height: 20), - const Center( - child: Text( - '🏆 Pro 版付费功能 🏆', - style: TextStyle( - color: Colors.purple, - fontWeight: FontWeight.bold, - ), - ), - ), - const SizedBox(height: 10), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - child: const Text('信息流广告(Pro)'), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const ProPage(), - )); - }, - ), - const SizedBox(height: 20), - ElevatedButton( - child: const Text('激励视频广告(Pro)'), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const ProPage(), - ), - ); - }, - ), - ], - ), - ], - ), - ), - bottomNavigationBar: SafeArea( - child: Container( - width: double.maxFinite, - height: 140, - color: Colors.grey[200], - alignment: Alignment.center, - child: Column( - children: [ - const SizedBox(height: 10), - const Center(child: Text('👇🏻 Banner 广告 👇🏻')), - const SizedBox(height: 10), - AdBannerWidget( - posId: AdsConfig.bannerId, - width: 300, - height: 75, - ), - ], - )), - ), - ); - } - - /// 初始化广告 SDK - Future init() async { - try { - bool result = await FlutterGromoreAds.initAd( - AdsConfig.appId, - limitPersonalAds: 1, - ); - _result = "广告SDK 初始化${result ? '成功' : '失败'}"; - setState(() {}); - return result; - } on PlatformException catch (e) { - _result = - "广告SDK 初始化失败 code:${e.code} msg:${e.message} details:${e.details}"; - } - setState(() {}); - return false; - } - - /// 设置广告监听 - Future setAdEvent() async { - setState(() { - _adEvent = '设置成功'; - }); - FlutterGromoreAds.onEventListener((event) { - _adEvent = 'adId:${event.adId} action:${event.action}'; - if (event is AdErrorEvent) { - // 错误事件 - _adEvent += ' errCode:${event.errCode} errMsg:${event.errMsg}'; - } else if (event is AdRewardEvent) { - // 激励事件 - _adEvent += - ' rewardVerify:${event.rewardVerify} rewardAmount:${event.rewardAmount} rewardName:${event.rewardName} errCode:${event.errCode} errMsg:${event.errMsg} customData:${event.customData} userId:${event.userId}'; - } - // // 测试关闭 Banner(会员场景) - // if (event.action == AdEventAction.onAdClosed && - // event.adId == AdsConfig.bannerId02) { - // _adEvent += '仅会员可以关闭广告'; - // } - debugPrint('onEventListener:$_adEvent'); - setState(() {}); - }); - } - - /// 请求应用跟踪透明度授权 - Future requestIDFA() async { - bool result = await FlutterGromoreAds.requestIDFA; - _adEvent = '请求广告标识符:$result'; - setState(() {}); - } - - /// 请求应用跟踪透明度授权 - Future requestPermissionIfNecessary() async { - bool result = await FlutterGromoreAds.requestPermissionIfNecessary; - _adEvent = '请求相关权限:$result'; - setState(() {}); - } - - /// 展示开屏广告 - /// [logo] 展示如果传递则展示logo,不传递不展示 - Future showSplashAd([String? logo]) async { - try { - bool result = await FlutterGromoreAds.showSplashAd( - AdsConfig.splashId, - logo: logo, - timeout: 3.5, - ); - _result = "展示开屏广告${result ? '成功' : '失败'}"; - } on PlatformException catch (e) { - _result = "展示开屏广告失败 code:${e.code} msg:${e.message} details:${e.details}"; - } - } - - /// 展示插屏广告 - Future showInterstitialAd(String posid) async { - try { - bool result = await FlutterGromoreAds.showInterstitialAd(posid); - _result = "展示插屏广告${result ? '成功' : '失败'}"; - } on PlatformException catch (e) { - _result = "展示插屏广告失败 code:${e.code} msg:${e.message} details:${e.details}"; - } - setState(() {}); - } -} diff --git a/example/lib/main.dart b/example/lib/main.dart index d209e2d..9426166 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import 'home_page.dart'; +import 'pro_page.dart'; void main() { // 绑定引擎 @@ -20,7 +20,7 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { return const MaterialApp( - home: HomePage(), + home: ProPage(), ); } } diff --git a/example/lib/pro_page.dart b/example/lib/pro_page.dart index 0f6de11..34e7cb7 100644 --- a/example/lib/pro_page.dart +++ b/example/lib/pro_page.dart @@ -13,7 +13,7 @@ class _ProPageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text('Pro 版付费功能'), + title: const Text('Pro 版体验'), ), body: SingleChildScrollView( child: Column( @@ -22,20 +22,20 @@ class _ProPageState extends State { child: Padding( padding: EdgeInsets.all(10.0), child: Text( - '此功能是插件 Pro 版付费功能,需要购买插件后才能使用\n请联系微信:toponelan 咨询购买并获得技术支持', + '开源版不提供示例,请扫码下载 Pro 版体验', textAlign: TextAlign.center, ), ), ), - Image.asset( - 'assets/images/img_pro.png', + Image.network( + 'https://flutterads.top/gzh_qrcode.webp', fit: BoxFit.cover, ), const Center( child: Padding( padding: EdgeInsets.all(10.0), child: Text( - '日活 10W 以上,可咨询其他合作模式,目前已有百万级别的客户在合作,获得了非常好的收益提升', + '扫码关注公众号回复【Pro】,即可下载体验', textAlign: TextAlign.center, style: TextStyle( color: Colors.purple, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a985a96..33a1413 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -7,7 +7,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 3.2.0+16 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions