listBackups method

Future<List<String>> listBackups()

Implementation

Future<List<String>> listBackups() async {
  final tempDir = await getTemporaryDirectory();
  final List<String> backups = [];
  await for (final entity in tempDir.list()) {
    if (entity is File &&
        entity.path.contains('backup_') &&
        entity.path.endsWith('.json')) {
      backups.add(entity.path);
    }
  }
  backups.sort((a, b) => b.compareTo(a)); // Newest first
  return backups;
}