loadTasksWithRawQuery static method
Loads tasks from SQLite database using raw query
.
parameters:
query
: SQL statement. Note that the plugin will parse loaded data from database into DownloadTask object, in order to make it work, you should load tasks with all fields from database. In other words, usingSELECT *
statement.
Example:
FlutterDownloader.loadTasksWithRawQuery(
query: 'SELECT * FROM task WHERE status=3',
);
Implementation
static Future<List<DownloadTask>?> loadTasksWithRawQuery({
required String query,
}) async {
assert(_initialized, 'plugin flutter_downloader is not initialized');
try {
final result = await _channel.invokeMethod<List<dynamic>>(
'loadTasksWithRawQuery',
{'query': query},
);
if (result == null) {
throw const FlutterDownloaderException(
message: '`loadTasksWithRawQuery` 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 PlatformException catch (err) {
_log('Failed to loadTasksWithRawQuery. Reason: ${err.message}');
return null;
}
}