---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/flutter/release/8-0-0-migration.md
  - https://ads.yandex.com/helpcenter/ru/dev/flutter/release/8-0-0-migration.md
  - https://ads.yandex.com/helpcenter/zh/dev/flutter/release/8-0-0-migration.md
  - href: en/dev/flutter/release/8-0-0-migration.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/en/llms.txt

# Guide for migrating to version 8

## General changes

Renamed the `MobileAds` class to `YandexAds`.

Renamed the following properties and methods:

#|
|| **SDK 7** | **SDK 8** ||
|| `MobileAds.setLocationConsent(bool)` | `YandexAds.setLocationTracking(bool)` ||
|| `MobileAds.setAgeRestrictedUser(bool)` | `YandexAds.setAgeRestricted(bool)` ||
|#

## Ad request

Removed the `AdRequestConfiguration` class. Use `AdRequest` instead, which now includes `adUnitId`.

Targeting fields (`age`, `contextQuery`, `contextTags`, `gender`, `location`) have been moved from `AdRequest` into a new `AdTargeting` class.

#|
||
Ad request
| **SDK 7**

```dart
final adRequestConfiguration = AdRequestConfiguration(
  adUnitId: 'your-ad-unit-id',
  age: 25,
  contextQuery: 'query',
  parameters: {'key': 'value'},
);

await adLoader.loadAd(
  adRequestConfiguration: adRequestConfiguration,
);
```

**SDK 8**

```dart
final adRequest = AdRequest(
  adUnitId: 'your-ad-unit-id',
  targeting: AdTargeting(
    age: 25,
    contextQuery: 'query',
  ),
  parameters: {'key': 'value'},
);

final ad = await adLoader.loadAd(adRequest: adRequest);
```
||
|#

## Fullscreen ads (interstitial, rewarded, app open)

We changed the approach to creating and loading fullscreen ads. The loader constructor is now synchronous and `loadAd` returns the loaded ad directly as a `Future`.

Removed the `InterstitialAdLoadListener`, `RewardedAdLoadListener`, and `AppOpenAdLoadListener` classes.

#|
||
Ad loading
| **SDK 7**

Asynchronous creation with callbacks:

```dart
late final Future<InterstitialAdLoader> _adLoader =
      _createInterstitialAdLoader();
InterstitialAd? _ad;

Future<InterstitialAdLoader> _createInterstitialAdLoader() {
  return InterstitialAdLoader.create(
    onAdLoaded: (InterstitialAd interstitialAd) {
      // The ad was loaded successfully. Now you can show loaded ad
      _ad = interstitialAd;
    },
    onAdFailedToLoad: (error) {
      // Ad failed to load with AdRequestError.
      // Attempting to load a new ad from the onAdFailedToLoad() method is strongly discouraged.
    },
  );
}

Future<void> _loadInterstitialAd() async {
  final adLoader = await _adLoader;
  await adLoader.loadAd(adRequestConfiguration: AdRequestConfiguration(adUnitId: 'your-ad-unit-id'));
}
```

**SDK 8**

Synchronous creation, `loadAd` returns the loaded ad or throws `AdRequestError`:

```dart
final _adLoader = InterstitialAdLoader();
InterstitialAd? _ad;

Future<void> _loadInterstitialAd() async {
  try {
    _ad = await _adLoader.loadAd(
      adRequest: AdRequest(adUnitId: 'your-ad-unit-id'),
    );
  } on AdRequestError catch (error) {
    // Ad failed to load with AdRequestError.
    // Attempting to load a new ad from the error handler is strongly discouraged.
  }
}
```

||
|#

The same changes apply to `RewardedAdLoader` and `AppOpenAdLoader`.

## Banners

We changed the approach to creating and loading banner ads. The banner constructor no longer accepts `adRequest` or callbacks. Loading is now explicit via `load(AdRequest)`. Ad state and events are delivered through streams.

#|
||
Banner ad creation and loading
| **SDK 7**

```dart
BannerAd? _banner;

void _createBanner() {
  _banner = BannerAd(
    adSize: BannerAdSize.stickySize(width),
    adRequest: AdRequest(),
    onAdLoaded: () {
      // Ad loaded
    },
    onAdFailedToLoad: (error) {
      // Ad failed to load
    },
    onAdClicked: () {},
    onImpression: (data) {},
  );
}
```

**SDK 8**

```dart
BannerAd? _banner;

void _createBanner() {
  final banner = BannerAd(adSize: BannerAdSize.stickySize(width));

  banner.loadStateStream.listen((state) {
    if (state is BannerAdLoadStateLoaded) {
      // Ad loaded
    } else if (state is BannerAdLoadStateError) {
      // Ad failed to load
    }
  });

  banner.events.listen((event) {
    if (event is BannerAdClickedEvent) {
      // Ad clicked
    } else if (event is BannerAdImpressionEvent) {
      // Impression
    }
  });

  banner.load(AdRequest(adUnitId: 'your-ad-unit-id'));
  _banner = banner;
}
```

||
||
Banner ad destroy
| **SDK 7**

```dart
_banner?.destroy();
```

**SDK 8**

```dart
await _banner?.destroy();
```

||
|#

## Ad info

The `AdInfo` class has been restructured. Removed the `adSize` field. Added `creatives`, `extraData`, and `partnerText` fields.

#|
|| **SDK 7** | **SDK 8** ||
|| `AdInfo.adSize` | Removed ||
|| — | `AdInfo.creatives` (`List<Creative>`) ||
|| — | `AdInfo.extraData` (`String?`) ||
|| — | `AdInfo.partnerText` (`String?`) ||
|#

## Removed events

Removed the `onLeftApplication`, `onReturnedToApplication`, and `onAdClose` callback events.


