Skip to content

Commit 1774052

Browse files
committed
implement multiple select torrent feature
1 parent f48a7c9 commit 1774052

File tree

6 files changed

+698
-470
lines changed

6 files changed

+698
-470
lines changed

lib/Api/torrent_api.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class TorrentApi {
194194
}
195195

196196
static Future<void> deleteTorrent({
197-
required String hash,
197+
required List<String> hashes,
198198
required bool deleteWithData,
199199
required BuildContext context,
200200
}) async {
@@ -212,7 +212,7 @@ class TorrentApi {
212212
dio.options.headers['Cookie'] =
213213
Provider.of<UserDetailProvider>(context, listen: false).token;
214214
Map<String, dynamic> mp = Map();
215-
mp['hashes'] = [hash];
215+
mp['hashes'] = hashes;
216216
mp['deleteData'] = deleteWithData;
217217
String rawBody = json.encode(mp);
218218
print(rawBody);

lib/Components/delete_torrent_sheet.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import 'package:flutter/material.dart';
66
import 'flood_snackbar.dart';
77

88
class DeleteTorrentSheet extends StatefulWidget {
9-
final TorrentModel torrent;
9+
final List<TorrentModel> torrents;
1010

11-
DeleteTorrentSheet({required this.torrent});
11+
DeleteTorrentSheet({required this.torrents});
1212

1313
@override
1414
_DeleteTorrentSheetState createState() => _DeleteTorrentSheetState();
@@ -36,7 +36,9 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
3636
height: 5,
3737
),
3838
Text(
39-
'Are you sure you want to delete the torrent?',
39+
widget.torrents.length > 1
40+
? 'Are you sure you want to delete ${widget.torrents.length} torrents?'
41+
: 'Are you sure you want to delete the torrent?',
4042
style: TextStyle(fontSize: 16),
4143
),
4244
SizedBox(
@@ -108,8 +110,12 @@ class _DeleteTorrentSheetState extends State<DeleteTorrentSheet> {
108110
),
109111
child: ElevatedButton(
110112
onPressed: () {
113+
List<String> hashes = [];
114+
widget.torrents.forEach((element) {
115+
hashes.add(element.hash);
116+
});
111117
TorrentApi.deleteTorrent(
112-
hash: widget.torrent.hash,
118+
hashes: hashes,
113119
deleteWithData: deleteWithData,
114120
context: context);
115121
Navigator.of(context).pop();

0 commit comments

Comments
 (0)