How to replace Facebook Native Ad widget with any widget in case of error and can I preload Facebook native ad in a Flutter app?

Viewed 98

I am trying to show Facebook Native ads using Facebook Audience Network in a Flutter app. In case of any error loading native ads, I can't replace 'my native ad widget' with alternative widget. Here is my code creating Native Ad widget:

Container(
  //height: 40,
  decoration: BoxDecoration(
    color: Colors.white.withOpacity(0.07),
    borderRadius: BorderRadius.circular(8.0),
  ),
  padding: EdgeInsets.all(10),
  margin: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
  child: FacebookNativeAd(
    placementId: "YOUR_PLACEMENT_ID",
    adType: Platform.isAndroid ? NativeAdType.NATIVE_AD : NativeAdType.NATIVE_AD_VERTICAL,
    width: double.infinity,
    height: 300,
    backgroundColor: Colors.white12,
    titleColor: Colors.white,
    descriptionColor: Colors.white,
    buttonColor: Colors.deepPurple,
    buttonTitleColor: Colors.white,
    buttonBorderColor: Colors.white,
    listener: (result, value) {
      print("FB Native Ad: $result --> $value");
      if(value["invalidated"]) {
        print("Sth went wrong...Replace ad widget witt sth else...");
        return Text("Error... There is a problem with Facebook Native ad");
      }
    },
    keepExpandedWhileLoading: true,
    expandAnimationDuraion: 1000,
  ),
)

I'm trying to handle this in listener: (result, value){ //handle error }; I can read the print('Sth went wrong...') message in debug console, but the ad widget wasn't replaced with Text('Error...'). So how to replace my native ad widget with another widget in case of any error loading native ads? Secondly is there any way to preload(e.g. in initState()) Facebook native ad? Thank you.

0 Answers
Related