adivery_ads 0.0.6
adivery_ads: ^0.0.6 copied to clipboard
Flutter plugin for Adivery Ads by Moein kasaei
example/lib/main.dart
import 'package:adivery_ads/adivery.dart';
import 'package:adivery_ads/adivery_ads.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
@override
void initState() {
initPlatformState();
super.initState();
}
void initPlatformState() {
AdiveryPlugin.initialize("7e27fb38-5aff-473a-998f-437b89426f66");
AdiveryPlugin.setLoggingEnabled(true);
AdiveryPlugin.prepareInterstitialAd("de5db046-765d-478f-bb2e-30dc2eaf3f51");
AdiveryPlugin.prepareRewardedAd("3f97dc4d-3e09-4024-acaf-931862c03ba8");
AdiveryPlugin.addListener(
onError: onError,
onInterstitialLoaded: onInterstitialLoaded,
onRewardedClosed: onRewardedClosed,
onRewardedLoaded: (placement) => {});
}
static void onInterstitialLoaded(String placement) {
debugPrint("interstitial loaded");
}
static void onRewardedClosed(String placement, bool isRewarded) {
debugPrint("ad rewarded: $isRewarded");
}
static void onError(String placement, String error) {
debugPrint("onError$error");
}
static void _onAdLoaded(Ad ad) {
debugPrint("banner loaded");
}
static void _onAdClicked(Ad ad) {
debugPrint("banner clicked");
}
static void _onError(Ad ad, String error) {
debugPrint("banner load failed $error");
}
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text("Title"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
BannerAd(
"2f71ec44-f30a-4043-9cc1-f32347a07f8b",
BannerAdSize.BANNER,
onAdLoaded: _onAdLoaded,
onAdClicked: _onAdClicked,
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}