|
1 | 1 | import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
2 | 3 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
3 | 4 |
|
4 | 5 | import '../../data/constants/colors.dart'; |
5 | 6 | import '../components/inputs/text_input.dart'; |
| 7 | +import 'bloc/search_bloc.dart'; |
| 8 | +import 'widgets/filter_search.dart'; |
| 9 | +import 'widgets/recent_searches.dart'; |
| 10 | +import 'widgets/searched_result.dart'; |
6 | 11 |
|
7 | 12 | class SearchScreen extends StatelessWidget { |
8 | | - const SearchScreen({Key? key}) : super(key: key); |
| 13 | + SearchScreen({Key? key}) : super(key: key); |
| 14 | + final TextEditingController _controller = TextEditingController(); |
9 | 15 |
|
10 | 16 | @override |
11 | 17 | Widget build(BuildContext context) { |
12 | | - return Column( |
13 | | - children: [ |
14 | | - Padding( |
15 | | - padding: EdgeInsets.symmetric( |
16 | | - horizontal: 13.w, |
17 | | - vertical: 30.h, |
18 | | - ), |
19 | | - child: TextInput( |
20 | | - hint: 'Search people by name or handles', |
21 | | - onChanged: (val) {}, |
22 | | - isFilled: true, |
23 | | - fillColor: AppColors.grey7, |
24 | | - suffix: Row( |
25 | | - mainAxisSize: MainAxisSize.min, |
26 | | - children: [ |
27 | | - IconButton( |
28 | | - padding: const EdgeInsets.fromLTRB(4, 1, 1, 4), |
29 | | - icon: const Icon( |
30 | | - Icons.filter_alt, |
31 | | - color: AppColors.grey6, |
32 | | - ), |
33 | | - onPressed: () {}, |
| 18 | + return BlocProvider<SearchBloc>( |
| 19 | + create: (context) => SearchBloc()..add(const FetchInstituteList()), |
| 20 | + child: BlocBuilder<SearchBloc, SearchState>( |
| 21 | + builder: (context, state) { |
| 22 | + return Column( |
| 23 | + children: [ |
| 24 | + Padding( |
| 25 | + padding: EdgeInsets.symmetric( |
| 26 | + horizontal: 13.w, |
| 27 | + vertical: 30.h, |
34 | 28 | ), |
35 | | - IconButton( |
36 | | - padding: const EdgeInsets.fromLTRB(4, 1, 1, 4), |
37 | | - icon: const Icon( |
38 | | - Icons.clear, |
39 | | - color: AppColors.grey6, |
| 29 | + child: TextInput( |
| 30 | + hint: 'Search people by name or handles', |
| 31 | + onChanged: (val) { |
| 32 | + if (val.isEmpty) { |
| 33 | + context.read<SearchBloc>().add(const Reset()); |
| 34 | + } |
| 35 | + }, |
| 36 | + controller: _controller, |
| 37 | + onSubmitted: (val) { |
| 38 | + final res = val.trim(); |
| 39 | + if (res.isEmpty) return; |
| 40 | + context.read<SearchBloc>().add(SearchPeople(query: res)); |
| 41 | + }, |
| 42 | + action: TextInputAction.search, |
| 43 | + isFilled: true, |
| 44 | + border: InputBorder.none, |
| 45 | + fillColor: AppColors.grey7, |
| 46 | + suffix: Row( |
| 47 | + mainAxisSize: MainAxisSize.min, |
| 48 | + children: [ |
| 49 | + IconButton( |
| 50 | + padding: const EdgeInsets.fromLTRB(4, 1, 1, 4), |
| 51 | + icon: const Icon( |
| 52 | + Icons.filter_alt, |
| 53 | + color: AppColors.grey6, |
| 54 | + ), |
| 55 | + onPressed: () { |
| 56 | + showModalBottomSheet( |
| 57 | + context: context, |
| 58 | + builder: (_) { |
| 59 | + return FilterSearch( |
| 60 | + bloc: context.read<SearchBloc>(), |
| 61 | + ); |
| 62 | + }, |
| 63 | + ); |
| 64 | + }, |
| 65 | + ), |
| 66 | + IconButton( |
| 67 | + padding: const EdgeInsets.fromLTRB(4, 1, 1, 4), |
| 68 | + icon: const Icon( |
| 69 | + Icons.close, |
| 70 | + color: AppColors.grey6, |
| 71 | + ), |
| 72 | + onPressed: () { |
| 73 | + _controller.clear(); |
| 74 | + if (state.showSearches) { |
| 75 | + context.read<SearchBloc>().add(const Reset()); |
| 76 | + } |
| 77 | + }, |
| 78 | + ), |
| 79 | + ], |
40 | 80 | ), |
41 | | - onPressed: () {}, |
42 | 81 | ), |
43 | | - ], |
44 | | - ), |
45 | | - ), |
46 | | - ), |
47 | | - ], |
| 82 | + ), |
| 83 | + Expanded( |
| 84 | + child: state.showSearches |
| 85 | + ? const SearchedResult() |
| 86 | + : const RecentSearches(), |
| 87 | + ), |
| 88 | + ], |
| 89 | + ); |
| 90 | + }, |
| 91 | + ), |
48 | 92 | ); |
49 | 93 | } |
50 | 94 | } |
0 commit comments