1
1
part of 'headlines_search_bloc.dart' ;
2
2
3
3
abstract class HeadlinesSearchState extends Equatable {
4
- const HeadlinesSearchState ();
5
- // lastSearchTerm will be defined in specific states that need it.
4
+ const HeadlinesSearchState ({
5
+ this .selectedModelType = SearchModelType .headline,
6
+ });
7
+
8
+ final SearchModelType selectedModelType;
9
+
6
10
@override
7
- List <Object ?> get props => [];
11
+ List <Object ?> get props => [selectedModelType ];
8
12
}
9
13
10
14
/// Initial state before any search is performed.
11
15
class HeadlinesSearchInitial extends HeadlinesSearchState {
12
- const HeadlinesSearchInitial ();
13
- // No lastSearchTerm needed for initial state.
16
+ const HeadlinesSearchInitial ({super .selectedModelType});
14
17
}
15
18
16
19
/// State when a search is actively in progress.
17
20
class HeadlinesSearchLoading extends HeadlinesSearchState {
18
- const HeadlinesSearchLoading ({this .lastSearchTerm});
19
- final String ? lastSearchTerm; // Term being loaded
21
+ const HeadlinesSearchLoading ({
22
+ required this .lastSearchTerm,
23
+ required super .selectedModelType,
24
+ });
25
+ final String lastSearchTerm; // Term being loaded
20
26
21
27
@override
22
- List <Object ?> get props => [lastSearchTerm];
28
+ List <Object ?> get props => [... super .props, lastSearchTerm];
23
29
}
24
30
25
31
/// State when a search has successfully returned results.
26
32
class HeadlinesSearchSuccess extends HeadlinesSearchState {
27
33
const HeadlinesSearchSuccess ({
28
- required this .headlines ,
34
+ required this .results ,
29
35
required this .hasMore,
30
36
required this .lastSearchTerm,
37
+ required super .selectedModelType, // The model type for these results
31
38
this .cursor,
32
39
this .errorMessage, // For non-critical errors like pagination failure
33
40
});
34
41
35
- final List <Headline > headlines;
42
+ final List <dynamic > results; // Can hold Headline, Category, Source, Country
36
43
final bool hasMore;
37
44
final String ? cursor;
38
45
final String ? errorMessage; // e.g., for pagination errors
39
46
final String lastSearchTerm; // The term that yielded these results
40
47
41
48
HeadlinesSearchSuccess copyWith ({
42
- List <Headline >? headlines ,
49
+ List <dynamic >? results ,
43
50
bool ? hasMore,
44
51
String ? cursor,
45
- String ? errorMessage, // Allow clearing/setting error
52
+ String ? errorMessage,
46
53
String ? lastSearchTerm,
54
+ SearchModelType ? selectedModelType,
47
55
bool clearErrorMessage = false ,
48
56
}) {
49
57
return HeadlinesSearchSuccess (
50
- headlines : headlines ?? this .headlines ,
58
+ results : results ?? this .results ,
51
59
hasMore: hasMore ?? this .hasMore,
52
60
cursor: cursor ?? this .cursor,
53
61
errorMessage:
54
62
clearErrorMessage ? null : errorMessage ?? this .errorMessage,
55
63
lastSearchTerm: lastSearchTerm ?? this .lastSearchTerm,
64
+ selectedModelType: selectedModelType ?? this .selectedModelType,
56
65
);
57
66
}
58
67
59
68
@override
60
69
List <Object ?> get props => [
61
- headlines,
70
+ ...super .props,
71
+ results,
62
72
hasMore,
63
73
cursor,
64
74
errorMessage,
@@ -71,11 +81,12 @@ class HeadlinesSearchFailure extends HeadlinesSearchState {
71
81
const HeadlinesSearchFailure ({
72
82
required this .errorMessage,
73
83
required this .lastSearchTerm,
84
+ required super .selectedModelType,
74
85
});
75
86
76
87
final String errorMessage;
77
88
final String lastSearchTerm; // The term that failed
78
89
79
90
@override
80
- List <Object ?> get props => [errorMessage, lastSearchTerm];
91
+ List <Object ?> get props => [... super .props, errorMessage, lastSearchTerm];
81
92
}
0 commit comments