From 9f6b444f0c5e07d0313afcf0e5f96fb7b7caa6ef Mon Sep 17 00:00:00 2001 From: Kevin Rodrigues Borges <115191440+K3vinb5@users.noreply.github.com> Date: Fri, 31 May 2024 20:32:43 +0100 Subject: [PATCH] Made quick search on anime screen --- lib/screens/anime_screen.dart | 33 +++++- lib/screens/media_search_screen.dart | 3 - lib/widgets/styled_dropdown_menu.dart | 152 ++++++++++++++++++++++++++ lib/widgets/styled_textfield.dart | 7 +- lib/widgets/widgets.dart | 1 + 5 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 lib/widgets/styled_dropdown_menu.dart diff --git a/lib/screens/anime_screen.dart b/lib/screens/anime_screen.dart index 1507132..8b20b50 100644 --- a/lib/screens/anime_screen.dart +++ b/lib/screens/anime_screen.dart @@ -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 { @@ -29,6 +31,7 @@ class _AnimeScreenState extends State { double totalWidth = 0; double totalHeight = 0; ScrollController pageScrollController = ScrollController(); + TextEditingController quickSearchController = TextEditingController(); @override void initState() { @@ -91,7 +94,6 @@ class _AnimeScreenState extends State { ); }, ); - } void setScrollListener() { @@ -264,6 +266,29 @@ class _AnimeScreenState extends State { 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", @@ -305,7 +330,11 @@ class _AnimeScreenState extends State { 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, diff --git a/lib/screens/media_search_screen.dart b/lib/screens/media_search_screen.dart index 3e76968..9f7d762 100644 --- a/lib/screens/media_search_screen.dart +++ b/lib/screens/media_search_screen.dart @@ -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'; diff --git a/lib/widgets/styled_dropdown_menu.dart b/lib/widgets/styled_dropdown_menu.dart new file mode 100644 index 0000000..92be5ce --- /dev/null +++ b/lib/widgets/styled_dropdown_menu.dart @@ -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 createState() => _StyledDropDownMenuState(); +} + +class _StyledDropDownMenuState extends State { + Timer searchTimer = Timer(const Duration(milliseconds: 500), () {}); + List listAnimeModels = []; + List> 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 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)}"); + }, + ); + } +} diff --git a/lib/widgets/styled_textfield.dart b/lib/widgets/styled_textfield.dart index 41ef539..20b7522 100644 --- a/lib/widgets/styled_textfield.dart +++ b/lib/widgets/styled_textfield.dart @@ -9,7 +9,9 @@ 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; @@ -17,6 +19,7 @@ class StyledTextField extends StatelessWidget { final Color color; final Color hintColor; final String? label; + final Color? labelColor; final String hint; @override @@ -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, ), diff --git a/lib/widgets/widgets.dart b/lib/widgets/widgets.dart index 59a4805..eb4d65c 100644 --- a/lib/widgets/widgets.dart +++ b/lib/widgets/widgets.dart @@ -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';