geniee_sdk_flutter 0.0.2
geniee_sdk_flutter: ^0.0.2 copied to clipboard
A Flutter plugin for integrating the Geniee SDK, providing cross-platform ad display and mediation support for Android and iOS. Supporting banner, interstitial (full-screen), rewarded
example/lib/main.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:geniee_sdk_flutter/geniee_sdk_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _interstitialAdStatus = 'Not Loaded';
String _rewardedVideoAdStatus = 'Not Loaded';
String bannerZoneId =
defaultTargetPlatform == TargetPlatform.android
? "<BANNER_ANDROID_ZONE_ID>"
: "<BANNER_IOS_ZONE_ID>";
String interstitialZoneId =
defaultTargetPlatform == TargetPlatform.android
? "<INTERSTITIAL_ANDROID_ZONE_ID>"
: "<INTERSTITIAL_IOS_ZONE_ID>";
String rewardZoneId =
defaultTargetPlatform == TargetPlatform.android
? "<REWARD_ANDROID_ZONE_ID>"
: "<REWARD_IOS_ZONE_ID>";
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text(
'Geniee SDK Flutter Demo',
style: const TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text(
'Banner Ad',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16, width: double.infinity),
Container(
width: 320.0,
height: 50.0,
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1.0),
),
child: GenieeBannerAd(
appId: bannerZoneId,
width: 320.0,
height: 50.0,
onAdReceived: () => print("Banner Ad: onAdReceived"),
onAdFailed:
(error) =>
print('Banner Ad: onAdFailed - $error'),
onAdHidden: () => print('Banner Ad: onAdHidden'),
onStartExternalBrowser:
() => print('Banner Ad: onStartExternalBrowser'),
),
),
],
),
),
),
const SizedBox(height: 8),
Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text(
'Interstitial Ad Status: $_interstitialAdStatus',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16, width: double.infinity),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () async {
setState(() {
_interstitialAdStatus = 'Loading...';
});
GenieeInterstitialAd.loadAd(
zoneId: interstitialZoneId,
onAdReceived: () {
print('Interstitial ad loaded successfully');
setState(() {
_interstitialAdStatus = 'Ad loaded';
});
},
onAdFailed: (error) {
print('Failed to load interstitial ad: $error');
setState(() {
_interstitialAdStatus = 'Ad failed: $error';
});
},
onAdShown: () {
print('Interstitial ad shown');
setState(() {
_interstitialAdStatus = 'Ad shown';
});
},
onAdClicked: () {
print('Interstitial ad clicked');
setState(() {
_interstitialAdStatus = 'Ad clicked';
});
},
onAdClosed: () {
print('Interstitial ad dismissed');
setState(() {
_interstitialAdStatus = 'Ad closed';
});
},
);
},
child: const Text(
'Load Interstitial',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () async {
if (await GenieeInterstitialAd.canShowAd()) {
await GenieeInterstitialAd.showAd();
} else {
print('Interstitial Ad Not Ready');
}
},
child: const Text(
'Show Interstitial',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
),
],
),
),
),
const SizedBox(height: 8),
Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text(
'Rewarded Video Status: $_rewardedVideoAdStatus',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16, width: double.infinity),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () async {
setState(() {
_rewardedVideoAdStatus = 'Loading...';
});
GenieeRewardedVideoAd.loadAd(
zoneId: rewardZoneId,
useRTB: false,
onAdLoaded: () {
setState(() {
_rewardedVideoAdStatus = 'Ad loaded';
});
},
onAdFailedToLoad: (error) {
setState(() {
_rewardedVideoAdStatus = 'Ad failed: $error}';
});
},
onAdDismissed: () {
setState(() {
_rewardedVideoAdStatus = 'Ad closed';
});
},
onAdStarted: () {
setState(() {
_rewardedVideoAdStatus = 'Ad started';
});
},
onAdRewarded: (rewardItem) {
setState(() {
_rewardedVideoAdStatus =
'Ad rewarded: ${rewardItem.type} - ${rewardItem.amount}';
});
},
);
},
child: const Text(
'Load Rewarded Video',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () async {
if (await GenieeRewardedVideoAd.canShowAd()) {
await GenieeRewardedVideoAd.showAd();
print('Rewarded Video Ad Shown');
} else {
print('Rewarded Video Ad Not Ready');
}
},
child: const Text(
'Show Rewarded Video',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
),
],
),
),
),
],
),
),
),
);
}
}