pavelzaichyk / flutter_unity_ads

Unity Ads plugin for Flutter Applications. This plugin is able to display Unity Banner Ads and Unity Video Ads.
https://pub.dev/packages/unity_ads_plugin
MIT License
32 stars 13 forks source link

Banner ads & Display ads not showing #10

Closed Riyaz7364 closed 3 years ago

Riyaz7364 commented 3 years ago

Display and banner ads are not showing in my flutter project but video and rewarded video ads are working. I'm not getting any error after calling me the method to show ads.

class ShowAds extends StatefulWidget {
  const ShowAds({Key? key}) : super(key: key);

  @override
  _ShowAdsState createState() => _ShowAdsState();
}

class _ShowAdsState extends State<ShowAds> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    UnityAds.init(
        gameId: AdManager.gameId,
        testMode: true,
        listener: (state, args) {
          if (state == UnityAdState.ready) {
            showBannerAds();
          }
          print('Init Listener: $state => $args');
        });
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    showBannerAds();
  }

  void showBannerAds() {
    print("showBannerAds");
    UnityBannerAd(
      placementId: AdManager.bannerAdPlacementId,
      listener: (state, args) {
        print('Banner Listener: $state => $args');
      },
    );

    UnityAds.showVideoAd(
      placementId: AdManager.interstitialVideoAdPlacementId,
      listener: (state, args) =>
          print('Interstitial Video Listener: $state => $args'),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
pavelzaichyk commented 3 years ago

UnityBannerAd is a widget. It should be in the widget tree to be drawn on UI.

You can just put UnityBannerAd to the build method.

...
  @override
  Widget build(BuildContext context) {
    return Container(
      child: UnityBannerAd(
        placementId: AdManager.bannerAdPlacementId,
        listener: (state, args) {
          print('Banner Listener: $state => $args');
        },
      ),
    );
  }
  ...

See example for more details: https://pub.dev/packages/unity_ads_plugin/example