ironsource 0.1.0 copy "ironsource: ^0.1.0" to clipboard
ironsource: ^0.1.0 copied to clipboard

outdated

plugin to display banner ad (platform view), interstitial ad, rewarded video ad, and offerwall ads from IronSource (https://ironsrc.com). Currently support android only

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:ironsource/ironsource.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with IronSourceListener {
  final String appKey = "85460dcd";

  bool rewardeVideoAvailable = false,
      offerwallAvailable = false,
      showBanner = false,
      interstitialReady = false;
  @override
  void initState() {
    super.initState();
    init();
  }

  void init() async {
    await IronSource.initialize(appKey: appKey, listener: this);
    rewardeVideoAvailable = await IronSource.isRewardedVideoAvailable();
    offerwallAvailable = await IronSource.isOfferwallAvailable();
    setState(() {});
  }

  void loadInterstitial() {
    IronSource.loadInterstitial();
  }

  void showInterstitial() async {
    if (await IronSource.isInterstitialReady()) {
      IronSource.showInterstitial();
    } else {
      print(
        "Interstial is not ready. use 'Ironsource.loadInterstial' before showing it",
      );
    }
  }

  void showOfferwall() async {
    if (await IronSource.isOfferwallAvailable()) {
      IronSource.showOfferwall();
    } else {
      print("Offerwall not available");
    }
  }

  void showRewardedVideo() async {
    if (await IronSource.isRewardedVideoAvailable()) {
      IronSource.showRewardedVideol();
    } else {
      print("RewardedVideo not available");
    }
  }

  void showHideBanner() {
    setState(() {
      showBanner = !showBanner;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: const Text('IronSource ads demo'),
        ),
        body: Stack(
          children: <Widget>[
            Container(
              padding: EdgeInsets.symmetric(vertical: 50.0),
              alignment: Alignment.center,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  CustomButton(
                    label: "Load interstitial",
                    onPressed: loadInterstitial,
                  ),
                  CustomButton(
                    label: "Show interstitial",
                    onPressed: interstitialReady ? showInterstitial : null,
                  ),
                  CustomButton(
                    label: "Show offerwall",
                    onPressed: offerwallAvailable ? showOfferwall : null,
                  ),
                  CustomButton(
                    label: "Show Rewarded Video",
                    onPressed: rewardeVideoAvailable ? showRewardedVideo : null,
                  ),
                  CustomButton(
                    label: showBanner ? "hide banner" : "Show Banner",
                    onPressed: showHideBanner,
                  ),
                ],
              ),
            ),
// Banner ad
            if (showBanner)
              Align(
                alignment: Alignment.bottomCenter,
                child: IronSourceBannerAd(
                    keepAlive: true, listener: BannerAdListener()),
              )
          ],
        ),
      ),
    );
  }

  @override
  void onInterstitialAdClicked() {
    print("onInterstitialAdClicked");
  }

  @override
  void onInterstitialAdClosed() {
    print("onInterstitialAdClosed");
  }

  @override
  void onInterstitialAdLoadFailed(Map<String, dynamic> error) {
      print("onInterstitialAdLoadFailed : $error");
  }

  @override
  void onInterstitialAdOpened() {
    print("onInterstitialAdOpened");
    setState(() {
      interstitialReady = false;
    });

 
  }

  @override
  void onInterstitialAdReady() {
    print("onInterstitialAdReady");
    setState(() {
      interstitialReady = true;
    });
  
  }

  @override
  void onInterstitialAdShowFailed(Map<String, dynamic> error) {

    print("onInterstitialAdShowFailed : $error");
    setState(() {
      interstitialReady = false;
    });
  }

  @override
  void onInterstitialAdShowSucceeded() {
    print("nInterstitialAdShowSucceeded");
  }

  @override
  void onGetOfferwallCreditsFailed(Map<String, dynamic> error) {

    print("onGetOfferwallCreditsFailed : $error");
  }

  @override
  void onOfferwallAdCredited(Map<String, dynamic> reward) {

    print("onOfferwallAdCredited : $reward");
  }

  @override
  void onOfferwallAvailable(bool available) {
    print("onOfferwallAvailable : $available");

    setState(() {
      offerwallAvailable = available;
    });
  }

  @override
  void onOfferwallClosed() {
    print("onOfferwallClosed");
  }

  @override
  void onOfferwallOpened() {
    print("onOfferwallOpened");
  }

  @override
  void onOfferwallShowFailed(Map<String, dynamic> error) {
    print("onOfferwallShowFailed $error");
  }

  @override
  void onRewardedVideoAdClicked(Map placement) {
   
    print("onRewardedVideoAdClicked");
  }

  @override
  void onRewardedVideoAdClosed() {
    print("onRewardedVideoAdClosed");

  }

  @override
  void onRewardedVideoAdEnded() {
    print("onRewardedVideoAdEnded");


  }

  @override
  void onRewardedVideoAdOpened() {
    print("onRewardedVideoAdOpened");

  }

  @override
  void onRewardedVideoAdRewarded(Map placement) {

    print("onRewardedVideoAdRewarded: $placement");
  }

  @override
  void onRewardedVideoAdShowFailed(Map<String, dynamic> error) {
  
    print("onRewardedVideoAdShowFailed : $error");
  }

  @override
  void onRewardedVideoAdStarted() {
    print("onRewardedVideoAdStarted");
  }

  @override
  void onRewardedVideoAvailabilityChanged(bool available) {
   
    print("onRewardedVideoAvailabilityChanged : $available");
    setState(() {
      rewardeVideoAvailable = available;
    });
  }
}

class BannerAdListener extends IronSourceBannerListener {
  @override
  void onBannerAdClicked() {
    print("onBannerAdClicked");
  }

  @override
  void onBannerAdLeftApplication() {
    print("onBannerAdLeftApplication");
  }

  @override
  void onBannerAdLoadFailed(Map<String, dynamic> error) {
    print("onBannerAdLoadFailed");

  }

  @override
  void onBannerAdLoaded() {
    print("onBannerAdLoaded");
  }

  @override
  void onBannerAdScreenDismissed() {
    print("onBannerAdScreenDismisse");
  }

  @override
  void onBannerAdScreenPresented() {
    print("onBannerAdScreenPresented");
  }
}

class CustomButton extends StatelessWidget {
  final String label;
  final Function onPressed;

  const CustomButton({Key key, this.label, this.onPressed}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10.0),
      child: MaterialButton(
        minWidth: 250.0,
        height: 50.0,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(40.0),
            side: BorderSide(width: 2.0, color: Colors.blue)),
        child: Text(
          label.toUpperCase(),
          style: TextStyle(),
        ),
        onPressed: onPressed,
      ),
    );
  }
}
13
likes
40
pub points
19%
popularity

Publisher

unverified uploader

plugin to display banner ad (platform view), interstitial ad, rewarded video ad, and offerwall ads from IronSource (https://ironsrc.com). Currently support android only

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on ironsource