getListOfProjetsLois function

Future<List<ProjetLoiFromJson>> getListOfProjetsLois({
  1. required Directory mainDirectory,
})

Get the Projets Lois JSON files in designated directory and convert to ProjetLoiFromJson:

mainDirectory is the required Directory where Open Data ZIP was extracted. You can use App Support directory for instance.

Implementation

Future<List<ProjetLoiFromJson>> getListOfProjetsLois(
    {required Directory mainDirectory}) async {
  List<ProjetLoiFromJson> _listToReturn = [];
  Directory theDirectory = Directory(mainDirectory.path +
      docsLegisDirectory +
      jsonIntermediaryDirectory +
      documentDirectory);
  List<FileSystemEntity> _initialListOfFiles =
      await theDirectory.list(recursive: true).toList();
  for (FileSystemEntity file in _initialListOfFiles) {
    if (file.path.split("/").last.substring(0, 1) != ".") {
      // to exclude any system file
      if (file.path.split("/").last.substring(0, 4) == "PRJL") {
        File _theFile = File(file.path);
        dynamic response = await _theFile.readAsString();

        if (response != null) {
          Map<String, dynamic> _map = json.decode(response);
          ProjetLoiFromJson _toReturn =
              ProjetLoiFromJson.fromFrenchNationalAssemblyJson(_map);
          _listToReturn.add(_toReturn);
        }
      }
    }
  }
  return _listToReturn;
}