From 82d6787c9c2fc8d3b219f8e0b10070e1c069e7f0 Mon Sep 17 00:00:00 2001 From: Mohamed Ali Date: Sun, 26 May 2024 22:31:43 +0300 Subject: [PATCH] search --- .../home/presentation/screens/home.dart | 66 ++++++++++++++----- .../widgets/custom_textfield.dart | 5 +- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/lib/features/home/presentation/screens/home.dart b/lib/features/home/presentation/screens/home.dart index c98c480..23795fc 100644 --- a/lib/features/home/presentation/screens/home.dart +++ b/lib/features/home/presentation/screens/home.dart @@ -21,15 +21,33 @@ import '../../../random_drink/presentation/providers/random_recipe_provider.dart import '../../../random_drink/presentation/widgets/recipe_item.dart'; import '../../../search/presentation/provider/serached_drinks_provider.dart'; -class HomeScreen extends ConsumerWidget { +class HomeScreen extends ConsumerStatefulWidget { const HomeScreen({super.key}); @override - Widget build(BuildContext context, WidgetRef ref) { + HomeScreenState createState() => HomeScreenState(); +} + +class HomeScreenState extends ConsumerState { + final TextEditingController controller = TextEditingController(); + + @override + void initState() { + super.initState(); + } + + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { App.init(context); final categoriesState = ref.watch(categoriesProvider); final randomRecipeState = ref.watch(randomRecipeProvider); - final TextEditingController controller = TextEditingController(); + final searchState = ref.watch(searchProvider); log(AppDimensions.normalize(39.38).toString()); return Scaffold( @@ -67,26 +85,40 @@ class HomeScreen extends ConsumerWidget { onSubmitted: (value) { ref.read(searchValueProvider.notifier).state = value.toString(); + showDialog( context: context, builder: (context) { - return Dialog( - child: SizedBox( - height: - MediaQuery.sizeOf(context).height * .3, - width: - MediaQuery.sizeOf(context).width * .6, - child: searchState is SuccessState< - List> && - searchState.data != null - ? searchState.data!.isNotEmpty - ? Text(searchState - .data!.first.strDrink) - : const Text("Empty") - : const Text("Error"), + return WillPopScope( + onWillPop: () async { + /* ref + .read(searchValueProvider.notifier) + .state = '';*/ + return true; + }, + child: Dialog( + child: SizedBox( + height: + MediaQuery.sizeOf(context).height * + .3, + width: + MediaQuery.sizeOf(context).width * .6, + child: searchState is SuccessState< + List> && + searchState.data != null + ? searchState.data!.isNotEmpty + ? Center( + child: Text(searchState + .data!.first.strDrink), + ) + : const Center( + child: Text("Empty")) + : const Center(child: Text("Error")), + ), ), ); }); + // ref.read(searchValueProvider.notifier).state = ''; }), ), Space.yf(), diff --git a/lib/features/home/presentation/widgets/custom_textfield.dart b/lib/features/home/presentation/widgets/custom_textfield.dart index 35972c1..e8453b9 100644 --- a/lib/features/home/presentation/widgets/custom_textfield.dart +++ b/lib/features/home/presentation/widgets/custom_textfield.dart @@ -13,8 +13,10 @@ Widget customTextField( return TextField( controller: controller, onChanged: onChanged, + onSubmitted: onSubmitted, cursorColor: Colors.grey, maxLines: maxLines, + textInputAction: TextInputAction.go, style: AppText.b1, decoration: InputDecoration( hintText: hintText, @@ -29,12 +31,9 @@ Widget customTextField( ), borderSide: const BorderSide(color: Colors.transparent), ), - contentPadding: Space.all(1, .5), fillColor: Colors.white, filled: true, - - ), ); }