Skip to content

Commit 1b57cde

Browse files
committed
feat(router): add multi-select search page route
- Add new route for reusable multi-select search page - Update Routes class with new multiSelectSearchName constant - Implement builder function for multi-select search page - Allow customization of title, items, and initial selections - Add support for custom item builder function
1 parent eb02682 commit 1b57cde

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/router/router.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/settings/view/no
5050
import 'package:flutter_news_app_mobile_client_full_source_code/settings/view/settings_page.dart';
5151
import 'package:flutter_news_app_mobile_client_full_source_code/settings/view/theme_settings_page.dart';
5252
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/feed_decorator_service.dart';
53+
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/multi_select_search_page.dart';
5354
import 'package:go_router/go_router.dart';
5455
import 'package:logging/logging.dart';
5556

@@ -339,6 +340,35 @@ GoRouter createRouter({
339340
);
340341
},
341342
),
343+
// --- Reusable Multi-Select Search Page Route (Top Level) ---
344+
// This route provides a generic UI for selecting multiple items from a
345+
// searchable list. It is used by other pages (like the source filter)
346+
// to offload the complexity of list selection.
347+
GoRoute(
348+
path: '/multi-select-search',
349+
name: Routes.multiSelectSearchName,
350+
builder: (context, state) {
351+
final extra = state.extra as Map<String, dynamic>? ?? {};
352+
final title = extra['title'] as String? ?? 'Select';
353+
final allItems = extra['allItems'] as List<dynamic>? ?? [];
354+
final initialSelectedItems =
355+
extra['initialSelectedItems'] as Set<dynamic>? ?? {};
356+
// The itemBuilder is passed as a function to display the item name.
357+
final itemBuilder = extra['itemBuilder'] as String Function(
358+
dynamic item,
359+
)? ??
360+
(item) => item.toString();
361+
362+
// Since this is a generic page, we pass the dynamic types directly.
363+
// The calling page is responsible for casting the result.
364+
return MultiSelectSearchPage<dynamic>(
365+
title: title,
366+
allItems: allItems,
367+
initialSelectedItems: initialSelectedItems,
368+
itemBuilder: itemBuilder,
369+
);
370+
},
371+
),
342372
// --- Main App Shell ---
343373
StatefulShellRoute.indexedStack(
344374
builder: (context, state, navigationShell) {

lib/router/routes.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ abstract final class Routes {
2727
static const entityDetailsName = 'entityDetails';
2828
static const globalArticleDetails = '/article/:id';
2929
static const globalArticleDetailsName = 'globalArticleDetails';
30+
static const multiSelectSearchName = 'multiSelectSearch';
3031

3132
// --- Feed Sub-Routes ---
3233
static const articleDetailsName = 'articleDetails';

0 commit comments

Comments
 (0)