Skip to content

Commit a0bf3e2

Browse files
committed
feat: search for staff,studio,character
1 parent 9d4a87f commit a0bf3e2

File tree

21 files changed

+741
-84
lines changed

21 files changed

+741
-84
lines changed

lib/Adaptor/Charactes/EntityAdaptor.dart

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,33 @@ import 'package:dantotsu/Functions/Function.dart';
33
import 'package:dantotsu/Screens/Character/CharacterScreen.dart';
44
import 'package:dantotsu/Screens/Staff/StaffScreen.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
67

78
import '../../Animation/ScaleAnimation.dart';
89
import '../../DataClass/Author.dart';
910
import '../../DataClass/Character.dart';
11+
import '../../DataClass/Studio.dart';
1012
import '../../Widgets/ScrollConfig.dart';
1113
import 'CharacterViewHolder.dart';
1214
import 'Widgets/EntitySection.dart';
1315

1416
class EntityAdaptor extends StatefulWidget {
1517
final EntityType type;
18+
19+
final int? adaptorType;
1620
final List<character>? characterList;
1721
final List<author>? staffList;
1822

19-
const EntityAdaptor(
20-
{super.key, required this.type, this.characterList, this.staffList});
23+
final List<studio>? studioList;
24+
25+
const EntityAdaptor({
26+
super.key,
27+
required this.type,
28+
this.characterList,
29+
this.staffList,
30+
this.adaptorType,
31+
this.studioList,
32+
});
2133

2234
@override
2335
EntityAdaptorState createState() => EntityAdaptorState();
@@ -26,17 +38,71 @@ class EntityAdaptor extends StatefulWidget {
2638
class EntityAdaptorState extends State<EntityAdaptor> {
2739
@override
2840
Widget build(BuildContext context) {
29-
return _buildCharacterLayout(widget.characterList, widget.staffList);
41+
switch (widget.adaptorType) {
42+
case 1:
43+
return _buildCharacterLayout(
44+
widget.characterList, widget.staffList, widget.studioList);
45+
case 2:
46+
return _buildStaggeredGrid(
47+
widget.characterList, widget.staffList, widget.studioList);
48+
default:
49+
return _buildCharacterLayout(
50+
widget.characterList, widget.staffList, widget.studioList);
51+
}
52+
}
53+
54+
Widget _buildStaggeredGrid(
55+
final List<character>? characterList,
56+
final List<author>? staffList,
57+
final List<studio>? studioList,
58+
) {
59+
var listType = widget.type;
60+
var length = listType == EntityType.Character
61+
? characterList!.length : listType == EntityType.Staff ? staffList!.length
62+
: studioList!.length;
63+
return LayoutBuilder(
64+
builder: (context, constraints) {
65+
final parentWidth = constraints.maxWidth;
66+
var crossAxisCount = (parentWidth / 124).floor();
67+
if (crossAxisCount < 1) crossAxisCount = 1;
68+
return Padding(
69+
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0),
70+
child: StaggeredGrid.count(
71+
crossAxisSpacing: 16,
72+
crossAxisCount: crossAxisCount,
73+
children: List.generate(
74+
length,
75+
(index) {
76+
return GestureDetector(
77+
onTap: () => onClick(listType, index),
78+
onLongPress: () {},
79+
child: SizedBox(
80+
width: 102,
81+
height: 212,
82+
child: listType == EntityType.Character
83+
? CharacterViewHolder(charInfo: characterList![index])
84+
: listType == EntityType.Staff
85+
? StaffViewHolder(staffInfo: staffList![index])
86+
: StudioViewHolder(studioInfo: studioList![index]),
87+
),
88+
);
89+
},
90+
),
91+
),
92+
);
93+
},
94+
);
3095
}
3196

3297
Widget _buildCharacterLayout(
3398
final List<character>? characterList,
3499
final List<author>? staffList,
100+
final List<studio>? studioList,
35101
) {
36102
var listType = widget.type;
37103
var length = listType == EntityType.Character
38-
? characterList!.length
39-
: staffList!.length;
104+
? characterList!.length : listType == EntityType.Staff ? staffList!.length
105+
: studioList!.length;
40106
return SizedBox(
41107
height: 212,
42108
child: AnimatedSwitcher(
@@ -60,17 +126,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
60126
finalOffset: Offset.zero,
61127
duration: const Duration(milliseconds: 200),
62128
child: GestureDetector(
63-
onTap: () => listType == EntityType.Character
64-
? navigateToPage(context,
65-
CharacterScreen(characterInfo: characterList![index]))
66-
: navigateToPage(
67-
context, StaffScreen(staffInfo: staffList![index])),
129+
onTap: () => onClick(listType, index),
68130
child: Container(
69131
width: 102,
70132
margin: margin,
71133
child: listType == EntityType.Character
72134
? CharacterViewHolder(charInfo: characterList![index])
73-
: StaffViewHolder(staffInfo: staffList![index]),
135+
: listType == EntityType.Staff
136+
? StaffViewHolder(staffInfo: staffList![index])
137+
: StudioViewHolder(studioInfo: studioList![index]),
74138
),
75139
),
76140
);
@@ -80,4 +144,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
80144
),
81145
);
82146
}
147+
148+
void onClick(EntityType type, int index) {
149+
if (type == EntityType.Character) {
150+
navigateToPage(context,
151+
CharacterScreen(characterInfo: widget.characterList![index]));
152+
} else if (type == EntityType.Staff) {
153+
navigateToPage(context, StaffScreen(staffInfo: widget.staffList![index]));
154+
} else {
155+
navigateToPage(context, StudioScreen(studioInfo: widget.studioList![index]));
156+
}
157+
}
83158
}

