@@ -15,20 +15,14 @@ import 'Widgets/EntitySection.dart';
15
15
16
16
class EntityAdaptor extends StatefulWidget {
17
17
final EntityType type;
18
-
19
18
final int ? adaptorType;
20
- final List <character>? characterList;
21
- final List <author>? staffList;
22
-
23
- final List <studio>? studioList;
19
+ final List <Object > list;
24
20
25
21
const EntityAdaptor ({
26
22
super .key,
23
+ this .adaptorType = 1 ,
27
24
required this .type,
28
- this .characterList,
29
- this .staffList,
30
- this .adaptorType,
31
- this .studioList,
25
+ required this .list,
32
26
});
33
27
34
28
@override
@@ -40,26 +34,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
40
34
Widget build (BuildContext context) {
41
35
switch (widget.adaptorType) {
42
36
case 1 :
43
- return _buildCharacterLayout (
44
- widget.characterList, widget.staffList, widget.studioList);
37
+ return _buildCharacterLayout ();
45
38
case 2 :
46
- return _buildStaggeredGrid (
47
- widget.characterList, widget.staffList, widget.studioList);
39
+ return _buildStaggeredGrid ();
48
40
default :
49
- return _buildCharacterLayout (
50
- widget.characterList, widget.staffList, widget.studioList);
41
+ return _buildCharacterLayout ();
51
42
}
52
43
}
53
44
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 () {
63
46
return LayoutBuilder (
64
47
builder: (context, constraints) {
65
48
final parentWidth = constraints.maxWidth;
@@ -71,19 +54,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
71
54
crossAxisSpacing: 16 ,
72
55
crossAxisCount: crossAxisCount,
73
56
children: List .generate (
74
- length,
57
+ widget.list. length,
75
58
(index) {
76
59
return GestureDetector (
77
- onTap: () => onClick (listType, index),
60
+ onTap: () => onClick (index),
78
61
onLongPress: () {},
79
62
child: SizedBox (
80
63
width: 102 ,
81
64
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),
87
66
),
88
67
);
89
68
},
@@ -94,15 +73,7 @@ class EntityAdaptorState extends State<EntityAdaptor> {
94
73
);
95
74
}
96
75
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 () {
106
77
return SizedBox (
107
78
height: 212 ,
108
79
child: AnimatedSwitcher (
@@ -111,10 +82,10 @@ class EntityAdaptorState extends State<EntityAdaptor> {
111
82
context,
112
83
child: ListView .builder (
113
84
scrollDirection: Axis .horizontal,
114
- itemCount: length,
85
+ itemCount: widget.list. length,
115
86
itemBuilder: (context, index) {
116
87
final isFirst = index == 0 ;
117
- final isLast = index == length - 1 ;
88
+ final isLast = index == widget.list. length - 1 ;
118
89
final margin = EdgeInsets .only (
119
90
left: isFirst ? 24.0 : 6.5 ,
120
91
right: isLast ? 24.0 : 6.5 ,
@@ -126,15 +97,11 @@ class EntityAdaptorState extends State<EntityAdaptor> {
126
97
finalOffset: Offset .zero,
127
98
duration: const Duration (milliseconds: 200 ),
128
99
child: GestureDetector (
129
- onTap: () => onClick (listType, index),
100
+ onTap: () => onClick (index),
130
101
child: Container (
131
102
width: 102 ,
132
103
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),
138
105
),
139
106
),
140
107
);
@@ -145,14 +112,34 @@ class EntityAdaptorState extends State<EntityAdaptor> {
145
112
);
146
113
}
147
114
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]));
154
138
} else {
155
- navigateToPage (context, StudioScreen (studioInfo: widget.studioList! [index]));
139
+ navigateToPage (
140
+ context,
141
+ StudioScreen (
142
+ studioInfo: widget.list.whereType <studio>().toList ()[index]));
156
143
}
157
144
}
158
145
}
0 commit comments