Skip to content

Commit

Permalink
search
Browse files Browse the repository at this point in the history
  • Loading branch information
mo7amedaliEbaid committed May 26, 2024
1 parent f79955b commit 82d6787
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
66 changes: 49 additions & 17 deletions lib/features/home/presentation/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<HomeScreen> {
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(
Expand Down Expand Up @@ -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<DrinkDetails>> &&
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<DrinkDetails>> &&
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(),
Expand Down
5 changes: 2 additions & 3 deletions lib/features/home/presentation/widgets/custom_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,12 +31,9 @@ Widget customTextField(
),
borderSide: const BorderSide(color: Colors.transparent),
),

contentPadding: Space.all(1, .5),
fillColor: Colors.white,
filled: true,


),
);
}

0 comments on commit 82d6787

Please sign in to comment.