From 22cbf2dc44fd42ae13a0b86285636a4f51472f40 Mon Sep 17 00:00:00 2001 From: kodjomoustapha <107993382+kodjodevf@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:16:00 +0100 Subject: [PATCH] fix Textfield not visible on mobile when typing --- .../detail/widgets/tracker_search_widget.dart | 283 ++++++++++-------- 1 file changed, 161 insertions(+), 122 deletions(-) diff --git a/lib/modules/manga/detail/widgets/tracker_search_widget.dart b/lib/modules/manga/detail/widgets/tracker_search_widget.dart index 55727650..3cc947d4 100644 --- a/lib/modules/manga/detail/widgets/tracker_search_widget.dart +++ b/lib/modules/manga/detail/widgets/tracker_search_widget.dart @@ -1,4 +1,3 @@ -import 'package:draggable_menu/draggable_menu.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mangayomi/models/manga.dart'; @@ -6,6 +5,7 @@ import 'package:mangayomi/models/track.dart'; import 'package:mangayomi/models/track_search.dart'; import 'package:mangayomi/modules/manga/detail/providers/track_state_providers.dart'; import 'package:mangayomi/modules/widgets/custom_extended_image_provider.dart'; +import 'package:mangayomi/modules/widgets/error_text.dart'; import 'package:mangayomi/modules/widgets/progress_center.dart'; import 'package:mangayomi/utils/extensions/build_context_extensions.dart'; @@ -28,13 +28,20 @@ class _TrackerWidgetSearchState extends ConsumerState { } late String query = widget.track.title!.trim(); + bool hide = false; late List? tracks = []; + String? _errorMsg; _init() async { await Future.delayed(const Duration(microseconds: 100)); - tracks = await ref - .read(trackStateProvider(track: widget.track, itemType: widget.itemType) - .notifier) - .search(query); + try { + tracks = await ref + .read( + trackStateProvider(track: widget.track, itemType: widget.itemType) + .notifier) + .search(query); + } catch (e) { + _errorMsg = e.toString(); + } if (mounted) { setState(() { _isLoading = false; @@ -52,115 +59,133 @@ class _TrackerWidgetSearchState extends ConsumerState { bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)), clipBehavior: Clip.antiAliasWithSaveLayer, child: _isLoading - ? const ProgressCenter() + ? SizedBox( + height: context.height(0.3), + child: Padding( + padding: const EdgeInsets.all(20), + child: const ProgressCenter(), + ), + ) : Padding( padding: const EdgeInsets.symmetric(horizontal: 10), child: SizedBox( height: context.height(0.8), child: Column( children: [ - Flexible( - child: ListView.separated( - padding: const EdgeInsets.only(top: 20), - itemCount: tracks!.length, - itemBuilder: (context, index) { - return Padding( - padding: const EdgeInsets.only(top: 5), - child: InkWell( - onTap: () { - Navigator.pop(context, tracks![index]); - }, - child: Column( - children: [ - Row( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Material( - borderRadius: BorderRadius.circular(5), - color: Colors.transparent, - clipBehavior: - Clip.antiAliasWithSaveLayer, - child: Ink.image( - height: 120, - width: 80, - fit: BoxFit.cover, - image: - CustomExtendedNetworkImageProvider( - tracks![index].coverUrl!), - ), - ), - const SizedBox( - width: 10, - ), - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox( - width: context.width(0.6), - child: Text( - tracks![index].title!, - style: const TextStyle( - fontWeight: FontWeight.bold), - ), - ), - Row( - children: [ - const Text( - "Type : ", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 12), - ), - Text( - tracks![index].publishingType!, - style: const TextStyle( - fontSize: 12), - ), - ], + if (_errorMsg != null) ErrorText(_errorMsg!), + if (_errorMsg == null && !hide) + Flexible( + child: ListView.separated( + padding: const EdgeInsets.only(top: 20), + itemCount: tracks!.length, + itemBuilder: (context, index) { + return Padding( + padding: const EdgeInsets.only(top: 5), + child: InkWell( + onTap: () { + Navigator.pop(context, tracks![index]); + }, + child: Column( + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Material( + borderRadius: + BorderRadius.circular(5), + color: Colors.transparent, + clipBehavior: + Clip.antiAliasWithSaveLayer, + child: Ink.image( + height: 120, + width: 80, + fit: BoxFit.cover, + image: + CustomExtendedNetworkImageProvider( + tracks![index].coverUrl!), ), - Row( - children: [ - const Text( - "Status : ", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 12), - ), - Text( - tracks![index] - .publishingStatus!, + ), + const SizedBox( + width: 10, + ), + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox( + width: context.width(0.6), + child: Text( + tracks![index].title!, style: const TextStyle( - fontSize: 12), + fontWeight: + FontWeight.bold), ), - ], - ), - ], - ) - ], - ), - Text( - tracks![index].summary!, - style: const TextStyle( - fontSize: 12, - overflow: TextOverflow.ellipsis, + ), + Row( + children: [ + const Text( + "Type : ", + style: TextStyle( + fontWeight: + FontWeight.bold, + fontSize: 12), + ), + Text( + tracks![index] + .publishingType!, + style: const TextStyle( + fontSize: 12), + ), + ], + ), + Row( + children: [ + const Text( + "Status : ", + style: TextStyle( + fontWeight: + FontWeight.bold, + fontSize: 12), + ), + Text( + tracks![index] + .publishingStatus!, + style: const TextStyle( + fontSize: 12), + ), + ], + ), + ], + ) + ], + ), + Text( + tracks![index].summary!, + style: const TextStyle( + fontSize: 12, + overflow: TextOverflow.ellipsis, + ), + maxLines: 3, ), - maxLines: 3, - ), - ], + ], + ), ), - ), - ); - }, - separatorBuilder: (BuildContext context, int index) { - return const Divider(); - }, + ); + }, + separatorBuilder: (BuildContext context, int index) { + return const Divider(); + }, + ), ), - ), Padding( padding: const EdgeInsets.symmetric(vertical: 10), child: TextFormField( + onTap: () { + setState(() { + hide = true; + }); + }, controller: _controller, keyboardType: TextInputType.text, onChanged: (d) { @@ -171,16 +196,24 @@ class _TrackerWidgetSearchState extends ConsumerState { onFieldSubmitted: (d) async { setState(() { _isLoading = true; + _errorMsg = null; }); - tracks = await ref - .read(trackStateProvider( - track: widget.track, - itemType: widget.itemType) - .notifier) - .search(d.trim()); + try { + tracks = await ref + .read(trackStateProvider( + track: widget.track, + itemType: widget.itemType) + .notifier) + .search(d.trim()); + } catch (e) { + _errorMsg = e.toString(); + hide = false; + } + if (mounted) { setState(() { _isLoading = false; + hide = false; }); } }, @@ -218,13 +251,18 @@ class _TrackerWidgetSearchState extends ConsumerState { trackersSearchraggableMenu(BuildContext context, {required Track track, required ItemType itemType}) async { - return await DraggableMenu.open( - context, - DraggableMenu( - blockMenuClosing: true, - ui: ClassicDraggableMenu( - radius: 20, - barItem: Container( + var padding = MediaQuery.of(context).padding; + return await showDialog( + context: context, + builder: (context) => Scaffold( + backgroundColor: Colors.transparent, + body: SingleChildScrollView( + child: SizedBox( + height: context.height(1) - padding.top - padding.bottom, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( decoration: BoxDecoration( color: Theme.of(context).scaffoldBackgroundColor, borderRadius: const BorderRadius.only( @@ -245,16 +283,17 @@ trackersSearchraggableMenu(BuildContext context, ) ], ), - const Divider() ], ), - )), - levels: [ - DraggableMenuLevel.ratio(ratio: 0.9), - ], - minimizeBeforeFastDrag: true, - child: TrackerWidgetSearch( - track: track, - itemType: itemType, - ))); + ), + TrackerWidgetSearch( + track: track, + itemType: itemType, + ), + ], + ), + ), + ), + ), + ); }