Skip to content

Commit dc1916f

Browse files
Akshatji800jesec
authored andcommitted
feat: Adds filter torrent based on the completion status feature
1 parent a93fc1f commit dc1916f

File tree

4 files changed

+297
-9
lines changed

4 files changed

+297
-9
lines changed
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
import 'package:flood_mobile/Constants/theme_provider.dart';
2+
import 'package:flood_mobile/Pages/torrent_screen.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class FilterByStatus extends StatefulWidget {
6+
@override
7+
_FilterByStatusState createState() => _FilterByStatusState();
8+
}
9+
10+
enum FilterValue {
11+
all,
12+
downloading,
13+
seeding,
14+
complete,
15+
stopped,
16+
active,
17+
inactive
18+
}
19+
FilterValue? filterStatus = FilterValue.all;
20+
String trackerURISelected = '';
21+
22+
class _FilterByStatusState extends State<FilterByStatus> {
23+
@override
24+
void initState() {
25+
// TODO: implement initState
26+
super.initState();
27+
}
28+
29+
@override
30+
Widget build(BuildContext context) {
31+
return Container(
32+
decoration: BoxDecoration(
33+
borderRadius: BorderRadius.only(
34+
topRight: Radius.circular(15), topLeft: Radius.circular(15)),
35+
color: ThemeProvider.theme.primaryColorLight,
36+
),
37+
height: 500,
38+
padding: EdgeInsets.symmetric(vertical: 25, horizontal: 20),
39+
child: SingleChildScrollView(
40+
scrollDirection: Axis.vertical,
41+
child: Column(
42+
crossAxisAlignment: CrossAxisAlignment.start,
43+
mainAxisSize: MainAxisSize.min,
44+
children: <Widget>[
45+
Text("Filter by status",
46+
style: TextStyle(
47+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
48+
fontSize: 24,
49+
fontWeight: FontWeight.bold)),
50+
ListTile(
51+
title: Text('All',
52+
style: TextStyle(
53+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
54+
fontFamily: 'Montserrat',
55+
fontSize: 16,
56+
fontWeight: FontWeight.normal)),
57+
trailing: Radio<FilterValue>(
58+
value: FilterValue.all,
59+
groupValue: filterStatus,
60+
onChanged: (FilterValue? value) {
61+
setState(() {
62+
trackerURISelected = 'null';
63+
filterStatus = value;
64+
});
65+
},
66+
),
67+
),
68+
ListTile(
69+
title: Text('Downloading',
70+
style: TextStyle(
71+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
72+
fontFamily: 'Montserrat',
73+
fontSize: 16,
74+
fontWeight: FontWeight.normal)),
75+
trailing: Radio<FilterValue>(
76+
value: FilterValue.downloading,
77+
groupValue: filterStatus,
78+
onChanged: (FilterValue? value) {
79+
setState(() {
80+
trackerURISelected = 'null';
81+
filterStatus = value;
82+
});
83+
},
84+
),
85+
),
86+
ListTile(
87+
title: Text('Seeding',
88+
style: TextStyle(
89+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
90+
fontFamily: 'Montserrat',
91+
fontSize: 16,
92+
fontWeight: FontWeight.normal)),
93+
trailing: Radio<FilterValue>(
94+
value: FilterValue.seeding,
95+
groupValue: filterStatus,
96+
onChanged: (FilterValue? value) {
97+
setState(() {
98+
trackerURISelected = 'null';
99+
filterStatus = value;
100+
});
101+
},
102+
),
103+
),
104+
ListTile(
105+
title: Text('Complete',
106+
style: TextStyle(
107+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
108+
fontFamily: 'Montserrat',
109+
fontSize: 16,
110+
fontWeight: FontWeight.normal)),
111+
trailing: Radio<FilterValue>(
112+
value: FilterValue.complete,
113+
groupValue: filterStatus,
114+
onChanged: (FilterValue? value) {
115+
setState(() {
116+
trackerURISelected = 'null';
117+
filterStatus = value;
118+
});
119+
},
120+
),
121+
),
122+
ListTile(
123+
title: Text('Stopped',
124+
style: TextStyle(
125+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
126+
fontFamily: 'Montserrat',
127+
fontSize: 16,
128+
fontWeight: FontWeight.normal)),
129+
trailing: Radio<FilterValue>(
130+
value: FilterValue.stopped,
131+
groupValue: filterStatus,
132+
onChanged: (FilterValue? value) {
133+
setState(() {
134+
trackerURISelected = 'null';
135+
filterStatus = value;
136+
});
137+
},
138+
),
139+
),
140+
ListTile(
141+
title: Text('Active',
142+
style: TextStyle(
143+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
144+
fontFamily: 'Montserrat',
145+
fontSize: 16,
146+
fontWeight: FontWeight.normal)),
147+
trailing: Radio<FilterValue>(
148+
value: FilterValue.active,
149+
groupValue: filterStatus,
150+
onChanged: (FilterValue? value) {
151+
setState(() {
152+
trackerURISelected = 'null';
153+
filterStatus = value;
154+
});
155+
},
156+
),
157+
),
158+
ListTile(
159+
title: Text('Inactive',
160+
style: TextStyle(
161+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
162+
fontFamily: 'Montserrat',
163+
fontSize: 16,
164+
fontWeight: FontWeight.normal)),
165+
trailing: Radio<FilterValue>(
166+
value: FilterValue.inactive,
167+
groupValue: filterStatus,
168+
onChanged: (FilterValue? value) {
169+
setState(() {
170+
trackerURISelected = 'null';
171+
filterStatus = value;
172+
});
173+
},
174+
),
175+
),
176+
SizedBox(
177+
height: 20,
178+
),
179+
Text("Filter by trackers",
180+
style: TextStyle(
181+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
182+
fontSize: 24,
183+
fontWeight: FontWeight.bold)),
184+
ListTile(
185+
title: Text('All',
186+
style: TextStyle(
187+
color: ThemeProvider.theme.textTheme.bodyText1?.color,
188+
fontFamily: 'Montserrat',
189+
fontSize: 16,
190+
fontWeight: FontWeight.normal)),
191+
trailing: Radio<FilterValue>(
192+
value: FilterValue.all,
193+
groupValue: filterStatus,
194+
onChanged: (FilterValue? value) {
195+
setState(() {
196+
trackerURISelected = 'null';
197+
filterStatus = value;
198+
});
199+
},
200+
),
201+
),
202+
ListView.builder(
203+
shrinkWrap: true,
204+
physics: NeverScrollableScrollPhysics(),
205+
itemCount: trackerURIsList.length,
206+
itemBuilder: (BuildContext context, int index) {
207+
return ListTile(
208+
title: Text(trackerURIsList[index].toString(),
209+
style: TextStyle(
210+
color:
211+
ThemeProvider.theme.textTheme.bodyText1?.color,
212+
fontFamily: 'Montserrat',
213+
fontSize: 16,
214+
fontWeight: FontWeight.normal)),
215+
trailing: Radio<String>(
216+
value: trackerURIsList[index].toString(),
217+
groupValue: trackerURISelected,
218+
onChanged: (value) {
219+
print(value);
220+
setState(() {
221+
filterStatus = null;
222+
trackerURISelected = value.toString();
223+
});
224+
},
225+
),
226+
);
227+
}),
228+
],
229+
),
230+
),
231+
);
232+
}
233+
}

