Config.fromMap constructor

Config.fromMap(
  1. PlatformValueProvider valueProvider,
  2. Map config,
  3. Map<String, dynamic> args
)

Implementation

factory Config.fromMap(PlatformValueProvider valueProvider,
    Map<dynamic, dynamic> config, Map<String, dynamic> args) {
  final String? devExtension = config[ConfigFieldType.DEV_EXTENSION];
  final Map<dynamic, dynamic> configFields = config[ConfigFieldType.FIELDS];
  final Map<dynamic, dynamic> extensions =
      config[ConfigFieldType.EXTENSIONS] ?? {};

  Map<dynamic, dynamic> extension = {};
  String? extensionName;

  if (devExtension != null && args[devExtension]) {
    extensionName = devExtension;
  }

  extensionName ??= args[ConfigFieldType.CONFIG_EXTENSION];

  if (extensionName != null) {
    if (!extensions.containsKey(extensionName)) {
      throw ExtensionNotFound(extensionName);
    }

    extension = extensions[extensionName] ?? {};
  }

  Map<dynamic, dynamic> extensionFields =
      extension[ConfigFieldType.FIELDS] ?? {};

  final Iterable<FieldConfig> fields = configFields.keys.map((key) =>
      FieldConfig(
          valueProvider,
          key,
          config[ConfigFieldType.FIELDS][key] ?? {},
          extensionFields[key] ?? {},
          args[key]));

  return Config(config, args, fields, extension);
}