[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723191517.05600688219611163122622069171978:50510805055709:2800:2DED2D52AA6DB712B56BB946EFA5FCD1E3664025CDF74D58EB6AF6DBC533BE29.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723191517.05600688219611163122622069171978:50510805055709:2800:2DED2D52AA6DB712B56BB946EFA5FCD1E3664025CDF74D58EB6AF6DBC533BE29.png[/IMG]​

In our previous article we have discussed regarding how we can integrate Banner Ads and Splash Ads.

We have also discussed on how you can integrate Ads kit sdk into flutter project. If you have missed the project then i would recommend you to give it a read. Here is the link.

In this article we will be discussing about how we can integrate Interstitial Ads, Reward Ads and Native Ads

Plugin for Ads Kit: https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Library/flutter-sdk-download-0000001050196675

Application: In case you want to try the demo yourself please download Calculate BMI app form AppGallery. This application helps you calculate your Body Mass Index and shows you Banner and Interstitial Ads at the same time.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192616.86100565714604637737025660855335:50510805061546:2800:63A1476B205DBA701C4BADD229064F4D219993415888BEC020147E58822FFE62.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192616.86100565714604637737025660855335:50510805061546:2800:63A1476B205DBA701C4BADD229064F4D219993415888BEC020147E58822FFE62.png[/IMG]​

Below is the demo

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200724080108.80698792757485116227619673603794:50510805055709:2800:02509186532C3BFE85F6B2E8189783A87747A25344AD9CACA65F809876C0E9CC.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200724080108.80698792757485116227619673603794:50510805055709:2800:02509186532C3BFE85F6B2E8189783A87747A25344AD9CACA65F809876C0E9CC.gif[/IMG]​

Interstitial Ads:

These are full Screen Ads. In these ads the control to close the ads is given to customer.

The ideal place to add these kind of ads is transition between activities or if there is a level up then you can insert these ads.

These ads can be configured to redirect to a particular URL as well.

Let us see how to add these ads in flutter.

import 'package:flutter/material.dart';
import 'package:huawei_ads/adslite/interstitial/interstitial_ad.dart';

class InterstitialAds extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.topCenter,
child: RaisedButton(
child: Text(
'Load Interstitial Ads',
),
onPressed: () {
InterstitialAd _interstitialAd = createInterstitialAd();
_interstitialAd
..loadAd()
..show();
},
),
);
}
}

InterstitialAd createInterstitialAd() {
return InterstitialAd(
adUnitId: "teste9ih9j0rc3",
);
}

Below is the result you will get after running it.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192142.26230498103792902922112857237268:50510805055709:2800:93A253D0D07DB4744FF4D4426F4264DE234FA150AEEC65A40C92158F89617106.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192142.26230498103792902922112857237268:50510805055709:2800:93A253D0D07DB4744FF4D4426F4264DE234FA150AEEC65A40C92158F89617106.png[/IMG]​

Rewarded Ads:

These are also full screen ads but they provide some kind of reward to customer if he watches full add.

Example – User can get extra life in a game if he watches full video.

These are explicitly chosen by customer but user have full control to close the ads. User can anytime close these ads but in that case he won’t get any reward.

These ads are always singleton ads hence we need to check whether the ad is showing or not.

import 'package:flutter/material.dart';
import 'package:huawei_ads/hms_ads_lib.dart';

import 'package:huawei_ads/adslite/ad_param.dart';
import 'package:huawei_ads/adslite/reward/reward_verify_config.dart';
import 'package:flutter/cupertino.dart';
import 'package:huawei_ads/hms_ads.dart';

typedef void RewardAdListener(RewardAdEvent event,
{Reward reward, int errorCode});

