Langaugeset.fromJsonString constructor

Langaugeset.fromJsonString(
  1. Locale locale,
  2. String jsonFile
)

Returns Languageset from JsonString Json should look like this: { "1":"2", "2":"2" } Key and Value of every element in JsonString has to be typeOf String

Implementation

factory Langaugeset.fromJsonString(Locale locale, String jsonFile) {
  Map<String, dynamic>? jsonMap = json.decode(jsonFile);

  bool checkIfString(List<dynamic> list) {
    bool ans = true;
    for (int x = 0; x < list.length; x++) {
      if (list[x].runtimeType.toString() != "String") {
        return !ans;
      }
    }
    return ans;
  }

  if (checkIfString(jsonMap!.values.toList()) &&
      checkIfString(jsonMap.keys.toList())) {
    return Langaugeset(locale, jsonMap);
  } else {
    throw ("jsonString does not meet requirements. Languageset with Locale: ${locale.scriptCode}");
  }
}