1
1
//
2
- // ignore_for_file: lines_longer_than_80_chars
2
+ // ignore_for_file: lines_longer_than_80_chars, public_member_api_docs
3
3
4
4
import 'package:flutter/material.dart' ;
5
5
import 'package:flutter_bloc/flutter_bloc.dart' ;
@@ -10,7 +10,12 @@ import 'package:ht_main/l10n/l10n.dart';
10
10
import 'package:ht_main/router/routes.dart' ;
11
11
import 'package:ht_main/shared/constants/constants.dart' ;
12
12
import 'package:ht_shared/ht_shared.dart'
13
- show Category, Source; // Import models from ht_shared, Country removed
13
+ show Category, Source, SourceType;
14
+
15
+ // Keys for passing data to/from SourceFilterPage
16
+ const String keySelectedSources = 'selectedSources' ;
17
+ const String keySelectedCountryIsoCodes = 'selectedCountryIsoCodes' ;
18
+ const String keySelectedSourceTypes = 'selectedSourceTypes' ;
14
19
15
20
/// {@template headlines_filter_page}
16
21
/// A full-screen dialog page for selecting headline filters.
@@ -35,7 +40,9 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
35
40
/// and are only applied back to the BLoC when the user taps 'Apply'.
36
41
late List <Category > _tempSelectedCategories;
37
42
late List <Source > _tempSelectedSources;
38
- // late List<Country> _tempSelectedCountries; // Removed
43
+ // State for source filter capsules, to be passed to and from SourceFilterPage
44
+ late Set <String > _tempSelectedSourceCountryIsoCodes;
45
+ late Set <SourceType > _tempSelectedSourceSourceTypes;
39
46
40
47
@override
41
48
void initState () {
@@ -48,15 +55,18 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
48
55
// Create copies of the lists to avoid modifying the BLoC state directly.
49
56
_tempSelectedCategories = List .from (currentState.filter.categories ?? []);
50
57
_tempSelectedSources = List .from (currentState.filter.sources ?? []);
51
- // _tempSelectedCountries = List.from(
52
- // currentState.filter.eventCountries ?? [],
53
- // ); // Removed
58
+ // Initialize source capsule states. These are persisted here.
59
+ // For now, let's assume they start empty and are populated by SourceFilterPage's result.
60
+ // Or, if HeadlineFilter could store them, we'd get them from there.
61
+ // For this iteration, they start empty. SourceFilterPage will manage its own capsule
62
+ // state and return it.
63
+ _tempSelectedSourceCountryIsoCodes = {};
64
+ _tempSelectedSourceSourceTypes = {};
54
65
} else {
55
- // Default to empty lists if the feed isn't loaded yet. This might happen
56
- // if the filter page is accessed before the initial feed load completes.
57
66
_tempSelectedCategories = [];
58
67
_tempSelectedSources = [];
59
- // _tempSelectedCountries = []; // Removed
68
+ _tempSelectedSourceCountryIsoCodes = {};
69
+ _tempSelectedSourceSourceTypes = {};
60
70
}
61
71
}
62
72
@@ -76,8 +86,9 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
76
86
required String title,
77
87
required int selectedCount,
78
88
required String routeName,
79
- required List <dynamic > currentSelection, // Pass current temp selection
80
- required void Function (List <dynamic >? ) onResult,
89
+ // For sources, currentSelection will be a Map
90
+ required dynamic currentSelectionData,
91
+ required void Function (dynamic )? onResult, // Result can also be a Map
81
92
}) {
82
93
final l10n = context.l10n;
83
94
final allLabel = l10n.headlinesFeedFilterAllLabel;
@@ -92,21 +103,12 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
92
103
subtitle: Text (subtitle),
93
104
trailing: const Icon (Icons .chevron_right),
94
105
onTap: () async {
95
- // Navigate to the specific filter selection page (e.g., SourceFilterPage).
96
- // Use pushNamed to wait for a result when the page is popped.
97
- final result = await context.pushNamed <List <dynamic >>(
98
- routeName, // The route name for the specific filter page.
99
- // Pass the current temporary selection for this filter type
100
- // (e.g., _tempSelectedSources) to the next page. This allows
101
- // the next page to initialize its UI reflecting the current state.
102
- extra: currentSelection,
106
+ final result = await context.pushNamed <dynamic >(
107
+ routeName,
108
+ extra: currentSelectionData, // Pass the map or list
103
109
);
104
- // When the filter selection page pops (usually via its 'Apply' button),
105
- // it returns the potentially modified list of selected items.
106
- // If the result is not null (meaning the user didn't just cancel/go back),
107
- // update the corresponding temporary state list on *this* page.
108
- if (result != null ) {
109
- onResult (result); // Calls setState to update the UI here.
110
+ if (result != null && onResult != null ) {
111
+ onResult (result);
110
112
}
111
113
},
112
114
);
@@ -175,7 +177,7 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
175
177
title: l10n.headlinesFeedFilterCategoryLabel,
176
178
selectedCount: _tempSelectedCategories.length,
177
179
routeName: Routes .feedFilterCategoriesName,
178
- currentSelection : _tempSelectedCategories,
180
+ currentSelectionData : _tempSelectedCategories,
179
181
onResult: (result) {
180
182
if (result is List <Category >) {
181
183
setState (() => _tempSelectedCategories = result);
@@ -187,10 +189,21 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
187
189
title: l10n.headlinesFeedFilterSourceLabel,
188
190
selectedCount: _tempSelectedSources.length,
189
191
routeName: Routes .feedFilterSourcesName,
190
- currentSelection: _tempSelectedSources,
192
+ currentSelectionData: {
193
+ keySelectedSources: _tempSelectedSources,
194
+ keySelectedCountryIsoCodes: _tempSelectedSourceCountryIsoCodes,
195
+ keySelectedSourceTypes: _tempSelectedSourceSourceTypes,
196
+ },
191
197
onResult: (result) {
192
- if (result is List <Source >) {
193
- setState (() => _tempSelectedSources = result);
198
+ if (result is Map <String , dynamic >) {
199
+ setState (() {
200
+ _tempSelectedSources =
201
+ result[keySelectedSources] as List <Source >? ?? [];
202
+ _tempSelectedSourceCountryIsoCodes =
203
+ result[keySelectedCountryIsoCodes] as Set <String >? ?? {};
204
+ _tempSelectedSourceSourceTypes =
205
+ result[keySelectedSourceTypes] as Set <SourceType >? ?? {};
206
+ });
194
207
}
195
208
},
196
209
),
0 commit comments