dreamsoftin / facebook_audience_network

Flutter Facebook Audience Network
https://pub.dartlang.org/packages/facebook_audience_network/
MIT License
156 stars 89 forks source link

Getting error for height in IOS but works totally fine in Android #54

Closed AlohaTiger closed 4 years ago

AlohaTiger commented 4 years ago

Hi I am getting this error in IOS, but in Android, it works fine.

The following _TypeError was thrown building FacebookNativeAd(dirty, dependencies: [MediaQuery], state: _FacebookNativeAdState#fefd9):
type 'int' is not a subtype of type 'double'

Here is the code

class FacebookNativeBannerAdWidget extends StatefulWidget{
  final double width;
  final double height;
  final Color backgroundColor;
  final Color titleColor ;
  final Color descriptionColor;
  final Color buttonColor;
  final Color buttonTitleColor;
  final Color buttonBorderColor;

  const FacebookNativeBannerAdWidget({Key key,@required this.width,@required this.backgroundColor,
          @required this.titleColor,@required this.descriptionColor,@required this.buttonColor,@required this.buttonTitleColor,
          @required this.buttonBorderColor,@required this.height}) : super(key: key);

  @override
  _FacebookNativeBannerAdWidgetState createState() => _FacebookNativeBannerAdWidgetState();
}

class _FacebookNativeBannerAdWidgetState extends State<FacebookNativeBannerAdWidget> {

  @override
  void initState() {
    super.initState();

    FacebookAudienceNetwork.init(
      // puting device-id for testing only
      // IOS
      testingId: "7d1416eb-c8c4-4b81-b1a8-4e0c8045bb76",
      // Android Emulator
      // testingId: "d18eeefd-1ab0-4bca-a479-4bfc6073379e",
    );
  }

  @override
  Widget build(BuildContext context) {
    return FacebookNativeAd(
      adType: NativeAdType.NATIVE_BANNER_AD,
      placementId: Platform.isAndroid ? '603201673930615_606066876977428' : '603201673930615_606067633644019',
      width: widget.width,
      height: widget.height < 50.0 ? 50.0 : widget.height > 50.0 && widget.height < 120.0 ? 100.0 : 120.0 ,
      bannerAdSize: widget.height < 50.0 ? NativeBannerAdSize.HEIGHT_50 : widget.height > 50.0 && widget.height < 120.0 ? NativeBannerAdSize.HEIGHT_100 : NativeBannerAdSize.HEIGHT_120,
      backgroundColor: widget.backgroundColor,
      titleColor: widget.titleColor,
      descriptionColor: widget.descriptionColor,
      buttonColor: widget.buttonColor,
      buttonTitleColor: widget.buttonTitleColor,
      buttonBorderColor: widget.buttonBorderColor,
      keepExpandedWhileLoading: false,
      listener: (result, value) {
        print("Native Ad: $result --> $value");   
        }
      );
  }
ourmazd commented 4 years ago

just open ad_native.dart and change line 190 from widget.height : widget.bannerAdSize.height.toInt(),

to this widget.height : widget.bannerAdSize.height.toDouble(),

AlohaTiger commented 4 years ago

@ourmazd Nice, but instead of line 190, it should be line 232.

AlohaTiger commented 4 years ago

@dharmesh304 Bug fixed. Thanks.

rushabhshah065 commented 4 years ago

I am still getting this same error for version 0.7.1.

CalvinTp commented 3 years ago

Same here, I am getting this error on version 0.7.1

The following _TypeError was thrown building FacebookNativeAd(dirty, dependencies: [MediaQuery], state: _FacebookNativeAdState#6c492): type 'int' is not a subtype of type 'double'

jesusspr commented 3 years ago

This bug is not fixed yet in 0.7.1