getTorrents method Null safety

Future<List<Torrent>> getTorrents(
  1. {List<String> fields = const ['id', 'name', 'eta', 'queuePosition', 'downloadDir', 'isFinished', 'isStalled', 'leftUntilDone', 'metadataPercentComplete', 'error', 'errorString', 'percentDone', 'totalSize', 'peersConnected', 'sizeWhenDone', 'status', 'rateDownload', 'rateUpload', 'peersGettingFromUs', 'peersSendingToUs']}
)

Get the list of torrents, fields can be provided to get only needed information fields to retrieve, can be checked at https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt Returns list of Torrent currently in transmission instance Throws TransmissionException if errors

Implementation

Future<List<Torrent>> getTorrents({
  List<String> fields = const [
    'id',
    'name',
    'eta',
    'queuePosition',
    'downloadDir',
    'isFinished',
    'isStalled',
    'leftUntilDone',
    'metadataPercentComplete',
    'error',
    'errorString',
    'percentDone',
    'totalSize',
    'peersConnected',
    'sizeWhenDone',
    'status',
    'rateDownload',
    'rateUpload',
    'peersGettingFromUs',
    'peersSendingToUs',
  ],
}) async {
  final results = await _dio.post('/',
      data: _Request(methodGetTorrent, arguments: {
        'fields': fields,
      }).toJSON());
  final response = _Response.fromJSON(results.data);
  _checkResults(response);
  final torrentsData = response.arguments!['torrents'];
  return torrentsData
      .map((data) => Torrent._(data))
      .cast<Torrent>()
      .toList(growable: false);
}