lib/Pages/torrent_screen.dart

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flood_mobile/Components/add_torrent_sheet.dart';
2+
import 'package:flood_mobile/Components/filter_by_status.dart';
23
import 'package:flood_mobile/Components/torrent_tile.dart';
34
import 'package:flood_mobile/Constants/theme_provider.dart';
45
import 'package:flood_mobile/Provider/client_provider.dart';
@@ -14,6 +15,8 @@ class TorrentScreen extends StatefulWidget {
1415
_TorrentScreenState createState() => _TorrentScreenState();
1516
}
1617

18+
List<String> trackerURIsList = [];
19+
1720
class _TorrentScreenState extends State<TorrentScreen> {
1821
String keyword = '';
1922

@@ -35,10 +38,27 @@ class _TorrentScreenState extends State<TorrentScreen> {
3538
? PullToRevealTopItemList(
3639
itemCount: model.torrentList.length,
3740
itemBuilder: (BuildContext context, int index) {
41+
trackerURIsList =
42+
model.torrentList[index].trackerURIs;
3843
if (model.torrentList[index].name
39-
.toLowerCase()
40-
.contains(keyword.toLowerCase())) {
41-
return TorrentTile(model: model.torrentList[index]);
44+
.toLowerCase()
45+
.contains(keyword.toLowerCase()) &&
46+
model.torrentList[index].status.contains(
47+
filterStatus
48+
.toString()
49+
.split(".")
50+
.last) ||
51+
model.torrentList[index].trackerURIs
52+
.toString()
53+
.contains(trackerURISelected) ||
54+
filterStatus.toString().split(".").last ==
55+
"all") {
56+
if (model.torrentList[index].name
57+
.toLowerCase()
58+
.contains(keyword.toLowerCase())) {
59+
return TorrentTile(
60+
model: model.torrentList[index]);
61+
}
4262
}
4363
return Container();
4464
},
@@ -118,6 +138,42 @@ class _TorrentScreenState extends State<TorrentScreen> {
118138
contentPadding: EdgeInsets.symmetric(
119139
horizontal: 20, vertical: 20),
120140
hintText: 'Search Torrent',
141+
suffixIcon: Padding(
142+
padding: const EdgeInsets.all(5.0),
143+
child: Container(
144+
decoration: BoxDecoration(
145+
color: Colors.green,
146+
borderRadius:
147+
BorderRadius.circular(5),
148+
),
149+
child: IconButton(
150+
icon: Icon(
151+
Icons.filter_list_alt,
152+
color: Colors.white,
153+
),
154+
onPressed: () {
155+
showModalBottomSheet(
156+
shape: RoundedRectangleBorder(
157+
borderRadius:
158+
BorderRadius.only(
159+
topRight:
160+
Radius.circular(15),
161+
topLeft:
162+
Radius.circular(15),
163+
),
164+
),
165+
isScrollControlled: true,
166+
context: context,
167+
backgroundColor: ThemeProvider
168+
.theme.backgroundColor,
169+
builder: (context) {
170+
return FilterByStatus();
171+
},
172+
);
173+
},
174+
),
175+
),
176+
),
121177
border: OutlineInputBorder(
122178
borderRadius: BorderRadius.circular(8),
123179
),

lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:flutter/services.dart';
99
import 'package:flutter_downloader/flutter_downloader.dart';
1010
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
1111
import 'package:provider/provider.dart';
12-
1312
import 'Route/route_generator.dart';
1413
import 'Route/routes.dart';
1514

pubspec.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ packages:
2828
name: async
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "2.8.2"
31+
version: "2.8.1"
3232
badges:
3333
dependency: "direct main"
3434
description:
@@ -105,7 +105,7 @@ packages:
105105
name: characters
106106
url: "https://pub.dartlang.org"
107107
source: hosted
108-
version: "1.2.0"
108+
version: "1.1.0"
109109
charcode:
110110
dependency: transitive
111111
description:
@@ -456,7 +456,7 @@ packages:
456456
name: matcher
457457
url: "https://pub.dartlang.org"
458458
source: hosted
459-
version: "0.12.11"
459+
version: "0.12.10"
460460
meta:
461461
dependency: "direct overridden"
462462
description:
@@ -755,7 +755,7 @@ packages:
755755
name: test_api
756756
url: "https://pub.dartlang.org"
757757
source: hosted
758-
version: "0.4.3"
758+
version: "0.4.2"
759759
timing:
760760
dependency: transitive
761761
description:
@@ -818,7 +818,7 @@ packages:
818818
name: vector_math
819819
url: "https://pub.dartlang.org"
820820
source: hosted
821-
version: "2.1.1"
821+
version: "2.1.0"
822822
video_player:
823823
dependency: "direct main"
824824
description:

0 commit comments

Comments
 (0)