class RewardedAds extends StatelessWidget {
@override
Widget build(BuildContext context) {

return Align(
alignment: Alignment.topCenter,
child: RaisedButton(
child: Text(
'Load Rewarded Ads',
),
onPressed: () {

RewardAd.instance
.loadAd(adUnitId: "testx9dtjwj8hp", adParam: AdParam.build());
RewardAd.instance.isLoaded().then((isLoaded) {
if (isLoaded) {
RewardAd.instance.show();
}
});

RewardAd.instance.setRewardAdListener =
(RewardAdEvent event, {Reward reward, int errorCode}) {
print("RewardedVideoAd event $event");
if (event == RewardAdEvent.rewarded) {
print('Received reward : ');
}
};
},
),
);
}
}

As you can see in above code we are checking whether Rewarded as is loaded or not by isLoading() method.

If it is not loaded we will show it. Also we have applied listener to it so we can listen to user events.

Below are example of some events:

Opened - RewardAdEvent.opened

Started - RewardAdEvent.started

Completed - RewardAdEvent.completed

Closed - RewardAdEvent.closed

While adding reward ads make sure validation is done at client side so there is no delay in providing reward to user.

Below is the result you will get after running it.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192241.42692993572235061498464320340174:50510805055709:2800:C9356C3382E5927E3BA6B18BBF3F8A54159FCB784392CBC4CDB9F250C0A33C5F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192241.42692993572235061498464320340174:50510805055709:2800:C9356C3382E5927E3BA6B18BBF3F8A54159FCB784392CBC4CDB9F250C0A33C5F.png[/IMG]​

Native Ads:

These ads fit into the surrounding into which they are added.

Here Native ads acts like a widget which you can add into a child, loading and displaying the ads is handled by plugin itself. Images and videos both are supported here. We also need to use a controller in order to set properties of native ads.

We can also add listener in order to see the user interaction with the ads.

Below is the code to add native add.

import 'package:flutter/material.dart';
import 'package:huawei_ads/adslite/nativead/native_ad.dart';
import 'package:huawei_ads/adslite/nativead/native_ad_configuration.dart';
import 'package:huawei_ads/adslite/nativead/native_ad_controller.dart';
import 'package:huawei_ads/adslite/nativead/native_styles.dart';
import 'package:huawei_ads/utils/constants.dart';

class NativeAds extends StatelessWidget {
@override
Widget build(BuildContext context) {
NativeStyles stylesSmall = NativeStyles();
stylesSmall.setCallToAction(fontSize: 8);
stylesSmall.setFlag(fontSize: 10);
stylesSmall.setSource(fontSize: 11);

NativeAdConfiguration configuration = NativeAdConfiguration.build();
configuration.setChoicesPosition = NativeAdChoicesPosition.bottomRight;

return Align(
alignment: Alignment.topCenter,
child: Column(
children: <Widget>[
Container(
height: 100,
margin: EdgeInsets.only(bottom: 20.0),
child: NativeAd(
adUnitId: "testu7m3hc4gvm",
controller: NativeAdController(
adConfiguration: configuration,
listener: (AdEvent event, {int errorCode}) {
print("NativeAd event $event");
}),
type: NativeAdType.small,
styles: stylesSmall,
),
),
],
),
);
}
}

Below is the result you will get after running it.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192421.12237797001531659889018356295287:50510805061546:2800:F9A33D35FD7AF28F0E4C98BE7262C398BBB885BF8024EF51DF8CBA8BD2BFBB76.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/000/002/333/0890091000000002333.20200723192421.12237797001531659889018356295287:50510805061546:2800:F9A33D35FD7AF28F0E4C98BE7262C398BBB885BF8024EF51DF8CBA8BD2BFBB76.png[/IMG]​

Github Link:

Ads Kit: https://github.com/DTSE-India-Community/Flutter/tree/master/add_kit_flutter

BMI Calculator: https://github.com/DTSE-India-Community/Flutter/tree/master/calculate_bmi

Conclusion:

I hope with this article you will find some ease in integrating Ads kit in flutter project., In case you want to see any other kit integration or sample code then make sure to give the feedback.

Banner and Splash Ads: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201286813113710087&fid=0101187876626530001

Below is the official documentation: https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/publisher-service-0000001050196431