Skip to content

Commit 7d5ca25

Browse files
committed
feat(search): Localize search model type dropdown
- Localized dropdown menu - Added dynamic hint text
1 parent c293e0d commit 7d5ca25

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

lib/headlines-search/view/headlines_search_page.dart

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,27 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
122122
color: appBarTheme.iconTheme?.color ?? colorScheme.onSurface,
123123
),
124124
items: SearchModelType.values.map((SearchModelType type) {
125+
String displayLocalizedName;
126+
switch (type) {
127+
case SearchModelType.headline:
128+
displayLocalizedName = l10n.searchModelTypeHeadline;
129+
break;
130+
case SearchModelType.category:
131+
displayLocalizedName = l10n.searchModelTypeCategory;
132+
break;
133+
case SearchModelType.source:
134+
displayLocalizedName = l10n.searchModelTypeSource;
135+
break;
136+
case SearchModelType.country:
137+
displayLocalizedName = l10n.searchModelTypeCountry;
138+
break;
139+
}
125140
return DropdownMenuItem<SearchModelType>(
126141
value: type,
127142
child: Text(
128-
type.displayName, // Using the new getter
129-
// Ensure text color contrasts with dropdownColor
143+
displayLocalizedName,
130144
style: appBarTheme.titleTextStyle?.copyWith(
131-
color: colorScheme.onSurface, // Example color
145+
color: colorScheme.onSurface,
132146
) ??
133147
theme.textTheme.titleLarge?.copyWith(
134148
color: colorScheme.onSurface,
@@ -144,9 +158,7 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
144158
context
145159
.read<HeadlinesSearchBloc>()
146160
.add(HeadlinesSearchModelTypeChanged(newValue));
147-
if (_textController.text.isNotEmpty) {
148-
_performSearch(); // Re-trigger search with new model type
149-
}
161+
// DO NOT automatically perform search here
150162
}
151163
},
152164
),
@@ -155,7 +167,7 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
155167
controller: _textController,
156168
style: appBarTheme.titleTextStyle ?? theme.textTheme.titleLarge,
157169
decoration: InputDecoration(
158-
hintText: l10n.headlinesSearchHintText,
170+
hintText: _getHintTextForModelType(_selectedModelType, l10n),
159171
hintStyle: (appBarTheme.titleTextStyle ??
160172
theme.textTheme.titleLarge)
161173
?.copyWith(color: colorScheme.onSurface.withAlpha(153)),
@@ -277,4 +289,17 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
277289
),
278290
);
279291
}
292+
293+
String _getHintTextForModelType(SearchModelType modelType, AppLocalizations l10n) {
294+
switch (modelType) {
295+
case SearchModelType.headline:
296+
return l10n.searchHintTextHeadline;
297+
case SearchModelType.category:
298+
return l10n.searchHintTextCategory;
299+
case SearchModelType.source:
300+
return l10n.searchHintTextSource;
301+
case SearchModelType.country:
302+
return l10n.searchHintTextCountry;
303+
}
304+
}
280305
}

0 commit comments

Comments
 (0)