Flutter:使用 InterstitialAd 时,此库禁用了空安全功能? _interstitialAd;

时间:2021-06-02 07:54:06

标签: flutter dart flutter-layout flutter-dependencies google-ads-api

我正在我的 flutter 项目中集成插页式广告。 但是当我这样声明时

 InterstitialAd? _interstitialAd;

我收到此错误:

33:17: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.12 or higher.
  InterstitialAd? _interstitialAd;
                ^
lib/admob_service.dart:64:20: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.12 or higher.
    _interstitialAd!.fullScreenContentCallback = FullScreenContentCallback(
                   ^
lib/admob_service.dart:79:20: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.12 or higher.
    _interstitialAd!.show();

我看到了一些stackoverflow的答案,并尝试从

升级sdk版本
environment:
  sdk: ">=2.7.0 <3.0.0"

environment:
  sdk: ">=2.12.0 <3.0.0"

然后我在我的整个项目中出现错误。错误信息是:

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:local_database
 - package:auto_size_text
 - package:queue

除了声明这个:InterstitialAd 还有什么方法吗? _interstitialAd;

1 个答案:

答案 0 :(得分:0)

似乎您提到的软件包尚未迁移到空安全,因此出现错误。

这里唯一的解决方法是将包更新到它们的 null-safety 版本(如果有),或者只是不要为您的项目使用声音 null 安全。