yandexmobile / yandex-ads-flutter-plugin

Flutter plugin for Yandex Mobile Ads SDK. This plugin allows Flutter developers to easily integrate Yandex Mobile Ads SDK on Android and iOS apps.
Other
11 stars 2 forks source link

InterstitialAd.waitForDismiss() it works for a very long time #2

Closed zikwall closed 1 year ago

zikwall commented 1 year ago

There are two screens in app, it works fast on one, it works very slowly on other, although code of screens is completely identical and calls same functions.

Future<InterstitialAd> _createInterstitialAd() {
  return InterstitialAd.create(
    adUnitId: interstitialAd,
  );
}

Future<bool> _showInterstitialAd() async {
  var adRequest = const AdRequest();
  final ad = await _createInterstitialAd();
  await ad.load(adRequest: adRequest);
  await ad.show();
  await ad.waitForDismiss();
  return true;
}

// call

await _showInterstitialAd();

we have to choose other ways, for example:

Future<bool> _showInterstitialAd() async {
    final ad = await _createInterstitialAd();
    await ad.load(adRequest: adRequest);
    await ad.show();

    // change begin
    await Future.any([
      ad.waitForDismiss(),
      Future.delayed(const Duration(milliseconds: 100))
    ]);
    // change end

    return true;
}
$ flutter doctor -v

[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.19044.2364], locale ru-RU)
    • Flutter version 3.3.10 on channel stable at D:\Dart\FlutterSDK\flutter
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision 135454af32 (3 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

...

[√] HTTP Host Availability
    • All required HTTP hosts are available