gpt4 book ai didi

dart - Flutter 应用程序中的远程配置在获取时引发异常

转载 作者:IT老高 更新时间:2023-10-28 12:38:02 26 4
gpt4 key购买 nike

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

这是我设置远程配置的方法。

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

在我的控制台中显示:

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

我该如何解决这个问题?

最佳答案

使用 Try Catch 封装 fetch() 和 activateFetched() api 调用

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

关于dart - Flutter 应用程序中的远程配置在获取时引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52983314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com