from static method

FileDefinitionProvider from(
  1. String type,
  2. Map definitionsMap
)
override

Implementation

static FileDefinitionProvider from(String type, Map definitionsMap) {
  var providerMap = definitionsMap[type];
  if (providerMap == null) {
    throw ConfigError(
        "Missing configuration for provider '$type'. Please review Ensemble documentation.");
  }
  var path = type == _Provider.local.name
      ? _formatPath(providerMap['path'])
      : Utils.optionalString(providerMap['path']);
  if (path == null) {
    throw ConfigError(
        "'path' is required and should point to ${type == _Provider.local.name ? 'a local directory' : 'your Https server'} where the screen definitions and assets are stored.");
  }
  var appHome = Utils.optionalString(providerMap['appHome']);
  if (appHome == null) {
    throw ConfigError(
        "'appHome' is required. This is the home screen's name or id.");
  }
  var forcedLocale =
      DefinitionProvider._localeFromString(providerMap['forcedLocale']);
  var i18nProps = _getI18Props(providerMap);
  if (type == _Provider.local.name) {
    return LocalDefinitionProvider(path, appHome,
        i18nProps: i18nProps, initialForcedLocale: forcedLocale);
  } else {
    bool cacheEnabled = definitionsMap['enableCache'] == true;
    return RemoteDefinitionProvider(path, appHome,
        i18nProps: i18nProps,
        initialForcedLocale: forcedLocale,
        cacheEnabled: cacheEnabled);
  }
}