adivery_ads 0.0.4 copy "adivery_ads: ^0.0.4" to clipboard
adivery_ads: ^0.0.4 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 StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @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(widget.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),
      ),
    );
  }
}
1
likes
0
points
22
downloads

Publisher

verified publishermfuzzy.com

Weekly Downloads

Flutter plugin for Adivery Ads by Moein kasaei

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on adivery_ads

Packages that implement adivery_ads