import 'dart:developer'; import 'package:flutter/widgets.dart'; import 'package:yandex_mobileads/mobile_ads.dart'; class YandexAds { static BannerAd createBanner( BoxConstraints constraints, { String id = 'demo-banner-yandex', String? key, VoidCallback? onLoaded, }) { return BannerAd( adUnitId: id, // or 'demo-banner-yandex' adSize: BannerAdSize.inline( width: constraints.maxWidth.round(), maxHeight: constraints.maxHeight.round(), ), adRequest: const AdRequest(), onAdLoaded: () { log('Loaded $key'); onLoaded?.call(); }, onAdFailedToLoad: (error) { // Ad failed to load with AdRequestError. // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged. }, onAdClicked: () { // Called when a click is recorded for an ad. }, onLeftApplication: () { // Called when user is about to leave application (e.g., to go to the browser), as a result of clicking on the ad. }, onReturnedToApplication: () { // Called when user returned to application after click. }, onImpression: (impressionData) { // Called when an impression is recorded for an ad. }); } }