Skip to content

Commit

Permalink
feat: search for users
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed Feb 15, 2025
1 parent a0bf3e2 commit 6f9b59b
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 96 deletions.
97 changes: 42 additions & 55 deletions lib/Adaptor/Charactes/EntityAdaptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@ import 'Widgets/EntitySection.dart';

class EntityAdaptor extends StatefulWidget {
final EntityType type;

final int? adaptorType;
final List<character>? characterList;
final List<author>? staffList;

final List<studio>? studioList;
final List<Object> list;

const EntityAdaptor({
super.key,
this.adaptorType = 1,
required this.type,
this.characterList,
this.staffList,
this.adaptorType,
this.studioList,
required this.list,
});

@override
Expand All @@ -40,26 +34,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
Widget build(BuildContext context) {
switch (widget.adaptorType) {
case 1:
return _buildCharacterLayout(
widget.characterList, widget.staffList, widget.studioList);
return _buildCharacterLayout();
case 2:
return _buildStaggeredGrid(
widget.characterList, widget.staffList, widget.studioList);
return _buildStaggeredGrid();
default:
return _buildCharacterLayout(
widget.characterList, widget.staffList, widget.studioList);
return _buildCharacterLayout();
}
}

Widget _buildStaggeredGrid(
final List<character>? characterList,
final List<author>? staffList,
final List<studio>? studioList,
) {
var listType = widget.type;
var length = listType == EntityType.Character
? characterList!.length : listType == EntityType.Staff ? staffList!.length
: studioList!.length;
Widget _buildStaggeredGrid() {
return LayoutBuilder(
builder: (context, constraints) {
final parentWidth = constraints.maxWidth;
Expand All @@ -71,19 +54,15 @@ class EntityAdaptorState extends State<EntityAdaptor> {
crossAxisSpacing: 16,
crossAxisCount: crossAxisCount,
children: List.generate(
length,
widget.list.length,
(index) {
return GestureDetector(
onTap: () => onClick(listType, index),
onTap: () => onClick(index),
onLongPress: () {},
child: SizedBox(
width: 102,
height: 212,
child: listType == EntityType.Character
? CharacterViewHolder(charInfo: characterList![index])
: listType == EntityType.Staff
? StaffViewHolder(staffInfo: staffList![index])
: StudioViewHolder(studioInfo: studioList![index]),
child: _buildHolder(index),
),
);
},
Expand All @@ -94,15 +73,7 @@ class EntityAdaptorState extends State<EntityAdaptor> {
);
}

Widget _buildCharacterLayout(
final List<character>? characterList,
final List<author>? staffList,
final List<studio>? studioList,
) {
var listType = widget.type;
var length = listType == EntityType.Character
? characterList!.length : listType == EntityType.Staff ? staffList!.length
: studioList!.length;
Widget _buildCharacterLayout() {
return SizedBox(
height: 212,
child: AnimatedSwitcher(
Expand All @@ -111,10 +82,10 @@ class EntityAdaptorState extends State<EntityAdaptor> {
context,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: length,
itemCount: widget.list.length,
itemBuilder: (context, index) {
final isFirst = index == 0;
final isLast = index == length - 1;
final isLast = index == widget.list.length - 1;
final margin = EdgeInsets.only(
left: isFirst ? 24.0 : 6.5,
right: isLast ? 24.0 : 6.5,
Expand All @@ -126,15 +97,11 @@ class EntityAdaptorState extends State<EntityAdaptor> {
finalOffset: Offset.zero,
duration: const Duration(milliseconds: 200),
child: GestureDetector(
onTap: () => onClick(listType, index),
onTap: () => onClick(index),
child: Container(
width: 102,
margin: margin,
child: listType == EntityType.Character
? CharacterViewHolder(charInfo: characterList![index])
: listType == EntityType.Staff
? StaffViewHolder(staffInfo: staffList![index])
: StudioViewHolder(studioInfo: studioList![index]),
child: _buildHolder(index),
),
),
);
Expand All @@ -145,14 +112,34 @@ class EntityAdaptorState extends State<EntityAdaptor> {
);
}

void onClick(EntityType type, int index) {
if (type == EntityType.Character) {
navigateToPage(context,
CharacterScreen(characterInfo: widget.characterList![index]));
} else if (type == EntityType.Staff) {
navigateToPage(context, StaffScreen(staffInfo: widget.staffList![index]));
Widget _buildHolder(int index) {
return widget.type == EntityType.Character
? CharacterViewHolder(
charInfo: widget.list.whereType<character>().toList()[index])
: widget.type == EntityType.Staff
? StaffViewHolder(
staffInfo: widget.list.whereType<author>().toList()[index])
: StudioViewHolder(
studioInfo: widget.list.whereType<studio>().toList()[index]);
}

void onClick(int index) {
if (widget.type == EntityType.Character) {
navigateToPage(
context,
CharacterScreen(
characterInfo:
widget.list.whereType<character>().toList()[index]));
} else if (widget.type == EntityType.Staff) {
navigateToPage(
context,
StaffScreen(
staffInfo: widget.list.whereType<author>().toList()[index]));
} else {
navigateToPage(context, StudioScreen(studioInfo: widget.studioList![index]));
navigateToPage(
context,
StudioScreen(
studioInfo: widget.list.whereType<studio>().toList()[index]));
}
}
}
13 changes: 2 additions & 11 deletions lib/Adaptor/Charactes/Widgets/EntitySection.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import 'package:dantotsu/DataClass/Studio.dart';
import 'package:flutter/material.dart';

import '../../../../DataClass/Character.dart';
import '../../../DataClass/Author.dart';
import '../EntityAdaptor.dart';

Widget entitySection({
required BuildContext context,
required EntityType type,
required String title,
int adaptorType = 1,
List<character>? characterList,
List<author>? staffList,
List<studio>? studioList,
List<Object>? list,
List<Widget>? customNullListIndicator,
}) {
var theme = Theme.of(context);
var list = type == EntityType.Character ? characterList : type == EntityType.Staff ? staffList : studioList;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down Expand Up @@ -84,10 +77,8 @@ Widget entitySection({
)
: EntityAdaptor(
type: type,
characterList: characterList,
staffList: staffList,
studioList: studioList,
adaptorType: adaptorType,
list: list,
),
),
],
Expand Down
99 changes: 99 additions & 0 deletions lib/Adaptor/User/UserAdaptor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'dart:math';

import 'package:dantotsu/DataClass/User.dart';
import 'package:dantotsu/Functions/Function.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

import '../../Widgets/ScrollConfig.dart';
import 'UserLargeViewHolder.dart';
import 'UserViewHolder.dart';

class UserAdaptor extends StatefulWidget {
final int type;
final List<userData> list;

const UserAdaptor({
super.key,
required this.type,
required this.list,
});

@override
UserAdaptorState createState() => UserAdaptorState();
}

class UserAdaptorState extends State<UserAdaptor> {
@override
Widget build(BuildContext context) {
switch (widget.type) {
case 1:
return _buildVerticalList();
case 2:
return _buildStaggeredGrid();
default:
return _buildVerticalList();
}
}

String _generateTag(int index) =>
'${widget.list[index].id}${Random().nextInt(100000)}';

Widget _buildStaggeredGrid() {
return LayoutBuilder(
builder: (context, constraints) {
final parentWidth = constraints.maxWidth;
var crossAxisCount = (parentWidth / 124).floor();
if (crossAxisCount < 1) crossAxisCount = 1;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0),
child: StaggeredGrid.count(
crossAxisSpacing: 16,
crossAxisCount: crossAxisCount,
children: List.generate(
widget.list.length,
(index) {
return GestureDetector(
onTap: () => onClick(index),
onLongPress: () {},
child: SizedBox(
width: 102,
height: 150,
child: UserViewHolder(user: widget.list[index]),
),
);
},
),
),
);
},
);
}

void onClick(int index) {
snackString("not implemented yet");
}

Widget _buildVerticalList() {
return ScrollConfig(
context,
child: ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.list.length,
itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 18, vertical: 4),
child: GestureDetector(
onTap: () => onClick(index),
child: UserLargeViewHolder(
user: widget.list[index],
tag: _generateTag(index),
),
),
);
},
),
);
}
}
Loading

0 comments on commit 6f9b59b

Please sign in to comment.