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

# 插屏广告

<!-- source: zh/easy/_includes/sdk-guide.md -->
插屏广告是一种全屏广告格式，会在自然停顿处（例如当用户进入游戏下一关卡或完成转化操作时）嵌入到应用内容中。
<!-- endsource: zh/easy/_includes/sdk-guide.md -->

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

[演示项目](https://ads.yandex.com/helpcenter/zh/easy/integration/flutter/testing.md#demo)中提供了展示所有格式类型运作原理的示例。

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

#|
||

**实体**

|

**描述**

||
||

`HandleAdFailedToLoad`

|

如果 `HandleAdFailedToLoad()` 返回错误，请勿尝试**使用相同方法**再次加载新广告。

||
||

`adUnitId`

|

使用：

- **开发模式**，用于配合[演示广告单元](https://ads.yandex.com/helpcenter/zh/easy/integration/flutter/testing.md#blocks)使用。

- **生产模式**，用于配合 `R-M-XXXXXX-Y` 使用（实际 ID 请在 Yandex Advertising Network 界面查询）。`R-M-XXXXXX-Y` 是您实际广告单元 ID 的模板，将用于接收各种广告创意。

||
|#


## 插屏广告创建示例

```C#
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:yandex_mobileads/mobile_ads.dart';

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

  @override
  State<InterstitialPage> createState() => _InterstitialPageState();
}

class _InterstitialPageState extends State<InterstitialPage> {
  static const _tag = 'Interstitial';
  static const _adUnitId = 'demo-interstitial-yandex';
  InterstitialAdLoader? _loader;
  InterstitialAd? _ad;
  String _status = 'Initializing...';

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

  @override
  void dispose() {
    _ad?.destroy();
    super.dispose();
  }

  Future<void> _init() async {
    setState(() => _status = 'Creating loader...');

    _loader = await InterstitialAdLoader.create(
      onAdLoaded: (ad) {
        debugPrint('[$_tag] onAdLoaded');
        if (!mounted) { ad.destroy(); return; }
        _ad = ad;
        setState(() => _status = 'Showing...');
        _show();
      },
      onAdFailedToLoad: (error) {
        debugPrint('[$_tag] onAdFailedToLoad: ${error.description}');
        if (mounted) setState(() => _status = 'Error: ${error.description}');
      },
    );

    setState(() => _status = 'Loading ad...');

    await _loader!.loadAd(
      adRequestConfiguration: AdRequestConfiguration(adUnitId: _adUnitId),
    );
  }

  Future<void> _show() async {
    final ad = _ad;
    if (ad == null) return;

    ad.setAdEventListener(
      eventListener: InterstitialAdEventListener(
        onAdShown: () => debugPrint('[$_tag] onAdShown'),
        onAdDismissed: () {
          debugPrint('[$_tag] onAdDismissed');
          if (mounted) {
            setState(() => _status = 'Closed');
            Navigator.of(context).pop();
          }
        },
        onAdClicked: () => debugPrint('[$_tag] onAdClicked'),
        onAdFailedToShow: (error) {
          debugPrint('[$_tag] onAdFailedToShow: ${error.description}');
          if (mounted) setState(() => _status = 'Show error: ${error.description}');
        },
        onAdImpression: (ImpressionData impressionData) =>
            debugPrint('[$_tag] onAdImpression: $impressionData'),
      ),
    );

    await ad.show();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Interstitial')),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            const CircularProgressIndicator(),
            const SizedBox(height: 16),
            Text(_status),
          ],
        ),
      ),
    );
  }
}

```


## 检查集成

<!-- source: zh/easy/_includes/notes-flutter-easy-guide.md -->
创建并运行您的项目。您可以通过在 **Android Studio** 的 **Logcat** 中搜索 `YandexAds` 关键字来检查集成是否成功：
<!-- endsource: zh/easy/_includes/notes-flutter-easy-guide.md -->

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