Flutter应用中的远程配置在获取时引发异常 [英] Remote config in Flutter app throws exception on fetch

查看:87
本文介绍了Flutter应用中的远程配置在获取时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Flutter应用程序,我正在使用远程配置来检索一些信息,但是代码在获取数据时会引发异常。

I have a Flutter app and I am using remote config to retrieve some information, but the code throws an exception when fetching data.

这是我的设置方法

Future<RemoteConfig> setupRemoteConfig() async {
  final RemoteConfig remoteConfig = await RemoteConfig.instance;
  // Enable developer mode to relax fetch throttling
  remoteConfig.setConfigSettings(RemoteConfigSettings(debugMode: true));
  remoteConfig.setDefaults(<String, dynamic>{
    'categories': "food,drink",
  });
  await remoteConfig.fetch(expiration: const Duration(hours: 5));
  await remoteConfig.activateFetched();
  return remoteConfig;
}

此代码引发以下异常:

Exception: Unable to fetch remote config

并在我的控制台中显示:

and in my console it says:

W/FirebaseRemoteConfig(10456): IPC failure: 6503:NOT_AVAILABLE

我该如何解决?

推荐答案

使用尝试捕获包装您的fetch()和ActivateFetched()api调用

Wrap your fetch() and activateFetched() api calls with a Try Catch

try {
    // Using default duration to force fetching from remote server.
    await remoteConfig.fetch(expiration: const Duration(seconds: 0));
    await remoteConfig.activateFetched();
  } on FetchThrottledException catch (exception) {
    // Fetch throttled.
    print(exception);
  } catch (exception) {
    print(
        'Unable to fetch remote config. Cached or default values will be '
        'used');
  }

在此处查看官方示例: https://github.com/flutter/plugins/blob/master/packages/firebase_remote_config/example /lib/main.dart

See official example here: https://github.com/flutter/plugins/blob/master/packages/firebase_remote_config/example/lib/main.dart

这篇关于Flutter应用中的远程配置在获取时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