Skip to content

Commit 5b3b67c

Browse files
committed
refactor(content_management): replace SearchableDropdownFormField with DropdownButtonFormField
- Replace custom SearchableDropdownFormField with standard DropdownButtonFormField for country selection - Simplify the UI by removing searchable functionality and pagination - Add "None" option as the first dropdown item - Display load more option when there are more countries available
1 parent 2598648 commit 5b3b67c

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

lib/content_management/view/create_headline_page.dart

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -214,57 +214,50 @@ class _CreateHeadlineViewState extends State<_CreateHeadlineView> {
214214
.add(CreateHeadlineTopicChanged(value)),
215215
),
216216
const SizedBox(height: AppSpacing.lg),
217-
SearchableDropdownFormField<Country, CreateHeadlineBloc,
218-
CreateHeadlineState>(
219-
labelText: l10n.countryName,
220-
bloc: context.read<CreateHeadlineBloc>(),
221-
initialValue: state.eventCountry,
222-
itemsExtractor: (state) => state.countries,
223-
hasMoreExtractor: (state) => state.countriesHasMore,
224-
isLoadingExtractor: (state) =>
225-
state.status == CreateHeadlineStatus.loading,
226-
onChanged: (value) => context
227-
.read<CreateHeadlineBloc>()
228-
.add(CreateHeadlineCountryChanged(value)),
229-
onSearchChanged: (value) => context
230-
.read<CreateHeadlineBloc>()
231-
.add(CreateHeadlineCountrySearchChanged(value)),
232-
onLoadMore: () => context.read<CreateHeadlineBloc>().add(
233-
const CreateHeadlineLoadMoreCountriesRequested(),
234-
),
235-
itemBuilder: (context, country) {
236-
return ListTile(
237-
leading: SizedBox(
238-
width: 32,
239-
height: 20,
240-
child: Image.network(
241-
country.flagUrl,
242-
fit: BoxFit.cover,
243-
errorBuilder: (context, error, stackTrace) =>
244-
const Icon(Icons.flag),
217+
DropdownButtonFormField<Country?>(
218+
value: state.eventCountry,
219+
decoration: InputDecoration(
220+
labelText: l10n.countryName,
221+
border: const OutlineInputBorder(),
222+
),
223+
items: [
224+
DropdownMenuItem(value: null, child: Text(l10n.none)),
225+
...state.countries.map(
226+
(country) => DropdownMenuItem(
227+
value: country,
228+
child: Row(
229+
children: [
230+
SizedBox(
231+
width: 32,
232+
height: 20,
233+
child: Image.network(
234+
country.flagUrl,
235+
fit: BoxFit.cover,
236+
errorBuilder:
237+
(context, error, stackTrace) =>
238+
const Icon(Icons.flag),
239+
),
240+
),
241+
const SizedBox(width: AppSpacing.md),
242+
Text(country.name),
243+
],
245244
),
246245
),
247-
title: Text(country.name),
248-
);
249-
},
250-
selectedItemBuilder: (context, country) {
251-
return Row(
252-
children: [
253-
SizedBox(
254-
width: 32,
255-
height: 20,
256-
child: Image.network(
257-
country.flagUrl,
258-
fit: BoxFit.cover,
259-
errorBuilder: (context, error, stackTrace) =>
260-
const Icon(Icons.flag),
261-
),
246+
),
247+
if (state.countriesHasMore)
248+
DropdownMenuItem(
249+
value: null,
250+
child: Center(
251+
child: Text(l10n.loadMore),
262252
),
263-
const SizedBox(width: AppSpacing.md),
264-
Text(country.name),
265-
],
266-
);
267-
},
253+
onTap: () => context.read<CreateHeadlineBloc>().add(
254+
const CreateHeadlineLoadMoreCountriesRequested(),
255+
),
256+
),
257+
],
258+
onChanged: (value) => context
259+
.read<CreateHeadlineBloc>()
260+
.add(CreateHeadlineCountryChanged(value)),
268261
),
269262
const SizedBox(height: AppSpacing.lg),
270263
DropdownButtonFormField<ContentStatus>(

0 commit comments

Comments
 (0)