Skip to content

Commit 3167aa9

Browse files
committed
refactor(content_management): replace CountryPickerFormField with CountryDropdownFormField
- Remove unused import of country_picker package - Replace CountryPickerFormField with CountryDropdownFormField for better usability - Update country selection logic to use Country objects directly instead of adapting from core package - Improve error handling when matching selected country with available countries
1 parent 929d752 commit 3167aa9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lib/content_management/view/edit_headline_page.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:core/core.dart';
2-
import 'package:country_picker/country_picker.dart' as picker;
32
import 'package:data_repository/data_repository.dart';
43
import 'package:flutter/material.dart';
54
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -179,6 +178,17 @@ class _EditHeadlineViewState extends State<_EditHeadlineView> {
179178
}
180179
}
181180

181+
Country? selectedCountry;
182+
if (state.eventCountry != null) {
183+
try {
184+
selectedCountry = state.countries.firstWhere(
185+
(c) => c.id == state.eventCountry!.id,
186+
);
187+
} catch (_) {
188+
selectedCountry = null;
189+
}
190+
}
191+
182192
return SingleChildScrollView(
183193
child: Padding(
184194
padding: const EdgeInsets.all(AppSpacing.lg),
@@ -272,18 +282,13 @@ class _EditHeadlineViewState extends State<_EditHeadlineView> {
272282
.add(EditHeadlineTopicChanged(value)),
273283
),
274284
const SizedBox(height: AppSpacing.lg),
275-
CountryPickerFormField(
285+
CountryDropdownFormField(
276286
labelText: l10n.countryName,
277-
initialValue: state.eventCountry != null
278-
? adaptCoreCountryToPackageCountry(
279-
state.eventCountry!,
280-
)
281-
: null,
282-
onChanged: (picker.Country country) {
283-
context.read<EditHeadlineBloc>().add(
284-
EditHeadlineCountryChanged(country),
285-
);
286-
},
287+
countries: state.countries,
288+
initialValue: selectedCountry,
289+
onChanged: (value) => context
290+
.read<EditHeadlineBloc>()
291+
.add(EditHeadlineCountryChanged(value)),
287292
),
288293
const SizedBox(height: AppSpacing.lg),
289294
DropdownButtonFormField<ContentStatus>(

0 commit comments

Comments
 (0)