From 0478acfdc79b3e849f737993cb6da8c9984a2323 Mon Sep 17 00:00:00 2001 From: MattyBoy Date: Fri, 8 Oct 2021 13:26:57 -0500 Subject: [PATCH 1/2] Changed all AndroidViews to PlatformViewLink. The newish Android Hybrid View --- lib/ad/ad_banner.dart | 88 +++++++++++++------------- lib/ad/ad_native.dart | 144 ++++++++++++++++-------------------------- 2 files changed, 98 insertions(+), 134 deletions(-) diff --git a/lib/ad/ad_banner.dart b/lib/ad/ad_banner.dart index 16200d5..c9db116 100644 --- a/lib/ad/ad_banner.dart +++ b/lib/ad/ad_banner.dart @@ -1,5 +1,7 @@ import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:facebook_audience_network/constants.dart'; @@ -18,8 +20,7 @@ class BannerSize { static const BannerSize STANDARD = BannerSize(width: 320, height: 50); static const BannerSize LARGE = BannerSize(width: 320, height: 90); - static const BannerSize MEDIUM_RECTANGLE = - BannerSize(width: 320, height: 250); + static const BannerSize MEDIUM_RECTANGLE = BannerSize(width: 320, height: 250); const BannerSize({this.width = 320, this.height = 50}); } @@ -80,8 +81,7 @@ class FacebookBannerAd extends StatefulWidget { _FacebookBannerAdState createState() => _FacebookBannerAdState(); } -class _FacebookBannerAdState extends State - with AutomaticKeepAliveClientMixin { +class _FacebookBannerAdState extends State with AutomaticKeepAliveClientMixin { double containerHeight = 0.5; @override @@ -90,49 +90,58 @@ class _FacebookBannerAdState extends State @override Widget build(BuildContext context) { super.build(context); + final Map creationParams = { + "id": widget.placementId, + "width": widget.bannerSize.width, + "height": widget.bannerSize.height, + }; + if (defaultTargetPlatform == TargetPlatform.android) { return Container( height: containerHeight, color: Colors.transparent, - child: AndroidView( + child: PlatformViewLink( viewType: BANNER_AD_CHANNEL, - onPlatformViewCreated: _onBannerAdViewCreated, - creationParams: { - "id": widget.placementId, - "width": widget.bannerSize.width, - "height": widget.bannerSize.height, + surfaceFactory: (BuildContext context, PlatformViewController controller) { + return AndroidViewSurface( + controller: controller as AndroidViewController, + gestureRecognizers: const >{}, + hitTestBehavior: PlatformViewHitTestBehavior.opaque, + ); + }, + onCreatePlatformView: (PlatformViewCreationParams params) { + return PlatformViewsService.initSurfaceAndroidView( + id: params.id, + viewType: BANNER_AD_CHANNEL, + layoutDirection: TextDirection.ltr, + creationParams: creationParams, + creationParamsCodec: StandardMessageCodec(), + onFocus: () { + params.onFocusChanged(true); + }, + ) + ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) + ..addOnPlatformViewCreatedListener(_onBannerAdViewCreated) + ..create(); }, - creationParamsCodec: StandardMessageCodec(), ), ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { return Container( height: containerHeight, color: Colors.transparent, - child: Container( - width: widget.bannerSize.width.toDouble(), - child: Center( - child: UiKitView( - viewType: BANNER_AD_CHANNEL, - onPlatformViewCreated: _onBannerAdViewCreated, - creationParams: { - "id": widget.placementId, - "width": widget.bannerSize.width, - "height": widget.bannerSize.height, - }, - creationParamsCodec: StandardMessageCodec(), - ), - ), + child: UiKitView( + viewType: BANNER_AD_CHANNEL, + onPlatformViewCreated: _onBannerAdViewCreated, + creationParams: creationParams, + creationParamsCodec: StandardMessageCodec(), ), ); } else { return Container( - height: widget.bannerSize.height <= -1 - ? double.infinity - : widget.bannerSize.height.toDouble(), + height: widget.bannerSize.height <= -1 ? double.infinity : widget.bannerSize.height.toDouble(), child: Center( - child: - Text("Banner Ads for this platform is currently not supported"), + child: Text("Banner Ads for this platform is currently not supported"), ), ); } @@ -140,30 +149,23 @@ class _FacebookBannerAdState extends State void _onBannerAdViewCreated(int id) async { final channel = MethodChannel('${BANNER_AD_CHANNEL}_$id'); - - channel.setMethodCallHandler((MethodCall call) { + channel.setMethodCallHandler((MethodCall call) { switch (call.method) { case ERROR_METHOD: - if (widget.listener != null) - widget.listener!(BannerAdResult.ERROR, call.arguments); + if (widget.listener != null) widget.listener!(BannerAdResult.ERROR, call.arguments); break; case LOADED_METHOD: setState(() { - containerHeight = widget.bannerSize.height <= -1 - ? double.infinity - : widget.bannerSize.height.toDouble(); + containerHeight = widget.bannerSize.height <= -1 ? double.infinity : widget.bannerSize.height.toDouble(); }); - if (widget.listener != null) - widget.listener!(BannerAdResult.LOADED, call.arguments); + if (widget.listener != null) widget.listener!(BannerAdResult.LOADED, call.arguments); break; case CLICKED_METHOD: - if (widget.listener != null) - widget.listener!(BannerAdResult.CLICKED, call.arguments); + if (widget.listener != null) widget.listener!(BannerAdResult.CLICKED, call.arguments); break; case LOGGING_IMPRESSION_METHOD: - if (widget.listener != null) - widget.listener!(BannerAdResult.LOGGING_IMPRESSION, call.arguments); + if (widget.listener != null) widget.listener!(BannerAdResult.LOGGING_IMPRESSION, call.arguments); break; } diff --git a/lib/ad/ad_native.dart b/lib/ad/ad_native.dart index 72eade8..deb7e73 100644 --- a/lib/ad/ad_native.dart +++ b/lib/ad/ad_native.dart @@ -1,7 +1,9 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:facebook_audience_network/constants.dart'; @@ -133,8 +135,7 @@ class FacebookNativeAd extends StatefulWidget { _FacebookNativeAdState createState() => _FacebookNativeAdState(); } -class _FacebookNativeAdState extends State - with AutomaticKeepAliveClientMixin { +class _FacebookNativeAdState extends State with AutomaticKeepAliveClientMixin { final double containerHeight = Platform.isAndroid ? 1.0 : 0.1; bool isAdReady = false; @override @@ -142,8 +143,7 @@ class _FacebookNativeAdState extends State String _getChannelRegisterId() { String channel = NATIVE_AD_CHANNEL; - if (defaultTargetPlatform == TargetPlatform.iOS && - widget.adType == NativeAdType.NATIVE_BANNER_AD) { + if (defaultTargetPlatform == TargetPlatform.iOS && widget.adType == NativeAdType.NATIVE_BANNER_AD) { channel = NATIVE_BANNER_AD_CHANNEL; } return channel; @@ -151,23 +151,17 @@ class _FacebookNativeAdState extends State Widget build(BuildContext context) { super.build(context); - double width = widget.width == double.infinity - ? MediaQuery.of(context).size.width - : widget.width; + double width = widget.width == double.infinity ? MediaQuery.of(context).size.width : widget.width; return AnimatedContainer( color: Colors.transparent, width: width, - height: isAdReady || widget.keepExpandedWhileLoading - ? widget.height - : containerHeight, + height: isAdReady || widget.keepExpandedWhileLoading ? widget.height : containerHeight, duration: Duration(milliseconds: widget.expandAnimationDuraion), child: Stack( alignment: Alignment.center, children: [ Positioned.fill( - top: isAdReady || widget.keepExpandedWhileLoading - ? 0 - : -(widget.height - containerHeight), + top: isAdReady || widget.keepExpandedWhileLoading ? 0 : -(widget.height - containerHeight), child: ConstrainedBox( constraints: new BoxConstraints( maxHeight: widget.height, @@ -182,6 +176,22 @@ class _FacebookNativeAdState extends State } Widget buildPlatformView(double width) { + final Map creationParams = { + "id": widget.placementId, + "ad_type": widget.adType.index, + "banner_ad": widget.adType == NativeAdType.NATIVE_BANNER_AD ? true : false, + "height": widget.adType == NativeAdType.NATIVE_BANNER_AD ? widget.bannerAdSize.height : widget.height, + "bg_color": widget.backgroundColor == null ? null : _getHexStringFromColor(widget.backgroundColor!), + "title_color": widget.titleColor == null ? null : _getHexStringFromColor(widget.titleColor!), + "desc_color": widget.descriptionColor == null ? null : _getHexStringFromColor(widget.descriptionColor!), + "label_color": widget.labelColor == null ? null : _getHexStringFromColor(widget.labelColor!), + "button_color": widget.buttonColor == null ? null : _getHexStringFromColor(widget.buttonColor!), + "button_title_color": widget.buttonTitleColor == null ? null : _getHexStringFromColor(widget.buttonTitleColor!), + "button_border_color": + widget.buttonBorderColor == null ? null : _getHexStringFromColor(widget.buttonBorderColor!), + "is_media_cover": widget.isMediaCover, + }; + if (defaultTargetPlatform == TargetPlatform.android) { return Container( width: width, @@ -190,82 +200,41 @@ class _FacebookNativeAdState extends State widget.adType == NativeAdType.NATIVE_AD_VERTICAL ? widget.height : widget.bannerAdSize.height!.toDouble(), - child: AndroidView( + child: PlatformViewLink( viewType: NATIVE_AD_CHANNEL, - onPlatformViewCreated: _onNativeAdViewCreated, - creationParamsCodec: StandardMessageCodec(), - creationParams: { - "id": widget.placementId, - "banner_ad": - widget.adType == NativeAdType.NATIVE_BANNER_AD ? true : false, - // height param is only for Banner Ads. Native Ad's height is - // governed by container. - "height": widget.bannerAdSize.height, - "bg_color": widget.backgroundColor == null - ? null - : _getHexStringFromColor(widget.backgroundColor!), - "title_color": widget.titleColor == null - ? null - : _getHexStringFromColor(widget.titleColor!), - "desc_color": widget.descriptionColor == null - ? null - : _getHexStringFromColor(widget.descriptionColor!), - "label_color": widget.labelColor == null - ? null - : _getHexStringFromColor(widget.labelColor!), - "button_color": widget.buttonColor == null - ? null - : _getHexStringFromColor(widget.buttonColor!), - "button_title_color": widget.buttonTitleColor == null - ? null - : _getHexStringFromColor(widget.buttonTitleColor!), - "button_border_color": widget.buttonBorderColor == null - ? null - : _getHexStringFromColor(widget.buttonBorderColor!), + surfaceFactory: (BuildContext context, PlatformViewController controller) { + return AndroidViewSurface( + controller: controller as AndroidViewController, + gestureRecognizers: const >{}, + hitTestBehavior: PlatformViewHitTestBehavior.opaque, + ); + }, + onCreatePlatformView: (PlatformViewCreationParams params) { + return PlatformViewsService.initSurfaceAndroidView( + id: params.id, + viewType: NATIVE_AD_CHANNEL, + layoutDirection: TextDirection.ltr, + creationParams: creationParams, + creationParamsCodec: StandardMessageCodec(), + onFocus: () { + params.onFocusChanged(true); + }, + ) + ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) + ..addOnPlatformViewCreatedListener(_onNativeAdViewCreated) + ..create(); }, ), ); } else if (defaultTargetPlatform == TargetPlatform.iOS) { return Container( width: width, - height: widget.adType == NativeAdType.NATIVE_AD - ? widget.height - : widget.bannerAdSize.height!.toDouble(), + height: widget.adType == NativeAdType.NATIVE_AD ? widget.height : widget.bannerAdSize.height!.toDouble(), child: UiKitView( viewType: _getChannelRegisterId(), onPlatformViewCreated: _onNativeAdViewCreated, creationParamsCodec: StandardMessageCodec(), - creationParams: { - "id": widget.placementId, - "ad_type": widget.adType.index, - "banner_ad": - widget.adType == NativeAdType.NATIVE_BANNER_AD ? true : false, - "height": widget.adType == NativeAdType.NATIVE_BANNER_AD - ? widget.bannerAdSize.height - : widget.height, - "bg_color": widget.backgroundColor == null - ? null - : _getHexStringFromColor(widget.backgroundColor!), - "title_color": widget.titleColor == null - ? null - : _getHexStringFromColor(widget.titleColor!), - "desc_color": widget.descriptionColor == null - ? null - : _getHexStringFromColor(widget.descriptionColor!), - "label_color": widget.labelColor == null - ? null - : _getHexStringFromColor(widget.labelColor!), - "button_color": widget.buttonColor == null - ? null - : _getHexStringFromColor(widget.buttonColor!), - "button_title_color": widget.buttonTitleColor == null - ? null - : _getHexStringFromColor(widget.buttonTitleColor!), - "button_border_color": widget.buttonBorderColor == null - ? null - : _getHexStringFromColor(widget.buttonBorderColor!), - "is_media_cover": widget.isMediaCover, - }, + creationParams: creationParams, ), ); } else { @@ -277,8 +246,7 @@ class _FacebookNativeAdState extends State } } - String _getHexStringFromColor(Color color) => - '#${color.value.toRadixString(16)}'; + String _getHexStringFromColor(Color color) => '#${color.value.toRadixString(16)}'; void _onNativeAdViewCreated(int id) { final channel = MethodChannel('${NATIVE_AD_CHANNEL}_$id'); @@ -286,12 +254,10 @@ class _FacebookNativeAdState extends State channel.setMethodCallHandler((MethodCall call) { switch (call.method) { case ERROR_METHOD: - if (widget.listener != null) - widget.listener!(NativeAdResult.ERROR, call.arguments); + if (widget.listener != null) widget.listener!(NativeAdResult.ERROR, call.arguments); break; case LOADED_METHOD: - if (widget.listener != null) - widget.listener!(NativeAdResult.LOADED, call.arguments); + if (widget.listener != null) widget.listener!(NativeAdResult.LOADED, call.arguments); if (!isAdReady) { setState(() { @@ -313,21 +279,17 @@ class _FacebookNativeAdState extends State } break; case CLICKED_METHOD: - if (widget.listener != null) - widget.listener!(NativeAdResult.CLICKED, call.arguments); + if (widget.listener != null) widget.listener!(NativeAdResult.CLICKED, call.arguments); break; case LOGGING_IMPRESSION_METHOD: - if (widget.listener != null) - widget.listener!(NativeAdResult.LOGGING_IMPRESSION, call.arguments); + if (widget.listener != null) widget.listener!(NativeAdResult.LOGGING_IMPRESSION, call.arguments); break; case MEDIA_DOWNLOADED_METHOD: - if (widget.listener != null) - widget.listener!(NativeAdResult.MEDIA_DOWNLOADED, call.arguments); + if (widget.listener != null) widget.listener!(NativeAdResult.MEDIA_DOWNLOADED, call.arguments); break; } return Future.value(true); - }); } } From 4299fa3eccb3c98e08dd76136927055b71014b4a Mon Sep 17 00:00:00 2001 From: MattyBoy Date: Fri, 8 Oct 2021 14:20:44 -0500 Subject: [PATCH 2/2] Changed back to default line length --- lib/ad/ad_banner.dart | 35 ++++++++++++------ lib/ad/ad_native.dart | 82 ++++++++++++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 35 deletions(-) diff --git a/lib/ad/ad_banner.dart b/lib/ad/ad_banner.dart index c9db116..82584e0 100644 --- a/lib/ad/ad_banner.dart +++ b/lib/ad/ad_banner.dart @@ -20,7 +20,8 @@ class BannerSize { static const BannerSize STANDARD = BannerSize(width: 320, height: 50); static const BannerSize LARGE = BannerSize(width: 320, height: 90); - static const BannerSize MEDIUM_RECTANGLE = BannerSize(width: 320, height: 250); + static const BannerSize MEDIUM_RECTANGLE = + BannerSize(width: 320, height: 250); const BannerSize({this.width = 320, this.height = 50}); } @@ -81,7 +82,8 @@ class FacebookBannerAd extends StatefulWidget { _FacebookBannerAdState createState() => _FacebookBannerAdState(); } -class _FacebookBannerAdState extends State with AutomaticKeepAliveClientMixin { +class _FacebookBannerAdState extends State + with AutomaticKeepAliveClientMixin { double containerHeight = 0.5; @override @@ -102,10 +104,12 @@ class _FacebookBannerAdState extends State with AutomaticKeepA color: Colors.transparent, child: PlatformViewLink( viewType: BANNER_AD_CHANNEL, - surfaceFactory: (BuildContext context, PlatformViewController controller) { + surfaceFactory: + (BuildContext context, PlatformViewController controller) { return AndroidViewSurface( controller: controller as AndroidViewController, - gestureRecognizers: const >{}, + gestureRecognizers: const < + Factory>{}, hitTestBehavior: PlatformViewHitTestBehavior.opaque, ); }, @@ -139,9 +143,12 @@ class _FacebookBannerAdState extends State with AutomaticKeepA ); } else { return Container( - height: widget.bannerSize.height <= -1 ? double.infinity : widget.bannerSize.height.toDouble(), + height: widget.bannerSize.height <= -1 + ? double.infinity + : widget.bannerSize.height.toDouble(), child: Center( - child: Text("Banner Ads for this platform is currently not supported"), + child: + Text("Banner Ads for this platform is currently not supported"), ), ); } @@ -153,19 +160,25 @@ class _FacebookBannerAdState extends State with AutomaticKeepA channel.setMethodCallHandler((MethodCall call) { switch (call.method) { case ERROR_METHOD: - if (widget.listener != null) widget.listener!(BannerAdResult.ERROR, call.arguments); + if (widget.listener != null) + widget.listener!(BannerAdResult.ERROR, call.arguments); break; case LOADED_METHOD: setState(() { - containerHeight = widget.bannerSize.height <= -1 ? double.infinity : widget.bannerSize.height.toDouble(); + containerHeight = widget.bannerSize.height <= -1 + ? double.infinity + : widget.bannerSize.height.toDouble(); }); - if (widget.listener != null) widget.listener!(BannerAdResult.LOADED, call.arguments); + if (widget.listener != null) + widget.listener!(BannerAdResult.LOADED, call.arguments); break; case CLICKED_METHOD: - if (widget.listener != null) widget.listener!(BannerAdResult.CLICKED, call.arguments); + if (widget.listener != null) + widget.listener!(BannerAdResult.CLICKED, call.arguments); break; case LOGGING_IMPRESSION_METHOD: - if (widget.listener != null) widget.listener!(BannerAdResult.LOGGING_IMPRESSION, call.arguments); + if (widget.listener != null) + widget.listener!(BannerAdResult.LOGGING_IMPRESSION, call.arguments); break; } diff --git a/lib/ad/ad_native.dart b/lib/ad/ad_native.dart index deb7e73..306657d 100644 --- a/lib/ad/ad_native.dart +++ b/lib/ad/ad_native.dart @@ -135,7 +135,8 @@ class FacebookNativeAd extends StatefulWidget { _FacebookNativeAdState createState() => _FacebookNativeAdState(); } -class _FacebookNativeAdState extends State with AutomaticKeepAliveClientMixin { +class _FacebookNativeAdState extends State + with AutomaticKeepAliveClientMixin { final double containerHeight = Platform.isAndroid ? 1.0 : 0.1; bool isAdReady = false; @override @@ -143,7 +144,8 @@ class _FacebookNativeAdState extends State with AutomaticKeepA String _getChannelRegisterId() { String channel = NATIVE_AD_CHANNEL; - if (defaultTargetPlatform == TargetPlatform.iOS && widget.adType == NativeAdType.NATIVE_BANNER_AD) { + if (defaultTargetPlatform == TargetPlatform.iOS && + widget.adType == NativeAdType.NATIVE_BANNER_AD) { channel = NATIVE_BANNER_AD_CHANNEL; } return channel; @@ -151,17 +153,23 @@ class _FacebookNativeAdState extends State with AutomaticKeepA Widget build(BuildContext context) { super.build(context); - double width = widget.width == double.infinity ? MediaQuery.of(context).size.width : widget.width; + double width = widget.width == double.infinity + ? MediaQuery.of(context).size.width + : widget.width; return AnimatedContainer( color: Colors.transparent, width: width, - height: isAdReady || widget.keepExpandedWhileLoading ? widget.height : containerHeight, + height: isAdReady || widget.keepExpandedWhileLoading + ? widget.height + : containerHeight, duration: Duration(milliseconds: widget.expandAnimationDuraion), child: Stack( alignment: Alignment.center, children: [ Positioned.fill( - top: isAdReady || widget.keepExpandedWhileLoading ? 0 : -(widget.height - containerHeight), + top: isAdReady || widget.keepExpandedWhileLoading + ? 0 + : -(widget.height - containerHeight), child: ConstrainedBox( constraints: new BoxConstraints( maxHeight: widget.height, @@ -179,16 +187,32 @@ class _FacebookNativeAdState extends State with AutomaticKeepA final Map creationParams = { "id": widget.placementId, "ad_type": widget.adType.index, - "banner_ad": widget.adType == NativeAdType.NATIVE_BANNER_AD ? true : false, - "height": widget.adType == NativeAdType.NATIVE_BANNER_AD ? widget.bannerAdSize.height : widget.height, - "bg_color": widget.backgroundColor == null ? null : _getHexStringFromColor(widget.backgroundColor!), - "title_color": widget.titleColor == null ? null : _getHexStringFromColor(widget.titleColor!), - "desc_color": widget.descriptionColor == null ? null : _getHexStringFromColor(widget.descriptionColor!), - "label_color": widget.labelColor == null ? null : _getHexStringFromColor(widget.labelColor!), - "button_color": widget.buttonColor == null ? null : _getHexStringFromColor(widget.buttonColor!), - "button_title_color": widget.buttonTitleColor == null ? null : _getHexStringFromColor(widget.buttonTitleColor!), - "button_border_color": - widget.buttonBorderColor == null ? null : _getHexStringFromColor(widget.buttonBorderColor!), + "banner_ad": + widget.adType == NativeAdType.NATIVE_BANNER_AD ? true : false, + "height": widget.adType == NativeAdType.NATIVE_BANNER_AD + ? widget.bannerAdSize.height + : widget.height, + "bg_color": widget.backgroundColor == null + ? null + : _getHexStringFromColor(widget.backgroundColor!), + "title_color": widget.titleColor == null + ? null + : _getHexStringFromColor(widget.titleColor!), + "desc_color": widget.descriptionColor == null + ? null + : _getHexStringFromColor(widget.descriptionColor!), + "label_color": widget.labelColor == null + ? null + : _getHexStringFromColor(widget.labelColor!), + "button_color": widget.buttonColor == null + ? null + : _getHexStringFromColor(widget.buttonColor!), + "button_title_color": widget.buttonTitleColor == null + ? null + : _getHexStringFromColor(widget.buttonTitleColor!), + "button_border_color": widget.buttonBorderColor == null + ? null + : _getHexStringFromColor(widget.buttonBorderColor!), "is_media_cover": widget.isMediaCover, }; @@ -202,10 +226,12 @@ class _FacebookNativeAdState extends State with AutomaticKeepA : widget.bannerAdSize.height!.toDouble(), child: PlatformViewLink( viewType: NATIVE_AD_CHANNEL, - surfaceFactory: (BuildContext context, PlatformViewController controller) { + surfaceFactory: + (BuildContext context, PlatformViewController controller) { return AndroidViewSurface( controller: controller as AndroidViewController, - gestureRecognizers: const >{}, + gestureRecognizers: const < + Factory>{}, hitTestBehavior: PlatformViewHitTestBehavior.opaque, ); }, @@ -229,7 +255,9 @@ class _FacebookNativeAdState extends State with AutomaticKeepA } else if (defaultTargetPlatform == TargetPlatform.iOS) { return Container( width: width, - height: widget.adType == NativeAdType.NATIVE_AD ? widget.height : widget.bannerAdSize.height!.toDouble(), + height: widget.adType == NativeAdType.NATIVE_AD + ? widget.height + : widget.bannerAdSize.height!.toDouble(), child: UiKitView( viewType: _getChannelRegisterId(), onPlatformViewCreated: _onNativeAdViewCreated, @@ -246,7 +274,8 @@ class _FacebookNativeAdState extends State with AutomaticKeepA } } - String _getHexStringFromColor(Color color) => '#${color.value.toRadixString(16)}'; + String _getHexStringFromColor(Color color) => + '#${color.value.toRadixString(16)}'; void _onNativeAdViewCreated(int id) { final channel = MethodChannel('${NATIVE_AD_CHANNEL}_$id'); @@ -254,10 +283,12 @@ class _FacebookNativeAdState extends State with AutomaticKeepA channel.setMethodCallHandler((MethodCall call) { switch (call.method) { case ERROR_METHOD: - if (widget.listener != null) widget.listener!(NativeAdResult.ERROR, call.arguments); + if (widget.listener != null) + widget.listener!(NativeAdResult.ERROR, call.arguments); break; case LOADED_METHOD: - if (widget.listener != null) widget.listener!(NativeAdResult.LOADED, call.arguments); + if (widget.listener != null) + widget.listener!(NativeAdResult.LOADED, call.arguments); if (!isAdReady) { setState(() { @@ -279,13 +310,16 @@ class _FacebookNativeAdState extends State with AutomaticKeepA } break; case CLICKED_METHOD: - if (widget.listener != null) widget.listener!(NativeAdResult.CLICKED, call.arguments); + if (widget.listener != null) + widget.listener!(NativeAdResult.CLICKED, call.arguments); break; case LOGGING_IMPRESSION_METHOD: - if (widget.listener != null) widget.listener!(NativeAdResult.LOGGING_IMPRESSION, call.arguments); + if (widget.listener != null) + widget.listener!(NativeAdResult.LOGGING_IMPRESSION, call.arguments); break; case MEDIA_DOWNLOADED_METHOD: - if (widget.listener != null) widget.listener!(NativeAdResult.MEDIA_DOWNLOADED, call.arguments); + if (widget.listener != null) + widget.listener!(NativeAdResult.MEDIA_DOWNLOADED, call.arguments); break; }