Skip to content

Commit a84b878

Browse files
committed
feat(content): integrate language picker into create source page
1 parent 3a67f49 commit a84b878

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/content_management/view/create_source_page.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter_news_app_web_dashboard_full_source_code/content_manageme
77
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/create_source/create_source_bloc.dart';
88
import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/edit_source/edit_source_bloc.dart';
99
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
10+
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
1011
import 'package:flutter_news_app_web_dashboard_full_source_code/shared/shared.dart';
1112
import 'package:go_router/go_router.dart';
1213
import 'package:ui_kit/ui_kit.dart';
@@ -160,15 +161,13 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
160161
.add(CreateSourceUrlChanged(value)),
161162
),
162163
const SizedBox(height: AppSpacing.lg),
163-
TextFormField(
164+
LanguagePickerFormField(
165+
labelText: l10n.language,
164166
initialValue: state.language,
165-
decoration: InputDecoration(
166-
labelText: l10n.language,
167-
border: const OutlineInputBorder(),
168-
),
169-
onChanged: (value) => context
170-
.read<CreateSourceBloc>()
171-
.add(CreateSourceLanguageChanged(value)),
167+
onChanged: (language) =>
168+
context.read<CreateSourceBloc>().add(
169+
CreateSourceLanguageChanged(language),
170+
),
172171
),
173172
const SizedBox(height: AppSpacing.lg),
174173
DropdownButtonFormField<SourceType?>(

lib/shared/widgets/language_picker_form_field.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ class LanguagePickerFormField extends FormField<language_picker.Language> {
1414
/// standard [FormField] properties.
1515
///
1616
/// The [labelText] is displayed as the input field's label.
17+
/// The [onChanged] callback is invoked when a new language is selected.
1718
LanguagePickerFormField({
1819
super.key,
1920
super.onSaved,
2021
super.validator,
2122
super.initialValue,
2223
super.autovalidateMode,
2324
String? labelText,
25+
void Function(language_picker.Language)? onChanged,
2426
}) : super(
2527
builder: (FormFieldState<language_picker.Language> state) {
2628
// This controller is just for displaying the text. The actual
@@ -46,6 +48,9 @@ class LanguagePickerFormField extends FormField<language_picker.Language> {
4648
state.value ?? language_picker.Languages.english,
4749
onValuePicked: (language_picker.Language language) {
4850
state.didChange(language);
51+
if (onChanged != null) {
52+
onChanged(language);
53+
}
4954
// Update the text in the read-only text field.
5055
controller.text = language.name;
5156
},

0 commit comments

Comments
 (0)