Skip to content

Commit

Permalink
Made quick search on anime screen
Browse files Browse the repository at this point in the history
  • Loading branch information
K3vinb5 committed May 31, 2024
1 parent 62fd66c commit 9f6b444
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 6 deletions.
33 changes: 31 additions & 2 deletions lib/screens/anime_screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:unyo/api/anilist_api_anime.dart';
import 'package:unyo/models/anime_model.dart';
import 'package:unyo/screens/screens.dart';
import 'package:unyo/widgets/styled_dropdown_menu.dart';
import 'package:unyo/widgets/widgets.dart';

class AnimeScreen extends StatefulWidget {
Expand All @@ -29,6 +31,7 @@ class _AnimeScreenState extends State<AnimeScreen> {
double totalWidth = 0;
double totalHeight = 0;
ScrollController pageScrollController = ScrollController();
TextEditingController quickSearchController = TextEditingController();

@override
void initState() {
Expand Down Expand Up @@ -91,7 +94,6 @@ class _AnimeScreenState extends State<AnimeScreen> {
);
},
);

}

void setScrollListener() {
Expand Down Expand Up @@ -264,6 +266,29 @@ class _AnimeScreenState extends State<AnimeScreen> {
SizedBox(
height: totalHeight * 0.3,
),
//Acts as the beginning of screen
AnimatedOpacity(
opacity: bannerInfoVisible ? 1.0 : 0.0,
duration: !bannerInfoVisible
? const Duration(milliseconds: 300)
: const Duration(milliseconds: 1500),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
StyledDropDownMenu(
width: 400,
controller: quickSearchController,
color: Colors.white,
hintColor: Colors.grey,
label: "Search...",
labelColor: Colors.white,
),
const SizedBox(
width: 16,
),
],
),
),
AnimeWidgetList(
tag: "anime-details-list1",
title: "Recently Released",
Expand Down Expand Up @@ -305,7 +330,11 @@ class _AnimeScreenState extends State<AnimeScreen> {
AnimeButton(
text: "Advanced Search",
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => const MediaSearchScreen(type: "ANIME",),));
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const MediaSearchScreen(
type: "ANIME",
),
));
},
width: adjustedWidth,
height: adjustedHeight,
Expand Down
3 changes: 0 additions & 3 deletions lib/screens/media_search_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:math';
import 'dart:typed_data';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:unyo/api/consumet_api.dart';
import 'package:unyo/widgets/widgets.dart';
import 'package:unyo/models/models.dart';
import 'package:unyo/screens/screens.dart';
Expand Down
152 changes: 152 additions & 0 deletions lib/widgets/styled_dropdown_menu.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import 'dart:async';
import 'dart:ffi';
import 'package:flutter/material.dart';
import 'package:unyo/api/anilist_api_anime.dart';
import 'package:unyo/models/models.dart';
import 'package:unyo/screens/screens.dart';

class StyledDropDownMenu extends StatefulWidget {
const StyledDropDownMenu({
super.key,
required this.width,
required this.controller,
required this.color,
required this.hintColor,
this.label,
this.labelColor,
});

final double width;
final TextEditingController controller;
final Color color;
final Color hintColor;
final String? label;
final Color? labelColor;

@override
State<StyledDropDownMenu> createState() => _StyledDropDownMenuState();
}

class _StyledDropDownMenuState extends State<StyledDropDownMenu> {
Timer searchTimer = Timer(const Duration(milliseconds: 500), () {});
List<AnimeModel> listAnimeModels = [];
List<DropdownMenuEntry<AnimeModel>> listEntries = [
// const DropdownMenuEntry(value: SizedBox.shrink(), label: "Nothing"),
];

//There have no use, they just serve the search funtion and since I don't have filters here these are just the required default values
String currentSortBy = "Select Sorting";
String currentFormat = "Select Format";
String currentSeason = "Select Season";
String currentYear = "Select Year";

@override
void initState() {
super.initState();
widget.controller.addListener(() {
onChanged(widget.controller.text);
});
}

void openAnime(AnimeModel currentAnime, String tag) {
var animeScreen = AnimeDetailsScreen(
currentAnime: currentAnime,
tag: tag,
);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => animeScreen),
);
}

void onChanged(String text) {
// print(text);
searchTimer.cancel();
searchTimer = Timer(const Duration(milliseconds: 500), () async {
List<AnimeModel> newSearchMediaList = await getAnimeModelListSearch(
text, currentSortBy, currentSeason, currentFormat, currentYear, 10);
setState(() {
listAnimeModels = newSearchMediaList;
listEntries = [
...newSearchMediaList.map((animeModel) {
return DropdownMenuEntry(
style: const ButtonStyle(
side: MaterialStatePropertyAll(
BorderSide(
color: Color.fromARGB(255, 44, 43, 44),
),
),
overlayColor: MaterialStatePropertyAll(
Color.fromARGB(255, 33, 34, 33),
),
backgroundColor: MaterialStatePropertyAll(
Color.fromARGB(255, 39, 38, 39),
),
textStyle: MaterialStatePropertyAll(
TextStyle(color: Colors.white),
),
),
leadingIcon: Image.network(
animeModel.coverImage ?? "",
fit: BoxFit.fill,
height: 95,
),
labelWidget: Text(
animeModel.title ?? "",
style: const TextStyle(
color: Colors.white, overflow: TextOverflow.ellipsis),
),
label: "",
value: animeModel,
);
}),
];
});
});
}

@override
Widget build(BuildContext context) {
return DropdownMenu(
menuStyle: const MenuStyle(
padding: MaterialStatePropertyAll(EdgeInsets.symmetric(vertical: 10.0)),
side: MaterialStatePropertyAll(
BorderSide(
color: Color.fromARGB(255, 39, 38, 39),
width: 5.0,
),
),
),
width: widget.width,
menuHeight: 350,
controller: widget.controller,
inputDecorationTheme: InputDecorationTheme(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: BorderSide(color: widget.color),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: BorderSide(color: widget.color),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: BorderSide(color: widget.color),
// TextStyle(color: Colors.white),
),
),
textStyle: TextStyle(color: widget.color),
label: Text(
widget.label ?? "",
style: TextStyle(color: widget.labelColor ?? Colors.white),
),
dropdownMenuEntries: listEntries,
onSelected: (value) {
if (value == null) {
return;
}
openAnime(value, "search-${listAnimeModels.indexOf(value)}");
},
);
}
}
7 changes: 6 additions & 1 deletion lib/widgets/styled_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ class StyledTextField extends StatelessWidget {
required this.color,
required this.hintColor,
this.label,
required this.hint});
this.labelColor,
required this.hint
});

final double width;
final TextEditingController controller;
final void Function(String)? onChanged;
final Color color;
final Color hintColor;
final String? label;
final Color? labelColor;
final String hint;

@override
Expand All @@ -42,6 +45,8 @@ class StyledTextField extends StatelessWidget {
),
hintText: hint,
labelText: label,
// labelStyle: const TextStyle(color: Colors.white),
floatingLabelStyle: TextStyle(color: labelColor ?? Colors.white),
hintStyle: TextStyle(
color: hintColor,
),
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export 'manga_widget.dart';
export 'manga_widget_list.dart';
export 'chapter_button.dart';
export 'manga_options_bar.dart';
export 'styled_dropdown_menu.dart';

0 comments on commit 9f6b444

Please sign in to comment.