flutter_plugin_audience_network_ad

Plugin to integrate Facebook Native Ad to Flutter application

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Stack(
      children: <Widget>[
        Center(
          child: FacebookBannerAd(
            placementId: getPlacementId(),
            bannerSize: BannerSize.STANDARD,
            listener: (result, value) {
              setState(() {
                _bannerAdResult = result;
              });
              },
            ),
          ),
          Center(
            child: _getContentSection(),
          ),
        ],
      ),
    );
  }
  Widget _getContentSection() {
    switch (_bannerAdResult) {
      case BannerAdResult.ERROR:
        return RichText(
          overflow: TextOverflow.ellipsis,
          maxLines: 1,
          text: TextSpan(
            children: <TextSpan>[
              TextSpan(
                text: 'Error',
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  color: Colors.grey,
                  fontSize: 12.0,
                ),
              ),
            ],
          ),
        );
      case BannerAdResult.LOADED:
      case BannerAdResult.CLICKED:
      case BannerAdResult.LOGGING_IMPRESSION:
        return Container();
        break;
      default:
        return Container(
          child: RichText(
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
            text: TextSpan(
              children: <TextSpan>[
                TextSpan(
                  text: 'Loading..',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: Colors.grey,
                    fontSize: 12.0,
                  ),
                ),
              ],
            ),
          ),
        );
    }
}
void _loadInterstitialAd() {
  FacebookInterstitialAd.loadInterstitialAd(
    placementId: getPlacementId(),
    listener: (result, value) {
      setState(() {
        _interstitialAdResult = result;
      });
      if (result == InterstitialAdResult.LOADED) {
        FacebookInterstitialAd.showInterstitialAd();
      }
      if (result == InterstitialAdResult.DISMISSED && value["invalidated"] == true) {
        _loadInterstitialAd();
      }
    },
  );
}
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Stack(
      children: <Widget>[
        Center(
          child: FacebookNativeAd(
              placementId: getPlacementId(),
              adType: NativeAdType.NATIVE_AD_HORIZONTAL,
              width: double.infinity,
              height: 300,
              backgroundColor: Colors.blue,
              titleColor: Colors.white,
              descriptionColor: Colors.white,
              buttonColor: Colors.deepPurple,
              buttonTitleColor: Colors.white,
              buttonBorderColor: Colors.white,
              listener: (result, value) {
                setState(() {
                  _nativeAdResult = result;
                  print("NativeAdWidget Ad : $result -->  $value");
                });
              },
            ),
        ),
        Center(
          child: _getContentSection(),
        ),
      ],
    ),
  );
}
Widget _getContentSection() {
  switch (_nativeAdResult) {
    case NativeAdResult.ERROR:
      return RichText(
        overflow: TextOverflow.ellipsis,
        maxLines: 1,
        text: TextSpan(
          children: <TextSpan>[
            TextSpan(
              text: 'Error',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.grey,
                fontSize: 12.0,
              ),
            ),
          ],
        ),
      );
    case NativeAdResult.LOADED:
    case NativeAdResult.MEDIA_DOWNLOADED:
    case NativeAdResult.LOGGING_IMPRESSION:
      return Container();
      break;
    default:
      return Container(
        child: RichText(
          overflow: TextOverflow.ellipsis,
          maxLines: 1,
          text: TextSpan(
            children: <TextSpan>[
              TextSpan(
                text: 'Loading..',
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  color: Colors.grey,
                  fontSize: 12.0,
                ),
              ),
            ],
          ),
        ),
      );
    }
  }
  • placementID: required placement ID from Facebook. If you want to run test ads, please use "YOUR_PLACEMENT_ID"

Features Request

just facebook audience ad network support Android and iOS.

Libraries

ad_banner
ad_interstitial
ad_native
constants
fb_constants
i18n

Dart

VM

dart:ffi
Foreign Function Interface for interoperability with the C programming language. [...]

Web

dart:html
HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
dart:js
Low-level support for interoperating with JavaScript. [...]
dart:js_util
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.