getJsonScrutin method
Get JSON file (local or remote) and map to ScrutinFromJson
Implementation
Future<ReturnFromJson?> getJsonScrutin(
{String? localPath, String? remotePath, String? amendementPath}) async {
dynamic responseToProcess = "";
dynamic amendementToProcess = "";
// print("amendementPath = " + (amendementPath ?? "NOPE"));
if (remotePath != null) {
// print("sending to remote");
responseToProcess = await _checkAvailabilityOfRemoteFile(remotePath);
if (amendementPath != null) {
amendementToProcess =
await _checkAvailabilityOfRemoteFile(amendementPath);
// print("&\n" + amendementToProcess + "\n&");
}
// print("&\n" + responseToProcess + "\n&");
} else if (localPath != null) {
responseToProcess = await _checkAvailabilityOfLocalFile(localPath);
if (amendementPath != null) {
amendementToProcess =
await _checkAvailabilityOfLocalFile(amendementPath);
}
}
if (responseToProcess != "") {
Map<String, dynamic> _mapScrutin = json.decode(responseToProcess);
ScrutinFromJson _scrutinToReturn =
ScrutinFromJson.fromFrenchNationalAssemblyJson(_mapScrutin);
ReturnFromJson _toReturn = ReturnFromJson(_scrutinToReturn);
if (amendementToProcess != "") {
// print("••• STEP 1 •••");
Map<String, dynamic> _mapAmendement = json.decode(amendementToProcess);
// print("••• STEP 2 •••");
AmendementFromJson? _amendementToReturn =
AmendementFromJson.fromFrenchNationalAssemblyJson(_mapAmendement);
// print("••• STEP 4 •••");
_toReturn.amendement = _amendementToReturn;
}
return _toReturn;
} else {
return null;
}
}