Skip to content

Commit 18632b5

Browse files
committed
feat: search filters in anime and manga page
1 parent 6f9b59b commit 18632b5

File tree

11 files changed

+577
-39
lines changed

11 files changed

+577
-39
lines changed

lib/Adaptor/Media/Widgets/Chips.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class ChipsWidget extends StatelessWidget {
4343
color: theme.onSurface,
4444
),
4545
),
46+
backgroundColor: chipData.isSelected
47+
? theme.primaryContainer
48+
: theme.surface,
4649
onPressed: chipData.action,
4750
shape: RoundedRectangleBorder(
4851
borderRadius:
@@ -65,9 +68,11 @@ class ChipsWidget extends StatelessWidget {
6568
class ChipData {
6669
final String label;
6770
final VoidCallback action;
71+
final bool isSelected;
6872

6973
ChipData({
7074
required this.label,
7175
required this.action,
76+
this.isSelected = false,
7277
});
7378
}

lib/DataClass/SearchResults.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SearchResults {
6767
List<SearchChip> toChipList() {
6868
final List<SearchChip> list = [];
6969
if (sort != null) {
70-
list.add(SearchChip("SORT", "Sort by: $sort"));
70+
list.add(SearchChip("SORT", "Sort: $sort"));
7171
}
7272
if (status != null) {
7373
list.add(SearchChip("STATUS", "Status: $status"));

lib/Screens/Detail/Tabs/Watch/BaseParser.dart

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:async/async.dart';
2+
import 'package:dantotsu/Functions/GetExtensions.dart';
23
import 'package:flutter/cupertino.dart';
3-
import 'package:flutter_riverpod/flutter_riverpod.dart' as r;
44
import 'package:fuzzywuzzy/fuzzywuzzy.dart';
55
import 'package:get/get.dart';
66
import 'package:provider/provider.dart';
@@ -12,7 +12,6 @@ import '../../../../Preferences/PrefManager.dart';
1212
import '../../../../Services/ServiceSwitcher.dart';
1313
import '../../../../Widgets/CustomBottomDialog.dart';
1414
import '../../../../api/Sources/Eval/dart/model/m_manga.dart';
15-
import '../../../../api/Sources/Extensions/extensions_provider.dart';
1615
import '../../../../api/Sources/Model/Manga.dart';
1716
import '../../../../api/Sources/Model/Source.dart';
1817
import '../../../../api/Sources/Search/search.dart';
@@ -29,24 +28,13 @@ abstract class BaseParser extends GetxController {
2928
var sourcesLoaded = false.obs;
3029

3130
void initSourceList(Media media) async {
32-
final container = r.ProviderContainer();
3331
var isAnime = media.anime != null;
3432
final itemType = isAnime
3533
? ItemType.anime
3634
: media.format?.toLowerCase() == 'novel'
3735
? ItemType.novel
3836
: ItemType.manga;
39-
var sources =
40-
await container.read(getExtensionsStreamProvider(itemType).future);
41-
var s =
42-
sources.where((source) => source.isAdded!).toList().reversed.toList();
43-
final ids =
44-
loadCustomData<List<int>?>('sortedExtensions_${itemType.name}') ?? [];
45-
final sortedSources = [
46-
...s.where((source) => ids.contains(source.id)).toList()
47-
..sort((a, b) => ids.indexOf(a.id!).compareTo(ids.indexOf(b.id!))),
48-
...s.where((source) => !ids.contains(source.id)),
49-
];
37+
final sortedSources = await Extensions.getSortedExtension(itemType);
5038
if (sortedSources.isEmpty) {
5139
sourcesLoaded.value = true;
5240
return;

lib/Screens/Search/SearchScreen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ class SearchScreenState extends State<SearchScreen> {
254254
}
255255

256256
screen.searchResults.value = screen.searchResults.value
257-
..search = value.isEmpty ? null : value
258-
..page = 1;
257+
..search = value.isEmpty ? null : value;
259258

260259
if (value.isNotEmpty ||
261260
screen.searchResults.value.toChipList().isNotEmpty) {

lib/Widgets/CustomBottomDialog.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class _CustomBottomDialogState extends State<CustomBottomDialog> {
124124
],
125125
if (widget.positiveText != null) ...[
126126
Expanded(
127-
child: ElevatedButton(
127+
child: OutlinedButton(
128128
onPressed: widget.positiveCallback,
129129
style: ElevatedButton.styleFrom(
130130
padding: const EdgeInsets.symmetric(vertical: 28.0),

lib/Widgets/CustomElevatedButton.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Widget CustomElevatedButton({
55
required VoidCallback? onPressed,
66
required String label,
77
Widget? iconWidget,
8+
EdgeInsetsGeometry? padding,
89
}) {
910
final theme = Theme.of(context);
1011

@@ -26,7 +27,7 @@ Widget CustomElevatedButton({
2627
),
2728
style: ElevatedButton.styleFrom(
2829
backgroundColor: Theme.of(context).primaryColor,
29-
padding: const EdgeInsets.only(
30+
padding: padding ?? const EdgeInsets.only(
3031
top: 16,
3132
bottom: 16,
3233
left: 28,

lib/Widgets/DropdownMenu.dart

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class buildDropdownMenu extends StatefulWidget {
1010
final double borderRadius;
1111
final EdgeInsetsGeometry? padding;
1212
final Color? borderColor;
13+
final String? hintText;
1314

1415
const buildDropdownMenu({
1516
super.key,
@@ -21,6 +22,7 @@ class buildDropdownMenu extends StatefulWidget {
2122
this.borderRadius = 8.0,
2223
this.padding,
2324
this.borderColor,
25+
this.hintText,
2426
});
2527

2628
@override
@@ -35,6 +37,20 @@ class buildDropdownMenuState extends State<buildDropdownMenu> {
3537
super.initState();
3638
_selectedValue = widget.currentValue;
3739
}
40+
@override
41+
void didUpdateWidget(covariant buildDropdownMenu oldWidget) {
42+
super.didUpdateWidget(oldWidget);
43+
if (oldWidget.currentValue != widget.currentValue) {
44+
setState(() {
45+
_selectedValue = widget.currentValue;
46+
});
47+
} else if (_selectedValue != widget.currentValue) {
48+
setState(() {
49+
_selectedValue = widget.currentValue;
50+
});
51+
}
52+
53+
}
3854

3955
@override
4056
Widget build(BuildContext context) {
@@ -59,7 +75,18 @@ class buildDropdownMenuState extends State<buildDropdownMenu> {
5975
child: DropdownButtonHideUnderline(
6076
child: DropdownButton(
6177
focusColor: Colors.transparent,
62-
value: _selectedValue,
78+
hint: Text(
79+
widget.hintText ?? '',
80+
style: TextStyle(
81+
fontFamily: 'Poppins',
82+
fontSize: 14,
83+
fontWeight: FontWeight.w700,
84+
),
85+
),
86+
isExpanded: true,
87+
value: widget.options?.contains(_selectedValue) == true
88+
? _selectedValue
89+
: null,
6390
onChanged: (String? newValue) {
6491
if (newValue != null) {
6592
setState(() {

lib/api/Anilist/Anilist.dart

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,45 @@ class AnilistController extends BaseServiceData {
4040
"TITLE_ENGLISH_DESC",
4141
"SCORE"
4242
];
43+
var source = [
44+
"ORIGINAL",
45+
"MANGA",
46+
"LIGHT NOVEL",
47+
"VISUAL NOVEL",
48+
"VIDEO GAME",
49+
"OTHER",
50+
"NOVEL",
51+
"DOUJINSHI",
52+
"ANIME",
53+
"WEB NOVEL",
54+
"LIVE ACTION",
55+
"GAME",
56+
"COMIC",
57+
"MULTIMEDIA PROJECT",
58+
"PICTURE BOOK"
59+
];
60+
61+
var animeStatus = ["FINISHED", "RELEASING", "NOT YET RELEASED", "CANCELLED"];
62+
63+
var mangaStatus = [
64+
"FINISHED",
65+
"RELEASING",
66+
"NOT YET RELEASED",
67+
"HIATUS",
68+
"CANCELLED"
69+
];
70+
71+
var animeFormats = [
72+
"TV",
73+
"TV SHORT",
74+
"MOVIE",
75+
"SPECIAL",
76+
"OVA",
77+
"ONA",
78+
"MUSIC"
79+
];
80+
81+
var mangaFormats = ["MANGA", "NOVEL", "ONE SHOT"];
4382

4483
final List<String> authorRoles = ["Original Creator", "Story & Art", "Story"];
4584
final List<String> seasons = ["WINTER", "SPRING", "SUMMER", "FALL"];
@@ -81,7 +120,7 @@ class AnilistController extends BaseServiceData {
81120
@override
82121
bool getSavedToken() {
83122
token.value = PrefManager.getVal(PrefName.anilistToken);
84-
123+
query?.getGenresAndTags();
85124
if (token.isNotEmpty) query?.getUserData();
86125

87126
return token.isNotEmpty;

lib/api/Anilist/AnilistQueries/Search.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ extension on AnilistQueries {
3737
"yearLesser": (searchResults.startYear! + 1) * 10000,
3838
if (searchResults.season != null) "season": searchResults.season,
3939
if (searchResults.search != null) "search": searchResults.search,
40-
if (searchResults.source != null) "source": searchResults.source,
40+
if (searchResults.source != null) "source": searchResults.source?.replaceAll(" ", "_"),
4141
if (searchResults.sort != null) "sort": searchResults.sort,
42-
if (searchResults.status != null) "status": searchResults.status,
42+
if (searchResults.status != null) "status": searchResults.status?.replaceAll(" ", "_"),
4343
if (searchResults.format != null)
4444
"format": searchResults.format?.replaceAll(" ", "_"),
4545
if (searchResults.countryOfOrigin != null)

0 commit comments

Comments
 (0)