Skip to content

Commit 7030a97

Browse files
committed
feat(feed): add filter reset and scroll
- Added reset filter button - Added null value to dropdowns - Added SingleChildScrollView
1 parent 4f7c9e7 commit 7030a97

File tree

1 file changed

+104
-73
lines changed

1 file changed

+104
-73
lines changed

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 104 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class _HeadlinesFilterBottomSheetState
145145
String? selectedSource;
146146
String? selectedEventCountry;
147147

148-
@override
148+
@override
149149
void initState() {
150150
super.initState();
151151
final state = widget.bloc.state;
@@ -162,78 +162,109 @@ class _HeadlinesFilterBottomSheetState
162162
value: widget.bloc,
163163
child: Padding(
164164
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-
],
165+
child: SingleChildScrollView(
166+
child: Column(
167+
mainAxisSize: MainAxisSize.min,
168+
children: [
169+
// Text(
170+
// 'Filter Headlines',
171+
// style: Theme.of(context).textTheme.titleLarge,
172+
// ),
173+
const SizedBox(height: 16),
174+
// Category Dropdown
175+
DropdownButtonFormField<String>(
176+
decoration: const InputDecoration(labelText: 'Category'),
177+
value: selectedCategory,
178+
items: const [
179+
// Placeholder items
180+
const DropdownMenuItem<String>(
181+
value: null, child: Text('All')),
182+
DropdownMenuItem(
183+
value: 'technology', child: Text('Technology')),
184+
DropdownMenuItem(value: 'business', child: Text('Business')),
185+
DropdownMenuItem(value: 'Politics', child: Text('Sports')),
186+
],
187+
onChanged: (value) {
188+
setState(() {
189+
selectedCategory = value;
190+
});
191+
},
192+
),
193+
const SizedBox(height: 16),
194+
// Source Dropdown
195+
DropdownButtonFormField<String>(
196+
decoration: const InputDecoration(labelText: 'Source'),
197+
value: selectedSource,
198+
items: const [
199+
// Placeholder items
200+
const DropdownMenuItem<String>(
201+
value: null, child: Text('All')),
202+
DropdownMenuItem(value: 'cnn', child: Text('CNN')),
203+
DropdownMenuItem(value: 'reuters', child: Text('Reuters')),
204+
],
205+
onChanged: (value) {
206+
setState(() {
207+
selectedSource = value;
208+
});
209+
},
210+
),
211+
const SizedBox(height: 16),
212+
// Event Country Dropdown
213+
DropdownButtonFormField<String>(
214+
decoration: const InputDecoration(labelText: 'Event Country'),
215+
value: selectedEventCountry,
216+
items: const [
217+
// Placeholder items
218+
const DropdownMenuItem<String>(
219+
value: null, child: Text('All')),
220+
DropdownMenuItem(value: 'US', child: Text('United States')),
221+
DropdownMenuItem(value: 'UK', child: Text('United Kingdom')),
222+
DropdownMenuItem(value: 'CA', child: Text('Canada')),
223+
],
224+
onChanged: (value) {
225+
setState(() {
226+
selectedEventCountry = value;
227+
});
228+
},
229+
),
230+
const SizedBox(height: 24),
231+
ElevatedButton(
232+
onPressed: () {
233+
widget.bloc.add(
234+
HeadlinesFeedFilterChanged(
235+
category: selectedCategory,
236+
source: selectedSource,
237+
eventCountry: selectedEventCountry,
238+
),
239+
);
240+
Navigator.pop(context);
241+
},
242+
child: const Text('Apply Filters'),
243+
),
244+
const SizedBox(height: 8),
245+
TextButton(
246+
style: TextButton.styleFrom(
247+
foregroundColor: Theme.of(context).colorScheme.error,
248+
),
249+
onPressed: () {
250+
setState(() {
251+
selectedCategory = null;
252+
selectedSource = null;
253+
selectedEventCountry = null;
254+
});
255+
widget.bloc.add(
256+
const HeadlinesFeedFilterChanged(
257+
category: null,
258+
source: null,
259+
eventCountry: null,
260+
),
261+
);
262+
Navigator.pop(context);
263+
},
264+
child: const Text('Reset Filters'),
265+
),
266+
],
267+
),
237268
),
238269
),
239270
);

0 commit comments

Comments
 (0)