thinkingit_fb_ads
Show Meta Audience Network ads in Flutter apps on Android and iOS.
| Ad type | Android | iOS |
|---|---|---|
| Banner | ✅ | ✅ |
| Native | ✅ | ✅ |
| Native banner | ✅ | ✅ |
| Interstitial | ✅ | ✅ |
| Rewarded video | ✅ | ✅ |
Uses Meta Audience Network SDK 6.22.0.
Requirements
- Flutter 3.27 or newer
- Android:
minSdk24 or higher - iOS: 15.0 or higher, Xcode 26 or newer
Installation
flutter pub add thinkingit_fb_ads
iOS setup
Set the deployment target to 15.0 in ios/Podfile:
platform :ios, '15.0'
Also set Minimum Deployments to 15.0 for the Runner target in Xcode.
Meta asks iOS apps to add the SKAdNetworkItems listed in
Meta's iOS setup guide
and an NSUserTrackingUsageDescription to ios/Runner/Info.plist.
Usage
Initialize the SDK once, before loading any ad:
import 'package:thinkingit_fb_ads/thinkingit_fb_ads.dart';
await FbAds.init(
testingId: 'YOUR_DEVICE_TESTING_ID', // optional, for test ads
iOSAdvertiserTrackingEnabled: true, // the user's ATT choice
);
The testing ID is printed to the device log the first time an ad is requested without one.
Banner
FbBannerAd(
placementId: 'YOUR_PLACEMENT_ID',
bannerSize: FbBannerSize.standard, // standard, large, mediumRectangle
listener: (result, value) {
print('Banner ad: $result --> $value');
},
)
Native and native banner
FbNativeAd(
placementId: 'YOUR_PLACEMENT_ID',
adType: FbNativeAdType.nativeAd,
height: 300,
backgroundColor: Colors.white,
buttonColor: Colors.blue,
buttonTitleColor: Colors.white,
listener: (result, value) {
print('Native ad: $result --> $value');
},
)
FbNativeAd(
placementId: 'YOUR_PLACEMENT_ID',
adType: FbNativeAdType.nativeBannerAd,
bannerAdSize: FbNativeBannerAdSize.height100,
)
FbNativeAdType.nativeAdHorizontal and FbNativeAdType.nativeAdVertical are custom layouts on iOS. Android shows the standard native template for them.
Interstitial
FbInterstitialAd.loadInterstitialAd(
placementId: 'YOUR_PLACEMENT_ID',
listener: (result, value) {
if (result == FbInterstitialAdResult.loaded) {
FbInterstitialAd.showInterstitialAd();
}
},
);
Rewarded video
FbRewardedVideoAd.loadRewardedVideoAd(
placementId: 'YOUR_PLACEMENT_ID',
listener: (result, value) {
if (result == FbRewardedVideoAdResult.loaded) {
FbRewardedVideoAd.showRewardedVideoAd();
}
if (result == FbRewardedVideoAdResult.videoComplete) {
// Grant the reward.
}
},
);
Interstitial and rewarded ads can be shown only once. Load a new ad after dismissed or videoClosed.
Listener values
Listeners receive a map like this:
{
'placement_id': 'YOUR_PLACEMENT_ID',
'invalidated': false,
'error_code': 1001, // errors only
'error_message': 'No fill', // errors only
}
Migrating from facebook_audience_network
- Change the import to
package:thinkingit_fb_ads/thinkingit_fb_ads.dart. - Rename the classes and enums:
FacebookAudienceNetwork→FbAds,FacebookBannerAd→FbBannerAd,FacebookNativeAd→FbNativeAd,FacebookInterstitialAd→FbInterstitialAd,FacebookRewardedVideoAd→FbRewardedVideoAd, and addFbto every other class and enum, for exampleBannerSize→FbBannerSizeandNativeAdType→FbNativeAdType. - Enum values and constants now use lowerCamelCase. For example,
BannerSize.STANDARDis nowFbBannerSize.standard, andInterstitialAdResult.LOADEDis nowFbInterstitialAdResult.loaded. placementIdis required.expandAnimationDuraion(milliseconds) is nowexpandAnimationDuration(aDuration).
Credits
Based on facebook_audience_network by Dreamsoft Innovations, released under the MIT License.
Libraries
- thinkingit_fb_ads
- Meta (Facebook) Audience Network ads for Flutter: banner, native, native banner, interstitial and rewarded video ads on Android and iOS.