@@ -3,10 +3,9 @@ import 'package:data_repository/data_repository.dart';
33import 'package:flutter/material.dart' ;
44import 'package:flutter_bloc/flutter_bloc.dart' ;
55import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/edit_source/edit_source_bloc.dart' ;
6- import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/bloc/searchable_paginated_dropdown/searchable_paginated_dropdown_bloc.dart' ;
7- import 'package:flutter_news_app_web_dashboard_full_source_code/content_management/view/widgets/searchable_paginated_dropdown.dart' ;
86import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart' ;
97import 'package:flutter_news_app_web_dashboard_full_source_code/shared/shared.dart' ;
8+ import 'package:flutter_news_app_web_dashboard_full_source_code/shared/widgets/searchable_selection_input.dart' ;
109import 'package:go_router/go_router.dart' ;
1110import 'package:ui_kit/ui_kit.dart' ;
1211
@@ -188,114 +187,84 @@ class _EditSourceViewState extends State<_EditSourceView> {
188187 ),
189188 ),
190189 const SizedBox (height: AppSpacing .lg),
191- BlocProvider <SearchablePaginatedDropdownBloc <Language >>(
192- create: (context) =>
193- SearchablePaginatedDropdownBloc <Language >(
194- repository: context
195- .read <DataRepository <Language >>(),
196- filterBuilder: (searchTerm) => searchTerm == null
197- ? {}
198- : {
199- 'name' : {
200- r'$regex' : searchTerm,
201- r'$options' : 'i' ,
202- },
203- },
204- sortOptions: const [
205- SortOption ('name' , SortOrder .asc),
206- ],
207- limit: kDefaultRowsPerPage,
208- initialSelectedItem: state.language,
209- ),
210- child: SearchablePaginatedDropdown <Language >(
211- label: l10n.language,
212- selectedItem: state.language,
213- itemBuilder: (context, language) => Text (language.name),
214- itemToString: (language) => language.name,
215- onChanged: (value) =>
216- context.read <EditSourceBloc >().add (
217- EditSourceLanguageChanged (value),
218- ),
219- ),
190+ SearchableSelectionInput <Language >(
191+ label: l10n.language,
192+ selectedItem: state.language,
193+ itemBuilder: (context, language) => Text (language.name),
194+ itemToString: (language) => language.name,
195+ onChanged: (value) => context
196+ .read <EditSourceBloc >()
197+ .add (EditSourceLanguageChanged (value)),
198+ repository: context.read <DataRepository <Language >>(),
199+ filterBuilder: (searchTerm) => searchTerm == null
200+ ? {}
201+ : {
202+ 'name' : {
203+ r'$regex' : searchTerm,
204+ r'$options' : 'i' ,
205+ },
206+ },
207+ sortOptions: const [
208+ SortOption ('name' , SortOrder .asc),
209+ ],
210+ limit: kDefaultRowsPerPage,
220211 ),
221212 const SizedBox (height: AppSpacing .lg),
222- DropdownButtonFormField <SourceType ?>(
223- value: state.sourceType,
224- decoration: InputDecoration (
225- labelText: l10n.sourceType,
226- border: const OutlineInputBorder (),
227- ),
228- items: [
229- DropdownMenuItem (value: null , child: Text (l10n.none)),
230- ...SourceType .values.map (
231- (type) => DropdownMenuItem (
232- value: type,
233- child: Text (type.localizedName (l10n)),
234- ),
235- ),
236- ],
237- onChanged: (value) => context.read <EditSourceBloc >().add (
238- EditSourceTypeChanged (value),
239- ),
213+ SearchableSelectionInput <SourceType >(
214+ label: l10n.sourceType,
215+ selectedItem: state.sourceType,
216+ staticItems: SourceType .values.toList (),
217+ itemBuilder: (context, type) => Text (type.localizedName (l10n)),
218+ itemToString: (type) => type.localizedName (l10n),
219+ onChanged: (value) => context
220+ .read <EditSourceBloc >()
221+ .add (EditSourceTypeChanged (value)),
240222 ),
241223 const SizedBox (height: AppSpacing .lg),
242- BlocProvider <SearchablePaginatedDropdownBloc <Country >>(
243- create: (context) =>
244- SearchablePaginatedDropdownBloc <Country >(
245- repository: context.read <DataRepository <Country >>(),
246- filterBuilder: (searchTerm) => searchTerm == null
247- ? {}
248- : {
249- 'name' : {
250- r'$regex' : searchTerm,
251- r'$options' : 'i' ,
252- },
253- },
254- sortOptions: const [
255- SortOption ('name' , SortOrder .asc),
256- ],
257- limit: kDefaultRowsPerPage,
258- initialSelectedItem: state.headquarters,
259- ),
260- child: SearchablePaginatedDropdown <Country >(
261- label: l10n.headquarters,
262- selectedItem: state.headquarters,
263- itemBuilder: (context, country) => Row (
264- children: [
265- SizedBox (
266- width: 32 ,
267- height: 20 ,
268- child: Image .network (
269- country.flagUrl,
270- fit: BoxFit .cover,
271- errorBuilder: (context, error, stackTrace) =>
272- const Icon (Icons .flag),
273- ),
274- ),
275- const SizedBox (width: AppSpacing .md),
276- Text (country.name),
277- ],
278- ),
279- itemToString: (country) => country.name,
280- onChanged: (value) =>
281- context.read <EditSourceBloc >().add (
282- EditSourceHeadquartersChanged (value),
224+ SearchableSelectionInput <Country >(
225+ label: l10n.headquarters,
226+ selectedItem: state.headquarters,
227+ itemBuilder: (context, country) => Row (
228+ children: [
229+ SizedBox (
230+ width: 32 ,
231+ height: 20 ,
232+ child: Image .network (
233+ country.flagUrl,
234+ fit: BoxFit .cover,
235+ errorBuilder: (context, error, stackTrace) =>
236+ const Icon (Icons .flag),
283237 ),
238+ ),
239+ const SizedBox (width: AppSpacing .md),
240+ Text (country.name),
241+ ],
284242 ),
243+ itemToString: (country) => country.name,
244+ onChanged: (value) => context
245+ .read <EditSourceBloc >()
246+ .add (EditSourceHeadquartersChanged (value)),
247+ repository: context.read <DataRepository <Country >>(),
248+ filterBuilder: (searchTerm) => searchTerm == null
249+ ? {}
250+ : {
251+ 'name' : {
252+ r'$regex' : searchTerm,
253+ r'$options' : 'i' ,
254+ },
255+ },
256+ sortOptions: const [
257+ SortOption ('name' , SortOrder .asc),
258+ ],
259+ limit: kDefaultRowsPerPage,
285260 ),
286261 const SizedBox (height: AppSpacing .lg),
287- DropdownButtonFormField <ContentStatus >(
288- value: state.contentStatus,
289- decoration: InputDecoration (
290- labelText: l10n.status,
291- border: const OutlineInputBorder (),
292- ),
293- items: ContentStatus .values.map ((status) {
294- return DropdownMenuItem (
295- value: status,
296- child: Text (status.l10n (context)),
297- );
298- }).toList (),
262+ SearchableSelectionInput <ContentStatus >(
263+ label: l10n.status,
264+ selectedItem: state.contentStatus,
265+ staticItems: ContentStatus .values.toList (),
266+ itemBuilder: (context, status) => Text (status.l10n (context)),
267+ itemToString: (status) => status.l10n (context),
299268 onChanged: (value) {
300269 if (value == null ) return ;
301270 context.read <EditSourceBloc >().add (
0 commit comments