refinery89_monetize_app 0.0.1-dev.2 refinery89_monetize_app: ^0.0.1-dev.2 copied to clipboard
The flutter plugin for the Refinery 89 Monetize App, supporting banner, outStream, interstitial (full-screen) and scrollable ads
import 'package:flutter/material.dart';
import 'package:refinery89_monetize_app/r89_sdk.dart';
void main() {
runApp(const App());
}
class App extends StatefulWidget {
const App({super.key});
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
bool _isInitialized = false;
bool _isInitializationInProgress = false;
int? _infiniteScrollId;
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorObservers: [R89SDK.routeObserver],
home: Scaffold(
body: Builder(
builder: (BuildContext context) => Stack(
children: [
ListView.builder(
itemCount: 50,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Text('ITEM #$index'),
if (_infiniteScrollId != null)
R89InfiniteScrollAd(
infiniteScrollId: _infiniteScrollId!,
itemIndex: index)
],
),
),
),
),
),
if (_isInitializationInProgress)
const Center(
child: Card(
child: SizedBox(
width: 96,
height: 96,
child: CircularProgressIndicator()),
)),
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (!_isInitialized && !_isInitializationInProgress)
FilledButton(
onPressed: () {
// Initialize the SDK in debug mode
setState(() {
_isInitializationInProgress = true;
});
// Replace the initializeInAutoMode method below with the
// initializeInManualMode to run initialization with manual configs.
initializeInAutoMode(InitializationEvents.callbacks(
onDataFetchFailedCallback: () {
setState(() {
_isInitialized = false;
_isInitializationInProgress = false;
});
}, onInitializationFinishedCallback: () {
_infiniteScrollId = R89SDK.adFactory
.createInfiniteScroll(
configurationId: ConfigBuilder
.infiniteScrollTestR89ConfigId);
setState(() {
_isInitialized = true;
_isInitializationInProgress = false;
});
}));
},
child: const Text('AUTO CONFIG INITIALIZE')),
if (!_isInitialized && !_isInitializationInProgress)
FilledButton(
onPressed: () {
// Initialize the SDK in debug mode
setState(() {
_isInitializationInProgress = true;
});
initializeInManualMode(
InitializationEvents.callbacks(
onDataFetchFailedCallback: () {
setState(() {
_isInitialized = false;
_isInitializationInProgress = false;
});
}, onInitializationFinishedCallback: () {
_infiniteScrollId = R89SDK.adFactory
.createInfiniteScroll(
configurationId: ConfigBuilder
.infiniteScrollTestR89ConfigId);
setState(() {
_isInitialized = true;
_isInitializationInProgress = false;
});
}));
},
child: const Text('MANUAL CONFIG INITIALIZE')),
if (_isInitialized)
FilledButton(
onPressed: () => R89SDK.adFactory.createInterstitial(
configurationId:
ConfigBuilder.interstitialTestR89ConfigId),
child: const Text('SHOW INTERSTITIAL AD')),
const R89Banner(
configurationId: ConfigBuilder.bannerTestR89ConfigId,
),
// Uncomment to display Video ad
// R89OutStream(
// configurationId: ConfigBuilder.videoOutStreamTestR89ConfigId,
// )
],
),
),
)
],
),
),
),
);
}
}
/// Initializes the SDK in a automatic mode, see [R89SDK.initialize]
void initializeInAutoMode(InitializationEvents listener) async {
R89SDK.setLogLevel(LogLevel.debug);
R89SDK.setDebug();
R89SDK.initialize(
publisherId: "TestRefinery89ID",
appId: "TestDemoApp",
initializationEvents: listener);
}
/// Initializes the SDK in a manual mode, with provided [R89Config], see [R89SDK.initializeWithConfigBuilder]
Future<void> initializeInManualMode(InitializationEvents listener) async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
final configBuilder = ConfigBuilder("Manual Config");
const bannerR89ConfigId = ConfigBuilder.bannerTestR89ConfigId;
const bannerGAMId = ConfigBuilder.bannerTestUnitId;
const bannerPrebidConfigId = ConfigBuilder.bannerTestConfigId;
configBuilder.addBannerConfiguration(
configurationId: bannerR89ConfigId,
bannerUnitId: bannerGAMId,
bannerConfigId: bannerPrebidConfigId,
sizeList: [
AdSize(
width: ConfigBuilder.bannerTestWidth,
height: ConfigBuilder.bannerTestHeight,
)
]);
const outStreamR89ConfigId = ConfigBuilder.videoOutStreamTestR89ConfigId;
const outStreamGAMID = ConfigBuilder.videoOutStreamTestUnitId;
const outStreamPrebidConfigID = ConfigBuilder.videoOutStreamTestConfigId;
configBuilder.addVideoOutStreamBannerConfiguration(
configurationId: outStreamR89ConfigId,
outStreamUnitId: outStreamGAMID,
outStreamConfigId: outStreamPrebidConfigID,
size: AdSize(
width: ConfigBuilder.videoOutStreamTestWidth,
height: ConfigBuilder.videoOutStreamTestHeight),
);
const infiniteScrollR89ConfigId = ConfigBuilder.infiniteScrollTestR89ConfigId;
const infiniteScrollTestVariableProbabilityMin =
ConfigBuilder.infiniteScrollTestVariableProbabilityMin;
const infiniteScrollTestVariableProbabilityMax =
ConfigBuilder.infiniteScrollTestVariableProbabilityMax;
configBuilder.addInfiniteScrollConfiguration(
configurationId: infiniteScrollR89ConfigId,
minItems: 2,
maxItems: 2,
variableProbabilityMin: infiniteScrollTestVariableProbabilityMin,
variableProbabilityMax: infiniteScrollTestVariableProbabilityMax,
configsOfAdsToUse: [bannerR89ConfigId, outStreamR89ConfigId],
);
const interstitialR89ConfigId = ConfigBuilder.interstitialTestR89ConfigId;
const interstitialId = ConfigBuilder.interstitialTestUnitId;
const interstitialConfigId = ConfigBuilder.interstitialTestConfigId;
configBuilder.addInterstitialConfiguration(
configurationId: interstitialR89ConfigId,
interstitialUnitId: interstitialId,
interstitialConfigId: interstitialConfigId,
);
configBuilder.addCMPData(id: ConfigBuilder.cmpTestId);
configBuilder.addAppTargeting(
storeUrl:
"https://play.google.com/store/apps/details?id=com.refinery.xgnapp",
domain: "www.xgn.nl",
appContextKeywords: {"games", "news", "video-games"},
);
configBuilder.addPrebidServerConfig(useRealAuctionServer: false);
R89SDK.setLogLevel(LogLevel.debug);
R89SDK.setDebug();
R89SDK.initializeWithConfigBuilder(
appId: "",
publisherId: "",
config: configBuilder.build(),
initializationEvents: listener);
}