readFile method
Reads and parses a JSON file at the given path
and merges its data
into result
.
The path
is the file path of the JSON file.
result
is the current map that accumulates language data.
The method extracts the filename without extension and uses it as the key in the result map. The parsed JSON data is stored as a map of key-value pairs (both as strings) within this key.
Returns a Map<String, Map<String, String>>
containing the updated
language data.
Implementation
Future<Map<String, Map<String, String>>> readFile(
String path,
Map<String, Map<String, String>> result,
) async {
try {
File file = File(path);
String filename = p.basenameWithoutExtension(path);
String jsonString = await file.readAsString();
Map<String, dynamic> jsonMap = jsonDecode(jsonString);
Map<String, String> map = jsonMap.map(
(key, value) => MapEntry(key, value.toString()),
);
result[filename] = map;
return result;
} catch (e) {
Console.e({'error': e});
}
return {};
}