lib/Adaptor/Charactes/StaffViewHolder.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:dantotsu/DataClass/Author.dart';
22
import 'package:flutter/material.dart';
33

4+
import '../../DataClass/Studio.dart';
45
import '../../Widgets/CachedNetworkImage.dart';
56

67
class StaffViewHolder extends StatelessWidget {
@@ -59,3 +60,43 @@ class StaffViewHolder extends StatelessWidget {
5960
);
6061
}
6162
}
63+
class StudioViewHolder extends StatelessWidget {
64+
final studio studioInfo;
65+
66+
const StudioViewHolder({super.key, required this.studioInfo});
67+
68+
@override
69+
Widget build(BuildContext context) {
70+
final theme = Theme.of(context).colorScheme;
71+
return Column(
72+
mainAxisSize: MainAxisSize.min,
73+
crossAxisAlignment: CrossAxisAlignment.start,
74+
children: [
75+
ClipRRect(
76+
borderRadius: BorderRadius.circular(16.0),
77+
child: cachedNetworkImage(
78+
imageUrl: studioInfo.imageUrl ?? '',
79+
fit: BoxFit.cover,
80+
width: 108,
81+
height: 160,
82+
placeholder: (context, url) => Container(
83+
color: Colors.white12,
84+
width: 108,
85+
height: 160,
86+
),
87+
),
88+
),
89+
Text(
90+
studioInfo.name ?? "",
91+
overflow: TextOverflow.ellipsis,
92+
style: TextStyle(
93+
fontFamily: 'Poppins',
94+
fontSize: 14,
95+
color: theme.onSurface,
96+
),
97+
maxLines: 2,
98+
),
99+
],
100+
);
101+
}
102+
}

lib/Adaptor/Charactes/Widgets/EntitySection.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:dantotsu/DataClass/Studio.dart';
12
import 'package:flutter/material.dart';
23

34
import '../../../../DataClass/Character.dart';
@@ -8,12 +9,14 @@ Widget entitySection({
89
required BuildContext context,
910
required EntityType type,
1011
required String title,
12+
int adaptorType = 1,
1113
List<character>? characterList,
1214
List<author>? staffList,
15+
List<studio>? studioList,
1316
List<Widget>? customNullListIndicator,
1417
}) {
1518
var theme = Theme.of(context);
16-
var list = type == EntityType.Character ? characterList : staffList;
19+
var list = type == EntityType.Character ? characterList : type == EntityType.Staff ? staffList : studioList;
1720
return Column(
1821
crossAxisAlignment: CrossAxisAlignment.start,
1922
children: [
@@ -83,7 +86,8 @@ Widget entitySection({
8386
type: type,
8487
characterList: characterList,
8588
staffList: staffList,
86-
// Pass the callback here
89+
studioList: studioList,
90+
adaptorType: adaptorType,
8791
),
8892
),
8993
],
@@ -95,4 +99,5 @@ Widget entitySection({
9599
enum EntityType {
96100
Character,
97101
Staff,
102+
Studio,
98103
}

lib/DataClass/Data/SearchResults.g.dart

Lines changed: 37 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/DataClass/SearchResults.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import 'package:json_annotation/json_annotation.dart';
22

3+
import 'Author.dart';
4+
import 'Character.dart';
35
import 'Media.dart';
6+
import 'Studio.dart';
7+
import 'User.dart';
48

59
part 'Data/SearchResults.g.dart';
610

711
@JsonSerializable()
812
class SearchResults {
9-
String type;
13+
SearchType type;
1014
bool? isAdult;
1115
bool? onList;
1216
int? perPage;
@@ -25,11 +29,15 @@ class SearchResults {
2529
String? season;
2630
int? page;
2731
List<Media>? results;
32+
List<character>? characters;
33+
List<author>? staff;
34+
List<userData>? users;
35+
List<studio>? studios;
2836
bool? hasNextPage;
2937
int? id;
3038
bool? hdCover;
3139
SearchResults({
32-
this.type = "ANIME",
40+
this.type = SearchType.ANIME,
3341
this.isAdult,
3442
this.onList,
3543
this.perPage,
@@ -48,6 +56,9 @@ class SearchResults {
4856
this.season,
4957
this.page = 1,
5058
this.results = const [],
59+
this.characters = const [],
60+
this.staff = const [],
61+
this.users = const [],
5162
this.hasNextPage = false,
5263
this.hdCover,
5364
this.id,
@@ -147,3 +158,5 @@ class SearchChip {
147158

148159
SearchChip(this.type, this.text);
149160
}
161+
162+
enum SearchType { ANIME, MANGA, CHARACTER, STAFF, STUDIO, USER }

lib/DataClass/Studio.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
import 'Media.dart';
3+
4+
class studio {
5+
int id;
6+
String? name;
7+
bool? isAnimationStudio;
8+
String? siteUrl;
9+
Map<String, List<Media>>? media;
10+
bool? isFavourite;
11+
int? favourites;
12+
String? imageUrl;
13+
14+
studio({
15+
required this.id,
16+
this.name,
17+
this.isAnimationStudio,
18+
this.siteUrl,
19+
this.media,
20+
this.isFavourite,
21+
this.favourites,
22+
this.imageUrl,
23+
});
24+
25+
}

lib/DataClass/User.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class userData {
88
final String name;
99
final String? pfp;
1010
final String? banner;
11+
// for media info page
1112
final String? status;
1213
final double? score;
1314
final int? progress;

0 commit comments

Comments
 (0)