Settings.fromJson constructor

Settings.fromJson(
  1. Map json
)

Implementation

factory Settings.fromJson(Map json) {
  final result = _$SettingsFromJson(json);

  final patterns = <String, List<String>>{};

  result.priorities
      .forEach((e) => patterns.putIfAbsent(e, () => []).add('priorities'));
  result.register
      .forEach((e) => patterns.putIfAbsent(e, () => []).add('register'));
  result.factories
      .forEach((e) => patterns.putIfAbsent(e, () => []).add('factories'));
  result.lazySingletons.forEach(
      (e) => patterns.putIfAbsent(e, () => []).add('lazy_singletons'));
  result.singletons
      .forEach((e) => patterns.putIfAbsent(e, () => []).add('singletons'));
  result.doNotRegister.forEach(
      (e) => patterns.putIfAbsent(e, () => []).add('do_not_register'));

  // make sure that the priorities patterns are valid regex
  for (final MapEntry(key: pattern, value: locations) in patterns.entries) {
    try {
      RegExp(pattern);
    } catch (error) {
      throw ArgumentError.value(
        pattern,
        'Found in ${locations.join(',')}',
        error,
      );
    }
  }

  return result;
}