getListOfDeputes function

Future<List<DeputesFromCsv>> getListOfDeputes({
  1. String pathToDeputes = "https://data.assemblee-nationale.fr/static/openData/repository/16/amo/deputes_actifs_csv_opendata/liste_deputes_excel.csv",
  2. required Directory mainDirectory,
  3. bool forceRefresh = false,
})

If needed, download the CSV Excel-format from National Assembly open data. In any case, convert downloaded data :

pathToDeputes is the path to AN Deputees. If not provided, uses the default Path.

mainDirectory is the required Directory to download and extract files. You can use App Support directory for instance.

forceRefresh is a boolean to force the refresh of Open Data files.

Implementation

Future<List<DeputesFromCsv>> getListOfDeputes(
    {String pathToDeputes =
        "https://data.assemblee-nationale.fr/static/openData/repository/16/amo/deputes_actifs_csv_opendata/liste_deputes_excel.csv",
    required Directory mainDirectory,
    bool forceRefresh = false}) async {
  List<List<dynamic>> _listData = [];
  HttpClient httpClient = new HttpClient();

  String dossiersFilePath = mainDirectory.path + deputesCsvFile;

  if (!File(dossiersFilePath).existsSync() || forceRefresh) {
    await _updateListOfDeputes(
        pathToDeputes: pathToDeputes, destinationDirectory: mainDirectory);
  }

  File? dossiersFile = File(dossiersFilePath);

  String dossiersString = await dossiersFile.readAsString(encoding: latin1);
  _listData = CsvToListConverter().convert(dossiersString, fieldDelimiter: ";");

  List<DeputesFromCsv> _tempDeputes = [];
  for (var i = 1; i < _listData.length; i++) {
    DeputesFromCsv _tempTranscode =
        DeputesFromCsv.fromFrenchNationalAssemblyCsv(_listData[i]);
    _tempDeputes.add(_tempTranscode);
  }

  return _tempDeputes;
}