export method

Future<String> export(
  1. DateTime start,
  2. DateTime end
)

Return json String with ServiceOfJournal between dates start and end

It gets values from both hive and hiveArchive. The end date is not included, the dates DateTime should be rounded to zero time.

Implementation

Future<String> export(DateTime start, DateTime end) async {
  Iterable<ServiceOfJournal> curState = state;
  if (openHive.isLoading) {
    await ref.read(hiveJournalBox(journalHiveName).future);
    curState = openHive.requireValue.values;
  }

  await ref.read(hiveJournalBox(archiveHiveName).future);
  final hiveArchive = openArchiveHive.requireValue.values;

  return jsonEncode({
    'api_key': apiKey,
    'services': [
      ...curState
          .where((s) => s.provDate.isAfter(start) && s.provDate.isBefore(end))
          .map((e) => e.toJson()),
      ...hiveArchive
          .where((s) => s.provDate.isAfter(start) && s.provDate.isBefore(end))
          .map((e) => e.toJson()),
    ],
  });
}