loadTasks static method

Future<List<DownloadTask>?> loadTasks()

Loads all tasks from SQLite database.

Implementation

static Future<List<DownloadTask>?> loadTasks() async {
  assert(_initialized, 'plugin flutter_downloader is not initialized');

  try {
    final result = await _channel.invokeMethod<List<dynamic>>('loadTasks');

    if (result == null) {
      throw const FlutterDownloaderException(
        message: '`loadTasks` returned null',
      );
    }

    return result.map(
      (dynamic item) {
        return DownloadTask(
          taskId: item['task_id'] as String,
          status: DownloadTaskStatus.fromInt(item['status'] as int),
          progress: item['progress'] as int,
          url: item['url'] as String,
          filename: item['file_name'] as String?,
          savedDir: item['saved_dir'] as String,
          timeCreated: item['time_created'] as int,

          // allowCellular field is true by default (similar to enqueue())
          allowCellular: (item['allow_cellular'] as bool?) ?? true,
        );
      },
    ).toList();
  } on FlutterDownloaderException catch (err) {
    _log('Failed to load tasks. Reason: ${err.message}');
  } on PlatformException catch (err) {
    _log(err.message);
    return null;
  }
  return null;
}