loadFromAsset method
Retrieves the content inside the JSON
file and initalizes the _localizedStrings
object using the retrieved data.
The result of retrieving the data will either be true (successed) or false (failed).
Implementation
Future<bool> loadFromAsset(String jsonAssetURL) async {
// Try to load the JSON asset.
try {
_localizedStrings = jsonDecode(await rootBundle.loadString(jsonAssetURL));
// Retrieving the data was successful.
return true;
// Catch the exception if the file is either empty or non existing.
} catch (e) {
if (debug) {
print(
"LitLocalizationService: JSON file does not contain a valid format or does not exist. Please verify the JSON fileĀ“s existence inside the provided directory.");
}
// Retrieving the data failed.
return false;
}
}