I am going to add facebook_audience_network flutter plugin with the following command.
flutter pub add facebook_audience_network
I am planning to add banner ad to details screen; after installing facebook ad plugin to my flutter app now I can import its code my details screen like below.
import 'package:facebook_audience_network/facebook_audience_network.dart';
To serve ads I need to create StatefulWidget. You will have to change the placementID. Just add your PlacementID after # sign.
class Details extends StatefulWidget {
@override
_DetailsState createState() => _DetailsState();
}
class _DetailsState extends State<Details> {
Widget _currentAd = SizedBox(
width: 0.0,
height: 0.0,
);
@override
void initState() {
FacebookAudienceNetwork.init(
);
super.initState();
setState(() {
_currentAd = FacebookBannerAd(
placementId: "IMG_16_9_LINK#YOUR_BANNER_ID",
bannerSize: BannerSize.STANDARD,
listener: (result, value) {
print("Banner Ad: $result --> $value");
},
);
});
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
margin: EdgeInsets.only(top: 5.0, bottom: 5.0),
child: _currentAd,
),
),
}