【问题标题】:How can I open/close Admob with Firebase Remote Config?如何使用 Firebase 远程配置打开/关闭 Admob?
【发布时间】:2019-05-30 11:54:05
【问题描述】:

我是 Flutter 和远程配置的新手。在我的项目中,我试图从远程配置中关闭我的广告横幅,如真/假声明,但我认为我错过了一些东西。如果您能给我任何建议,我将不胜感激。

我为 Flutter 导入了远程插件并进行了 android 集成。之后我初始化它

Future<RemoteConfig> setupRemoteConfig() async {
  final RemoteConfig remoteConfig = await RemoteConfig.instance;
  // Enable developer mode to relax fetch throttling
  remoteConfig.setConfigSettings(RemoteConfigSettings(debugMode: true));
  await remoteConfig.activateFetched();
  remoteConfig.setDefaults(<String, dynamic>{
    'admob_status': 'true',
  });
  return remoteConfig;
}

然后,我将它添加到我的构建小部件中。

var value = remoteConfig.getString("admob_status");

    if(value == "true"){
      FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId)
          .then((response) {
        myBanner
          ..load()
          ..show(
            //anchorOffset: 60.0,
              anchorType: AnchorType.bottom);
      });
    } else if(value == "false") {
      return null;
    }

并且输出是“方法 'getString' 在 null 上被调用。”

【问题讨论】:

    标签: flutter dart admob firebase-remote-config


    【解决方案1】:

    我想我找到了解决方案,它似乎有效。或许以后能帮到你

    checkAdmobStatus() async {
        final RemoteConfig remoteConfig = await RemoteConfig.instance;
    
        final defaults = <String, dynamic>{'status': 'true'};
        await remoteConfig.setDefaults(defaults);
    
        await remoteConfig.fetch();
        await remoteConfig.activateFetched();
    
        if ('true' == remoteConfig.getString('status')) {
          FirebaseAdMob.instance
              .initialize(appId: FirebaseAdMob.testAppId)
              .then((response) {
            myBanner
              ..load()
              ..show(anchorType: AnchorType.bottom);
          });
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-10
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多