---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/easy/integration/flutter/formats/banner.md
  - https://ads.yandex.com/helpcenter/ru/easy/integration/flutter/formats/banner.md
  - https://ads.yandex.com/helpcenter/zh/easy/integration/flutter/formats/banner.md
  - href: ru/easy/integration/flutter/formats/banner.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/ru/llms.txt

# Баннер

## Виды баннеров

В Yandex Mobile Ads SDK есть два вида баннеров:

#|
||

**Баннер**

|

**Описание**

|

**Когда использовать**

||
||

Sticky

|

Баннер-липучка, который примыкает к краю экрана и появляется поверх других элементов. Устойчивый к прокрутке.

|

Когда баннер должен «приклеиться» и находиться поверх контента даже при прокрутке.

||
||

Inline

|

Баннер, который встраивается как элемент UI — в списки, контент и т. д.

|

Когда баннер должен быть частью контента: в ленте новостей, между постами, как элемент списка.

||
|#

Все виды автоматически обновляют креатив каждые 60 секунд.

{% note tip %}

Чтобы установить свой период для автообновления, обратитесь к персональному менеджеру. 

{% endnote %}

Программно виды отличаются лишь тем, как задается их размер. Примеры:

{% list tabs %}

- Sticky-баннер

    ```dart
    BannerAdSize.sticky(width: screenWidth)
    ```

- Inline-баннер

    ```dart
    BannerAdSize.inline(width: screenWidth, maxHeight: maxHeight)
    ```

{% endlist %}


#|
||

**Сущность**

|

**Описание**

||
||

`BannerAdSize`

|

Высота баннера должна:

- **не** превышать 15% от высоты экрана;

- составлять не менее 50 **dp/pt** (**Android/iOS**).

Все размеры баннера должны передаваться строго в **dp**.

||
||

`adUnitId`

|

Используйте:

- **development mode** — для работы с [демоблоками](https://ads.yandex.com/helpcenter/ru/easy/integration/flutter/testing.md#blocks);

- **production mode** — для работы с `R-M-XXXXXX-Y` (уточните реальный ID в интерфейсе Рекламной сети Яндекса). `R-M-XXXXXX-Y` — это вид рабочего рекламного ID, по которому будут приходить разные креативы.

||
|#

<!-- source: ru/easy/_includes/notes-flutter-easy-guide.md -->
{% note info %}

Пример работы всех типов форматов есть в [демопроекте](https://ads.yandex.com/helpcenter/ru/easy/integration/flutter/testing.md#demo).

{% endnote %}
<!-- endsource: ru/easy/_includes/notes-flutter-easy-guide.md -->

## Пример создания баннера

```dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:yandex_mobileads/mobile_ads.dart';

class BannerPage extends StatefulWidget {
  const BannerPage({super.key});

  @override
  State<BannerPage> createState() => _BannerPageState();
}

class _BannerPageState extends State<BannerPage> {
  static const _tag = 'Banner';
  static const _adUnitId = 'demo-banner-yandex';

  BannerAd? _banner;
  StreamSubscription<BannerAdLoadState>? _loadSubscription;
  StreamSubscription<BannerAdEvent>? _eventSubscription;
  String _status = 'Loading...';

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (_banner == null) {
      _createBanner();
    }
  }

  @override
  void dispose() {
    _loadSubscription?.cancel();
    _eventSubscription?.cancel();
    _banner?.destroy();
    super.dispose();
  }

  void _createBanner() {
    final size = MediaQuery.of(context).size;
    final screenWidth = size.width.round();
    final maxHeight = (size.height / 3).round();

    final banner = BannerAd(
      adSize: BannerAdSize.inline(width: screenWidth, maxHeight: maxHeight),
    );

    _loadSubscription?.cancel();
    _eventSubscription?.cancel();

    _loadSubscription = banner.loadStateStream.listen((state) {
      if (state is BannerAdLoadStateLoaded) {
        debugPrint('[$_tag] onAdLoaded');
        if (mounted) setState(() => _status = 'Loaded');
      } else if (state is BannerAdLoadStateError) {
        debugPrint('[$_tag] onAdFailedToLoad: ${state.error.description}');
        if (mounted) setState(() => _status = 'Error: ${state.error.description}');
      }
    });

    _eventSubscription = banner.events.listen((event) {
      if (event is BannerAdClickedEvent) {
        debugPrint('[$_tag] onAdClicked');
      } else if (event is BannerAdImpressionEvent) {
        debugPrint('[$_tag] onAdImpression');
      }
    });

    banner.load(AdRequest(adUnitId: _adUnitId));
    _banner = banner;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Banner')),
      body: Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(16),
            child: Text(_status),
          ),
          const Spacer(),
          if (_banner != null)
            SizedBox(
              width: double.infinity,
              child: AdWidget(bannerAd: _banner!),
            ),
        ],
      ),
    );
  }
}

```

## Проверка интеграции

<!-- source: ru/easy/_includes/notes-flutter-easy-guide.md -->
Соберите и запустите проект. Успешную интеграцию можно проверить в **Logcat** **Android Studio** по ключевому слову `YandexAds`:
<!-- endsource: ru/easy/_includes/notes-flutter-easy-guide.md -->

```
[Integration] Ad type Banner was integrated successfully
```
