Skip to content

Commit 6f9b59b

Browse files
committed
feat: search for users
1 parent a0bf3e2 commit 6f9b59b

File tree

9 files changed

+484
-96
lines changed

9 files changed

+484
-96
lines changed

lib/Adaptor/Charactes/EntityAdaptor.dart

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@ import 'Widgets/EntitySection.dart';
1515

1616
class EntityAdaptor extends StatefulWidget {
1717
final EntityType type;
18-
1918
final int? adaptorType;
20-
final List<character>? characterList;
21-
final List<author>? staffList;
22-
23-
final List<studio>? studioList;
19+
final List<Object> list;
2420

2521
const EntityAdaptor({
2622
super.key,
23+
this.adaptorType = 1,
2724
required this.type,
28-
this.characterList,
29-
this.staffList,
30-
this.adaptorType,
31-
this.studioList,
25+
required this.list,
3226
});
3327

3428
@override
@@ -40,26 +34,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
4034
Widget build(BuildContext context) {
4135
switch (widget.adaptorType) {
4236
case 1:
43-
return _buildCharacterLayout(
44-
widget.characterList, widget.staffList, widget.studioList);
37+
return _buildCharacterLayout();
4538
case 2:
46-
return _buildStaggeredGrid(
47-
widget.characterList, widget.staffList, widget.studioList);
39+
return _buildStaggeredGrid();
4840
default:
49-
return _buildCharacterLayout(
50-
widget.characterList, widget.staffList, widget.studioList);
41+
return _buildCharacterLayout();
5142
}
5243
}
5344

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;
45+
Widget _buildStaggeredGrid() {
6346
return LayoutBuilder(
6447
builder: (context, constraints) {
6548
final parentWidth = constraints.maxWidth;
@@ -71,19 +54,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
7154
crossAxisSpacing: 16,
7255
crossAxisCount: crossAxisCount,
7356
children: List.generate(
74-
length,
57+
widget.list.length,
7558
(index) {
7659
return GestureDetector(
77-
onTap: () => onClick(listType, index),
60+
onTap: () => onClick(index),
7861
onLongPress: () {},
7962
child: SizedBox(
8063
width: 102,
8164
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]),
65+
child: _buildHolder(index),
8766
),
8867
);
8968
},
@@ -94,15 +73,7 @@ class EntityAdaptorState extends State<EntityAdaptor> {
9473
);
9574
}
9675

97-
Widget _buildCharacterLayout(
98-
final List<character>? characterList,
99-
final List<author>? staffList,
100-
final List<studio>? studioList,
101-
) {
102-
var listType = widget.type;
103-
var length = listType == EntityType.Character
104-
? characterList!.length : listType == EntityType.Staff ? staffList!.length
105-
: studioList!.length;
76+
Widget _buildCharacterLayout() {
10677
return SizedBox(
10778
height: 212,
10879
child: AnimatedSwitcher(
@@ -111,10 +82,10 @@ class EntityAdaptorState extends State<EntityAdaptor> {
11182
context,
11283
child: ListView.builder(
11384
scrollDirection: Axis.horizontal,
114-
itemCount: length,
85+
itemCount: widget.list.length,
11586
itemBuilder: (context, index) {
11687
final isFirst = index == 0;
117-
final isLast = index == length - 1;
88+
final isLast = index == widget.list.length - 1;
11889
final margin = EdgeInsets.only(
11990
left: isFirst ? 24.0 : 6.5,
12091
right: isLast ? 24.0 : 6.5,
@@ -126,15 +97,11 @@ class EntityAdaptorState extends State<EntityAdaptor> {
12697
finalOffset: Offset.zero,
12798
duration: const Duration(milliseconds: 200),
12899
child: GestureDetector(
129-
onTap: () => onClick(listType, index),
100+
onTap: () => onClick(index),
130101
child: Container(
131102
width: 102,
132103
margin: margin,
133-
child: listType == EntityType.Character
134-
? CharacterViewHolder(charInfo: characterList![index])
135-
: listType == EntityType.Staff
136-
? StaffViewHolder(staffInfo: staffList![index])
137-
: StudioViewHolder(studioInfo: studioList![index]),
104+
child: _buildHolder(index),
138105
),
139106
),
140107
);
@@ -145,14 +112,34 @@ class EntityAdaptorState extends State<EntityAdaptor> {
145112
);
146113
}
147114

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]));
115+
Widget _buildHolder(int index) {
116+
return widget.type == EntityType.Character
117+
? CharacterViewHolder(
118+
charInfo: widget.list.whereType<character>().toList()[index])
119+
: widget.type == EntityType.Staff
120+
? StaffViewHolder(
121+
staffInfo: widget.list.whereType<author>().toList()[index])
122+
: StudioViewHolder(
123+
studioInfo: widget.list.whereType<studio>().toList()[index]);
124+
}
125+
126+
void onClick(int index) {
127+
if (widget.type == EntityType.Character) {
128+
navigateToPage(
129+
context,
130+
CharacterScreen(
131+
characterInfo:
132+
widget.list.whereType<character>().toList()[index]));
133+
} else if (widget.type == EntityType.Staff) {
134+
navigateToPage(
135+
context,
136+
StaffScreen(
137+
staffInfo: widget.list.whereType<author>().toList()[index]));
154138
} else {
155-
navigateToPage(context, StudioScreen(studioInfo: widget.studioList![index]));
139+
navigateToPage(
140+
context,
141+
StudioScreen(
142+
studioInfo: widget.list.whereType<studio>().toList()[index]));
156143
}
157144
}
158145
}

lib/Adaptor/Charactes/Widgets/EntitySection.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
import 'package:dantotsu/DataClass/Studio.dart';
21
import 'package:flutter/material.dart';
3-
4-
import '../../../../DataClass/Character.dart';
5-
import '../../../DataClass/Author.dart';
62
import '../EntityAdaptor.dart';
73

84
Widget entitySection({
95
required BuildContext context,
106
required EntityType type,
117
required String title,
128
int adaptorType = 1,
13-
List<character>? characterList,
14-
List<author>? staffList,
15-
List<studio>? studioList,
9+
List<Object>? list,
1610
List<Widget>? customNullListIndicator,
1711
}) {
1812
var theme = Theme.of(context);
19-
var list = type == EntityType.Character ? characterList : type == EntityType.Staff ? staffList : studioList;
2013
return Column(
2114
crossAxisAlignment: CrossAxisAlignment.start,
2215
children: [
@@ -84,10 +77,8 @@ Widget entitySection({
8477
)
8578
: EntityAdaptor(
8679
type: type,
87-
characterList: characterList,
88-
staffList: staffList,
89-
studioList: studioList,
9080
adaptorType: adaptorType,
81+
list: list,
9182
),
9283
),
9384
],

lib/Adaptor/User/UserAdaptor.dart

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import 'dart:math';
2+
3+
import 'package:dantotsu/DataClass/User.dart';
4+
import 'package:dantotsu/Functions/Function.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
7+
8+
import '../../Widgets/ScrollConfig.dart';
9+
import 'UserLargeViewHolder.dart';
10+
import 'UserViewHolder.dart';
11+
12+
class UserAdaptor extends StatefulWidget {
13+
final int type;
14+
final List<userData> list;
15+
16+
const UserAdaptor({
17+
super.key,
18+
required this.type,
19+
required this.list,
20+
});
21+
22+
@override
23+
UserAdaptorState createState() => UserAdaptorState();
24+
}
25+
26+
class UserAdaptorState extends State<UserAdaptor> {
27+
@override
28+
Widget build(BuildContext context) {
29+
switch (widget.type) {
30+
case 1:
31+
return _buildVerticalList();
32+
case 2:
33+
return _buildStaggeredGrid();
34+
default:
35+
return _buildVerticalList();
36+
}
37+
}
38+
39+
String _generateTag(int index) =>
40+
'${widget.list[index].id}${Random().nextInt(100000)}';
41+
42+
Widget _buildStaggeredGrid() {
43+
return LayoutBuilder(
44+
builder: (context, constraints) {
45+
final parentWidth = constraints.maxWidth;
46+
var crossAxisCount = (parentWidth / 124).floor();
47+
if (crossAxisCount < 1) crossAxisCount = 1;
48+
return Padding(
49+
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0),
50+
child: StaggeredGrid.count(
51+
crossAxisSpacing: 16,
52+
crossAxisCount: crossAxisCount,
53+
children: List.generate(
54+
widget.list.length,
55+
(index) {
56+
return GestureDetector(
57+
onTap: () => onClick(index),
58+
onLongPress: () {},
59+
child: SizedBox(
60+
width: 102,
61+
height: 150,
62+
child: UserViewHolder(user: widget.list[index]),
63+
),
64+
);
65+
},
66+
),
67+
),
68+
);
69+
},
70+
);
71+
}
72+
73+
void onClick(int index) {
74+
snackString("not implemented yet");
75+
}
76+
77+
Widget _buildVerticalList() {
78+
return ScrollConfig(
79+
context,
80+
child: ListView.builder(
81+
shrinkWrap: true,
82+
physics: const NeverScrollableScrollPhysics(),
83+
itemCount: widget.list.length,
84+
itemBuilder: (context, index) {
85+
return Container(
86+
margin: const EdgeInsets.symmetric(horizontal: 18, vertical: 4),
87+
child: GestureDetector(
88+
onTap: () => onClick(index),
89+
child: UserLargeViewHolder(
90+
user: widget.list[index],
91+
tag: _generateTag(index),
92+
),
93+
),
94+
);
95+
},
96+
),
97+
);
98+
}
99+
}

0 commit comments

Comments
 (0)