@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
2
2
import 'package:flutter_bloc/flutter_bloc.dart' ;
3
3
import 'package:ht_headlines_repository/ht_headlines_repository.dart' ;
4
4
import 'package:ht_main/headlines-feed/bloc/headlines_feed_bloc.dart' ;
5
- import 'package:ht_main/headlines-feed/view/headline_filter_bottom_sheet.dart' ;
6
5
import 'package:ht_main/headlines-feed/widgets/headline_item_widget.dart' ;
7
6
import 'package:ht_main/shared/widgets/failure_state_widget.dart' ;
8
7
import 'package:ht_main/shared/widgets/loading_state_widget.dart' ;
@@ -73,24 +72,12 @@ class _HeadlinesFeedViewState extends State<_HeadlinesFeedView> {
73
72
IconButton (
74
73
icon: const Icon (Icons .filter_list),
75
74
onPressed: () {
75
+ final bloc = context.read <HeadlinesFeedBloc >();
76
76
showModalBottomSheet <void >(
77
77
context: context,
78
78
builder: (BuildContext context) {
79
- final bloc = context.read <HeadlinesFeedBloc >();
80
- return BlocProvider .value (
81
- value: bloc,
82
- child: HeadlineFilterBottomSheet (
83
- bloc: bloc,
84
- onApplyFilters: (category, source, eventCountry) {
85
- bloc.add (
86
- HeadlinesFeedFilterChanged (
87
- category: category,
88
- source: source,
89
- eventCountry: eventCountry,
90
- ),
91
- );
92
- },
93
- ),
79
+ return _HeadlinesFilterBottomSheet (
80
+ bloc: bloc,
94
81
);
95
82
},
96
83
);
@@ -139,3 +126,116 @@ class _HeadlinesFeedViewState extends State<_HeadlinesFeedView> {
139
126
);
140
127
}
141
128
}
129
+
130
+ class _HeadlinesFilterBottomSheet extends StatefulWidget {
131
+ const _HeadlinesFilterBottomSheet ({
132
+ required this .bloc,
133
+ });
134
+
135
+ final HeadlinesFeedBloc bloc;
136
+
137
+ @override
138
+ State <_HeadlinesFilterBottomSheet > createState () =>
139
+ _HeadlinesFilterBottomSheetState ();
140
+ }
141
+
142
+ class _HeadlinesFilterBottomSheetState
143
+ extends State <_HeadlinesFilterBottomSheet > {
144
+ String ? selectedCategory;
145
+ String ? selectedSource;
146
+ String ? selectedEventCountry;
147
+
148
+ @override
149
+ void initState () {
150
+ super .initState ();
151
+ final state = widget.bloc.state;
152
+ if (state is HeadlinesFeedLoaded ) {
153
+ selectedCategory = state.filter.category;
154
+ selectedSource = state.filter.source;
155
+ selectedEventCountry = state.filter.eventCountry;
156
+ }
157
+ }
158
+
159
+ @override
160
+ Widget build (BuildContext context) {
161
+ return BlocProvider .value (
162
+ value: widget.bloc,
163
+ child: Padding (
164
+ padding: const EdgeInsets .all (16 ),
165
+ child: Column (
166
+ mainAxisSize: MainAxisSize .min,
167
+ children: [
168
+ Text (
169
+ 'Filter Headlines' ,
170
+ style: Theme .of (context).textTheme.titleLarge,
171
+ ),
172
+ const SizedBox (height: 16 ),
173
+ // Category Dropdown
174
+ DropdownButtonFormField <String >(
175
+ decoration: const InputDecoration (labelText: 'Category' ),
176
+ value: selectedCategory,
177
+ items: const [
178
+ // Placeholder items
179
+ DropdownMenuItem (value: 'technology' , child: Text ('Technology' )),
180
+ DropdownMenuItem (value: 'business' , child: Text ('Business' )),
181
+ DropdownMenuItem (value: 'Politics' , child: Text ('Sports' )),
182
+ ],
183
+ onChanged: (value) {
184
+ setState (() {
185
+ selectedCategory = value;
186
+ });
187
+ },
188
+ ),
189
+ const SizedBox (height: 16 ),
190
+ // Source Dropdown
191
+ DropdownButtonFormField <String >(
192
+ decoration: const InputDecoration (labelText: 'Source' ),
193
+ value: selectedSource,
194
+ items: const [
195
+ // Placeholder items
196
+ DropdownMenuItem (value: 'cnn' , child: Text ('CNN' )),
197
+ DropdownMenuItem (value: 'reuters' , child: Text ('Reuters' )),
198
+ ],
199
+ onChanged: (value) {
200
+ setState (() {
201
+ selectedSource = value;
202
+ });
203
+ },
204
+ ),
205
+ const SizedBox (height: 16 ),
206
+ // Event Country Dropdown
207
+ DropdownButtonFormField <String >(
208
+ decoration: const InputDecoration (labelText: 'Event Country' ),
209
+ value: selectedEventCountry,
210
+ items: const [
211
+ // Placeholder items
212
+ DropdownMenuItem (value: 'US' , child: Text ('United States' )),
213
+ DropdownMenuItem (value: 'UK' , child: Text ('United Kingdom' )),
214
+ DropdownMenuItem (value: 'CA' , child: Text ('Canada' )),
215
+ ],
216
+ onChanged: (value) {
217
+ setState (() {
218
+ selectedEventCountry = value;
219
+ });
220
+ },
221
+ ),
222
+ const SizedBox (height: 24 ),
223
+ ElevatedButton (
224
+ onPressed: () {
225
+ widget.bloc.add (
226
+ HeadlinesFeedFilterChanged (
227
+ category: selectedCategory,
228
+ source: selectedSource,
229
+ eventCountry: selectedEventCountry,
230
+ ),
231
+ );
232
+ Navigator .pop (context);
233
+ },
234
+ child: const Text ('Apply Filters' ),
235
+ ),
236
+ ],
237
+ ),
238
+ ),
239
+ );
240
+ }
241
+ }
0 commit comments