Remote config in Flutter app throws exception on fetch

爷,独闯天下 提交于 2020-05-26 19:14:29

问题


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

This is my method for setting up remote config.

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;
}

This code throws the following exception:

Exception: Unable to fetch remote config

and in my console it says:

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

How can I fix this?


回答1:


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');
  }

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



来源:https://stackoverflow.com/questions/52983314/remote-config-in-flutter-app-throws-exception-on-fetch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!