Skip to content

Commit 2828084

Browse files
committed
refactor(content_management): replace SearchableDropdownFormField with DropdownButtonFormField
- Replace custom SearchableDropdownFormField with DropdownButtonFormField for country selection - Simplify the UI for better maintainability and readability - Improve performance by removing unnecessary search and load more functionality
1 parent f7ff2b7 commit 2828084

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

lib/content_management/view/edit_headline_page.dart

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -282,57 +282,50 @@ class _EditHeadlineViewState extends State<_EditHeadlineView> {
282282
.add(EditHeadlineTopicChanged(value)),
283283
),
284284
const SizedBox(height: AppSpacing.lg),
285-
SearchableDropdownFormField<Country, EditHeadlineBloc,
286-
EditHeadlineState>(
287-
labelText: l10n.countryName,
288-
bloc: context.read<EditHeadlineBloc>(),
289-
initialValue: selectedCountry,
290-
itemsExtractor: (state) => state.countries,
291-
hasMoreExtractor: (state) => state.countriesHasMore,
292-
isLoadingExtractor: (state) =>
293-
state.status == EditHeadlineStatus.loading,
294-
onChanged: (value) => context
295-
.read<EditHeadlineBloc>()
296-
.add(EditHeadlineCountryChanged(value)),
297-
onSearchChanged: (value) => context
298-
.read<EditHeadlineBloc>()
299-
.add(EditHeadlineCountrySearchChanged(value)),
300-
onLoadMore: () => context.read<EditHeadlineBloc>().add(
301-
const EditHeadlineLoadMoreCountriesRequested(),
302-
),
303-
itemBuilder: (context, country) {
304-
return ListTile(
305-
leading: SizedBox(
306-
width: 32,
307-
height: 20,
308-
child: Image.network(
309-
country.flagUrl,
310-
fit: BoxFit.cover,
311-
errorBuilder: (context, error, stackTrace) =>
312-
const Icon(Icons.flag),
285+
DropdownButtonFormField<Country?>(
286+
value: selectedCountry,
287+
decoration: InputDecoration(
288+
labelText: l10n.countryName,
289+
border: const OutlineInputBorder(),
290+
),
291+
items: [
292+
DropdownMenuItem(value: null, child: Text(l10n.none)),
293+
...state.countries.map(
294+
(country) => DropdownMenuItem(
295+
value: country,
296+
child: Row(
297+
children: [
298+
SizedBox(
299+
width: 32,
300+
height: 20,
301+
child: Image.network(
302+
country.flagUrl,
303+
fit: BoxFit.cover,
304+
errorBuilder:
305+
(context, error, stackTrace) =>
306+
const Icon(Icons.flag),
307+
),
308+
),
309+
const SizedBox(width: AppSpacing.md),
310+
Text(country.name),
311+
],
313312
),
314313
),
315-
title: Text(country.name),
316-
);
317-
},
318-
selectedItemBuilder: (context, country) {
319-
return Row(
320-
children: [
321-
SizedBox(
322-
width: 32,
323-
height: 20,
324-
child: Image.network(
325-
country.flagUrl,
326-
fit: BoxFit.cover,
327-
errorBuilder: (context, error, stackTrace) =>
328-
const Icon(Icons.flag),
329-
),
314+
),
315+
if (state.countriesHasMore)
316+
DropdownMenuItem(
317+
value: null,
318+
child: const Center(
319+
child: Text('Load More'),
330320
),
331-
const SizedBox(width: AppSpacing.md),
332-
Text(country.name),
333-
],
334-
);
335-
},
321+
onTap: () => context.read<EditHeadlineBloc>().add(
322+
const EditHeadlineLoadMoreCountriesRequested(),
323+
),
324+
),
325+
],
326+
onChanged: (value) => context
327+
.read<EditHeadlineBloc>()
328+
.add(EditHeadlineCountryChanged(value)),
336329
),
337330
const SizedBox(height: AppSpacing.lg),
338331
DropdownButtonFormField<ContentStatus>(

0 commit comments

Comments
 (0)