@@ -25,10 +25,9 @@ class EditHeadlinePage extends StatelessWidget {
2525 // The list of all countries is fetched once and cached in the
2626 // ContentManagementBloc. We read it here and provide it to the
2727 // EditHeadlineBloc.
28- final allCountries = context
29- .read <ContentManagementBloc >()
30- .state
31- .allCountries;
28+ final contentManagementState = context.watch <ContentManagementBloc >().state;
29+ final allCountries = contentManagementState.allCountries;
30+
3231 return BlocProvider (
3332 create: (context) => EditHeadlineBloc (
3433 headlinesRepository: context.read <DataRepository <Headline >>(),
@@ -289,40 +288,53 @@ class _EditHeadlineViewState extends State<_EditHeadlineView> {
289288 .add (EditHeadlineTopicChanged (value)),
290289 ),
291290 const SizedBox (height: AppSpacing .lg),
292- DropdownButtonFormField <Country ?>(
293- value: selectedCountry,
294- decoration: InputDecoration (
295- labelText: l10n.countryName,
296- border: const OutlineInputBorder (),
297- ),
298- items: [
299- DropdownMenuItem (value: null , child: Text (l10n.none)),
300- ...state.countries.map (
301- (country) => DropdownMenuItem (
302- value: country,
303- child: Row (
304- children: [
305- SizedBox (
306- width: 32 ,
307- height: 20 ,
308- child: Image .network (
309- country.flagUrl,
310- fit: BoxFit .cover,
311- errorBuilder:
312- (context, error, stackTrace) =>
313- const Icon (Icons .flag),
314- ),
291+ BlocBuilder <ContentManagementBloc , ContentManagementState >(
292+ builder: (context, contentState) {
293+ final isLoading = contentState.allCountriesStatus ==
294+ ContentManagementStatus .loading;
295+ return DropdownButtonFormField <Country ?>(
296+ value: selectedCountry,
297+ decoration: InputDecoration (
298+ labelText: l10n.countryName,
299+ border: const OutlineInputBorder (),
300+ helperText:
301+ isLoading ? l10n.loadingFullList : null ,
302+ ),
303+ items: [
304+ DropdownMenuItem (
305+ value: null ,
306+ child: Text (l10n.none),
307+ ),
308+ ...state.countries.map (
309+ (country) => DropdownMenuItem (
310+ value: country,
311+ child: Row (
312+ children: [
313+ SizedBox (
314+ width: 32 ,
315+ height: 20 ,
316+ child: Image .network (
317+ country.flagUrl,
318+ fit: BoxFit .cover,
319+ errorBuilder:
320+ (context, error, stackTrace) =>
321+ const Icon (Icons .flag),
322+ ),
323+ ),
324+ const SizedBox (width: AppSpacing .md),
325+ Text (country.name),
326+ ],
315327 ),
316- const SizedBox (width: AppSpacing .md),
317- Text (country.name),
318- ],
328+ ),
319329 ),
320- ),
321- ),
322- ],
323- onChanged: (value) => context
324- .read <EditHeadlineBloc >()
325- .add (EditHeadlineCountryChanged (value)),
330+ ],
331+ onChanged: isLoading
332+ ? null
333+ : (value) => context
334+ .read <EditHeadlineBloc >()
335+ .add (EditHeadlineCountryChanged (value)),
336+ );
337+ },
326338 ),
327339 const SizedBox (height: AppSpacing .lg),
328340 DropdownButtonFormField <ContentStatus >(
0 commit comments