@@ -15,11 +15,11 @@ class HeadlinesSearchBloc
15
15
required HtDataRepository <Category > categoryRepository,
16
16
required HtDataRepository <Source > sourceRepository,
17
17
required HtDataRepository <Country > countryRepository,
18
- }) : _headlinesRepository = headlinesRepository,
19
- _categoryRepository = categoryRepository,
20
- _sourceRepository = sourceRepository,
21
- _countryRepository = countryRepository,
22
- super (const HeadlinesSearchInitial ()) {
18
+ }) : _headlinesRepository = headlinesRepository,
19
+ _categoryRepository = categoryRepository,
20
+ _sourceRepository = sourceRepository,
21
+ _countryRepository = countryRepository,
22
+ super (const HeadlinesSearchInitial ()) {
23
23
on < HeadlinesSearchModelTypeChanged > (_onHeadlinesSearchModelTypeChanged);
24
24
on < HeadlinesSearchFetchRequested > (
25
25
_onSearchFetchRequested,
@@ -38,13 +38,15 @@ class HeadlinesSearchBloc
38
38
Emitter <HeadlinesSearchState > emit,
39
39
) async {
40
40
// If there's an active search term, re-trigger search with new model type
41
- final currentSearchTerm = state is HeadlinesSearchLoading
42
- ? (state as HeadlinesSearchLoading ).lastSearchTerm
43
- : state is HeadlinesSearchSuccess
41
+ // ignore: unused_local_variable
42
+ final currentSearchTerm =
43
+ state is HeadlinesSearchLoading
44
+ ? (state as HeadlinesSearchLoading ).lastSearchTerm
45
+ : state is HeadlinesSearchSuccess
44
46
? (state as HeadlinesSearchSuccess ).lastSearchTerm
45
47
: state is HeadlinesSearchFailure
46
- ? (state as HeadlinesSearchFailure ).lastSearchTerm
47
- : null ;
48
+ ? (state as HeadlinesSearchFailure ).lastSearchTerm
49
+ : null ;
48
50
49
51
emit (HeadlinesSearchInitial (selectedModelType: event.newModelType));
50
52
@@ -119,42 +121,44 @@ class HeadlinesSearchBloc
119
121
emit (successState.copyWith (errorMessage: e.message));
120
122
} catch (e, st) {
121
123
print ('Search pagination error ($modelType ): $e \n $st ' );
122
- emit (successState. copyWith (
123
- errorMessage: 'Failed to load more results.' ,
124
- )) ;
124
+ emit (
125
+ successState. copyWith ( errorMessage: 'Failed to load more results.' ) ,
126
+ );
125
127
}
126
128
return ;
127
129
}
128
130
}
129
131
130
132
// New search
131
- emit (HeadlinesSearchLoading (
132
- lastSearchTerm: searchTerm,
133
- selectedModelType: modelType,
134
- ));
133
+ emit (
134
+ HeadlinesSearchLoading (
135
+ lastSearchTerm: searchTerm,
136
+ selectedModelType: modelType,
137
+ ),
138
+ );
135
139
try {
136
140
PaginatedResponse <dynamic > response;
137
141
switch (modelType) {
138
142
case SearchModelType .headline:
139
- response = await _headlinesRepository.readAllByQuery (
140
- { 'q' : searchTerm, 'model' : modelType. toJson ()} ,
141
- limit : _limit ,
142
- );
143
+ response = await _headlinesRepository.readAllByQuery ({
144
+ 'q' : searchTerm,
145
+ 'model' : modelType. toJson () ,
146
+ }, limit : _limit, );
143
147
case SearchModelType .category:
144
- response = await _categoryRepository.readAllByQuery (
145
- { 'q' : searchTerm, 'model' : modelType. toJson ()} ,
146
- limit : _limit ,
147
- );
148
+ response = await _categoryRepository.readAllByQuery ({
149
+ 'q' : searchTerm,
150
+ 'model' : modelType. toJson () ,
151
+ }, limit : _limit, );
148
152
case SearchModelType .source:
149
- response = await _sourceRepository.readAllByQuery (
150
- { 'q' : searchTerm, 'model' : modelType. toJson ()} ,
151
- limit : _limit ,
152
- );
153
+ response = await _sourceRepository.readAllByQuery ({
154
+ 'q' : searchTerm,
155
+ 'model' : modelType. toJson () ,
156
+ }, limit : _limit, );
153
157
case SearchModelType .country:
154
- response = await _countryRepository.readAllByQuery (
155
- { 'q' : searchTerm, 'model' : modelType. toJson ()} ,
156
- limit : _limit ,
157
- );
158
+ response = await _countryRepository.readAllByQuery ({
159
+ 'q' : searchTerm,
160
+ 'model' : modelType. toJson () ,
161
+ }, limit : _limit, );
158
162
}
159
163
emit (
160
164
HeadlinesSearchSuccess (
0 commit comments