Skip to content

Commit b0b3e59

Browse files
committed
refactor(content_management): replace SearchableDropdownFormField with DropdownButtonFormField
- Replace SearchableDropdownFormField for language and headquarters selection with DropdownButtonFormField - Add support for loading more items in the dropdown menu - Improve UI by using a standard dropdown approach
1 parent beec0e6 commit b0b3e59

File tree

1 file changed

+66
-71
lines changed

1 file changed

+66
-71
lines changed

lib/content_management/view/create_source_page.dart

Lines changed: 66 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,34 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
161161
.add(CreateSourceUrlChanged(value)),
162162
),
163163
const SizedBox(height: AppSpacing.lg),
164-
SearchableDropdownFormField<Language, CreateSourceBloc,
165-
CreateSourceState>(
166-
labelText: l10n.language,
167-
bloc: context.read<CreateSourceBloc>(),
168-
initialValue: state.language,
169-
itemsExtractor: (state) => state.languages,
170-
hasMoreExtractor: (state) => state.languagesHasMore,
171-
isLoadingExtractor: (state) =>
172-
state.status == CreateSourceStatus.loading,
164+
DropdownButtonFormField<Language?>(
165+
value: state.language,
166+
decoration: InputDecoration(
167+
labelText: l10n.language,
168+
border: const OutlineInputBorder(),
169+
),
170+
items: [
171+
DropdownMenuItem(value: null, child: Text(l10n.none)),
172+
...state.languages.map(
173+
(language) => DropdownMenuItem(
174+
value: language,
175+
child: Text(language.name),
176+
),
177+
),
178+
if (state.languagesHasMore)
179+
DropdownMenuItem(
180+
value: null,
181+
child: const Center(
182+
child: Text('Load More'),
183+
),
184+
onTap: () => context.read<CreateSourceBloc>().add(
185+
const CreateSourceLoadMoreLanguagesRequested(),
186+
),
187+
),
188+
],
173189
onChanged: (value) => context
174190
.read<CreateSourceBloc>()
175191
.add(CreateSourceLanguageChanged(value)),
176-
onSearchChanged: (value) => context
177-
.read<CreateSourceBloc>()
178-
.add(CreateSourceLanguageSearchChanged(value)),
179-
onLoadMore: () => context.read<CreateSourceBloc>().add(
180-
const CreateSourceLoadMoreLanguagesRequested(),
181-
),
182-
itemBuilder: (context, language) {
183-
return ListTile(
184-
title: Text(language.name),
185-
);
186-
},
187-
selectedItemBuilder: (context, language) {
188-
return Text(language.name);
189-
},
190192
),
191193
const SizedBox(height: AppSpacing.lg),
192194
DropdownButtonFormField<SourceType?>(
@@ -209,57 +211,50 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
209211
.add(CreateSourceTypeChanged(value)),
210212
),
211213
const SizedBox(height: AppSpacing.lg),
212-
SearchableDropdownFormField<Country, CreateSourceBloc,
213-
CreateSourceState>(
214-
labelText: l10n.headquarters,
215-
bloc: context.read<CreateSourceBloc>(),
216-
initialValue: state.headquarters,
217-
itemsExtractor: (state) => state.countries,
218-
hasMoreExtractor: (state) => state.countriesHasMore,
219-
isLoadingExtractor: (state) =>
220-
state.status == CreateSourceStatus.loading,
221-
onChanged: (value) => context
222-
.read<CreateSourceBloc>()
223-
.add(CreateSourceHeadquartersChanged(value)),
224-
onSearchChanged: (value) => context
225-
.read<CreateSourceBloc>()
226-
.add(CreateSourceCountrySearchChanged(value)),
227-
onLoadMore: () => context.read<CreateSourceBloc>().add(
228-
const CreateSourceLoadMoreCountriesRequested(),
229-
),
230-
itemBuilder: (context, country) {
231-
return ListTile(
232-
leading: SizedBox(
233-
width: 32,
234-
height: 20,
235-
child: Image.network(
236-
country.flagUrl,
237-
fit: BoxFit.cover,
238-
errorBuilder: (context, error, stackTrace) =>
239-
const Icon(Icons.flag),
214+
DropdownButtonFormField<Country?>(
215+
value: state.headquarters,
216+
decoration: InputDecoration(
217+
labelText: l10n.headquarters,
218+
border: const OutlineInputBorder(),
219+
),
220+
items: [
221+
DropdownMenuItem(value: null, child: Text(l10n.none)),
222+
...state.countries.map(
223+
(country) => DropdownMenuItem(
224+
value: country,
225+
child: Row(
226+
children: [
227+
SizedBox(
228+
width: 32,
229+
height: 20,
230+
child: Image.network(
231+
country.flagUrl,
232+
fit: BoxFit.cover,
233+
errorBuilder:
234+
(context, error, stackTrace) =>
235+
const Icon(Icons.flag),
236+
),
237+
),
238+
const SizedBox(width: AppSpacing.md),
239+
Text(country.name),
240+
],
240241
),
241242
),
242-
title: Text(country.name),
243-
);
244-
},
245-
selectedItemBuilder: (context, country) {
246-
return Row(
247-
children: [
248-
SizedBox(
249-
width: 32,
250-
height: 20,
251-
child: Image.network(
252-
country.flagUrl,
253-
fit: BoxFit.cover,
254-
errorBuilder: (context, error, stackTrace) =>
255-
const Icon(Icons.flag),
256-
),
243+
),
244+
if (state.countriesHasMore)
245+
DropdownMenuItem(
246+
value: null,
247+
child: const Center(
248+
child: Text('Load More'),
257249
),
258-
const SizedBox(width: AppSpacing.md),
259-
Text(country.name),
260-
],
261-
);
262-
},
250+
onTap: () => context.read<CreateSourceBloc>().add(
251+
const CreateSourceLoadMoreCountriesRequested(),
252+
),
253+
),
254+
],
255+
onChanged: (value) => context
256+
.read<CreateSourceBloc>()
257+
.add(CreateSourceHeadquartersChanged(value)),
263258
),
264259
const SizedBox(height: AppSpacing.lg),
265260
DropdownButtonFormField<ContentStatus>(

0 commit comments

Comments
 (0)