Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Share settings search

Neeraj Gupta472c831a5c45
diff --git a/mobile/apps/locker/lib/ui/drawer/drawer_page.dart b/mobile/apps/locker/lib/ui/drawer/drawer_page.dart
index e106cc3df0..d41e4919c9 100644
--- a/mobile/apps/locker/lib/ui/drawer/drawer_page.dart
+++ b/mobile/apps/locker/lib/ui/drawer/drawer_page.dart
@@ -1,12 +1,13 @@
import "package:ente_components/ente_components.dart";
import "package:ente_sharing/verify_identity_dialog.dart";
import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/pages/settings_search_page.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
import "package:locker/services/configuration.dart";
import "package:locker/ui/components/legacy_collections_trash_widget.dart";
import "package:locker/ui/components/usage_card_widget.dart";
-import "package:locker/ui/settings/pages/settings_search_page.dart";
+import "package:locker/ui/settings/search/settings_search_registry.dart";
import "package:locker/ui/settings/settings_page.dart";
class DrawerPage extends StatelessWidget {
@@ -92,9 +93,20 @@ class DrawerPage extends StatelessWidget {
}
void _openSearch(BuildContext context) {
- Navigator.of(
- context,
- ).push(MaterialPageRoute(builder: (context) => const SettingsSearchPage()));
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) {
+ final items = SettingsSearchRegistry.getSearchableItems(context);
+ return SettingsSearchPage(
+ items: items,
+ suggestions: SettingsSearchRegistry.getSuggestions(context, items),
+ onNavigate: (context, routeBuilder) => Navigator.of(
+ context,
+ ).push(MaterialPageRoute(builder: routeBuilder)),
+ );
+ },
+ ),
+ );
}
void _showVerifyIDSheet(BuildContext context) {
diff --git a/mobile/apps/locker/lib/ui/settings/pages/settings_search_page.dart b/mobile/apps/locker/lib/ui/settings/pages/settings_search_page.dart
deleted file mode 100644
index 92c9149512..0000000000
--- a/mobile/apps/locker/lib/ui/settings/pages/settings_search_page.dart
+++ /dev/null
@@ -1,491 +0,0 @@
-import "dart:async";
-import "dart:io";
-
-import "package:ente_accounts/services/user_service.dart";
-import "package:ente_components/ente_components.dart";
-import "package:ente_strings/ente_strings.dart";
-import "package:flutter/foundation.dart";
-import "package:flutter/material.dart";
-import "package:hugeicons/hugeicons.dart";
-import "package:locker/services/configuration.dart";
-import "package:locker/services/update_service.dart";
-import "package:locker/ui/settings/pages/about_page.dart";
-import "package:locker/ui/settings/pages/account_settings_page.dart";
-import "package:locker/ui/settings/pages/general_settings_page.dart";
-import "package:locker/ui/settings/pages/security_settings_page.dart";
-import "package:locker/ui/settings/pages/support_page.dart";
-import "package:locker/ui/settings/pages/theme_settings_page.dart";
-import "package:locker/utils/bottom_sheet_illustration.dart";
-
-class SettingsSearchPage extends StatefulWidget {
- const SettingsSearchPage({super.key});
-
- @override
- State<SettingsSearchPage> createState() => _SettingsSearchPageState();
-}
-
-class _SettingsSearchPageState extends State<SettingsSearchPage> {
- final TextEditingController _searchController = TextEditingController();
- final FocusNode _focusNode = FocusNode();
- Timer? _debounceTimer;
- String _searchQuery = "";
- List<_SearchResultEntry> _searchResults = [];
- late List<_SearchableSetting> _allSettings;
- late List<_SearchableSetting> _suggestions;
-
- @override
- void initState() {
- super.initState();
- _focusNode.requestFocus();
- }
-
- @override
- void didChangeDependencies() {
- super.didChangeDependencies();
- _allSettings = _buildSettingsList(context);
- _suggestions = _getDefaultSuggestions();
- }
-
- @override
- void dispose() {
- _searchController.dispose();
- _focusNode.dispose();
- _debounceTimer?.cancel();
- super.dispose();
- }
-
- List<_SearchableSetting> _buildSettingsList(BuildContext context) {
- final l10n = context.strings;
- final hasLoggedIn = Configuration.instance.hasConfiguredAccount();
-
- return [
- if (hasLoggedIn) ...[
- _SearchableSetting(
- title: l10n.account,
- category: l10n.account,
- icon: HugeIcons.strokeRoundedUser,
- page: const AccountSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.changeEmail,
- category: l10n.account,
- icon: HugeIcons.strokeRoundedUser,
- page: const AccountSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.recoveryKey,
- category: l10n.account,
- icon: HugeIcons.strokeRoundedUser,
- page: const AccountSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.changePassword,
- category: l10n.account,
- icon: HugeIcons.strokeRoundedUser,
- page: const AccountSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.deleteAccount,
- category: l10n.account,
- icon: HugeIcons.strokeRoundedUser,
- page: const AccountSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.security,
- category: l10n.security,
- icon: HugeIcons.strokeRoundedSecurityCheck,
- page: const SecuritySettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.emailVerificationToggle,
- category: l10n.security,
- icon: HugeIcons.strokeRoundedSecurityCheck,
- page: const SecuritySettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.passkey,
- category: l10n.security,
- icon: HugeIcons.strokeRoundedSecurityCheck,
- page: const SecuritySettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.appLock,
- category: l10n.security,
- icon: HugeIcons.strokeRoundedSecurityCheck,
- page: const SecuritySettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.viewActiveSessions,
- category: l10n.security,
- icon: HugeIcons.strokeRoundedSecurityCheck,
- page: const SecuritySettingsPage(),
- ),
- if (Platform.isAndroid || kDebugMode)
- _SearchableSetting(
- title: l10n.appearance,
- category: l10n.appearance,
- icon: HugeIcons.strokeRoundedSun03,
- page: const ThemeSettingsPage(),
- ),
- ],
- _SearchableSetting(
- title: l10n.general,
- category: l10n.general,
- icon: HugeIcons.strokeRoundedSettings01,
- page: const GeneralSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.selectLanguage,
- category: l10n.general,
- icon: HugeIcons.strokeRoundedSettings01,
- page: const GeneralSettingsPage(),
- ),
- _SearchableSetting(
- title: l10n.helpAndSupport,
- category: l10n.helpAndSupport,
- icon: HugeIcons.strokeRoundedHelpCircle,
- page: const SupportPage(),
- ),
- _SearchableSetting(
- title: l10n.askAQuestion,
- category: l10n.helpAndSupport,
- icon: HugeIcons.strokeRoundedHelpCircle,
- page: const SupportPage(),
- ),
- _SearchableSetting(
- title: l10n.requestAFeature,
- category: l10n.helpAndSupport,
- icon: HugeIcons.strokeRoundedHelpCircle,
- page: const SupportPage(),
- ),
- _SearchableSetting(
- title: l10n.reportAnIssue,
- category: l10n.helpAndSupport,
- icon: HugeIcons.strokeRoundedHelpCircle,
- page: const SupportPage(),
- ),
- _SearchableSetting(
- title: l10n.about,
- category: l10n.about,
- icon: HugeIcons.strokeRoundedInformationCircle,
- page: const AboutPage(),
- ),
- _SearchableSetting(
- title: l10n.weAreOpenSource,
- category: l10n.about,
- icon: HugeIcons.strokeRoundedInformationCircle,
- page: const AboutPage(),
- ),
- _SearchableSetting(
- title: l10n.blog,
- category: l10n.about,
- icon: HugeIcons.strokeRoundedInformationCircle,
- page: const AboutPage(),
- ),
- _SearchableSetting(
- title: l10n.privacy,
- category: l10n.about,
- icon: HugeIcons.strokeRoundedInformationCircle,
- page: const AboutPage(),
- ),
- _SearchableSetting(
- title: l10n.termsOfServicesTitle,
- category: l10n.about,
- icon: HugeIcons.strokeRoundedInformationCircle,
- page: const AboutPage(),
- ),
- if (UpdateService.instance.isIndependent())
- _SearchableSetting(
- title: l10n.checkForUpdates,
- category: l10n.about,
- icon: HugeIcons.strokeRoundedInformationCircle,
- page: const AboutPage(),
- ),
- if (hasLoggedIn)
- _SearchableSetting(
- title: l10n.logout,
- category: l10n.logout,
- icon: HugeIcons.strokeRoundedLogout05,
- onTap: _onLogoutTapped,
- ),
- ];
- }
-
- List<_SearchableSetting> _getDefaultSuggestions() {
- final l10n = context.strings;
- final hasLoggedIn = Configuration.instance.hasConfiguredAccount();
-
- return _allSettings.where((s) {
- if (hasLoggedIn) {
- return s.title == l10n.appLock ||
- s.title == l10n.appearance ||
- s.title == l10n.selectLanguage ||
- s.title == l10n.privacy;
- } else {
- return s.title == l10n.selectLanguage ||
- s.title == l10n.help ||
- s.title == l10n.privacy;
- }
- }).toList();
- }
-
- void _onSearchChanged(String query) {
- _debounceTimer?.cancel();
- _debounceTimer = Timer(const Duration(milliseconds: 300), () {
- if (mounted) {
- setState(() {
- _searchQuery = query.trim().toLowerCase();
- if (_searchQuery.isEmpty) {
- _searchResults = [];
- } else {
- _searchResults = _allSettings
- .asMap()
- .entries
- .where((entry) {
- final setting = entry.value;
- return _containsQuery(setting.title, _searchQuery) ||
- _containsQuery(setting.category, _searchQuery);
- })
- .map(
- (entry) => _SearchResultEntry(
- setting: entry.value,
- category: entry.value.category,
- ),
- )
- .toList();
- }
- });
- }
- });
- }
-
- bool _containsQuery(String text, String query) {
- if (text.isEmpty) return false;
- final lowerText = text.toLowerCase();
- if (lowerText.contains(query)) {
- return true;
- }
- final words = lowerText.split(RegExp(r'[\s\-_\.]+'));
- return words.any((word) => word.startsWith(query));
- }
-
- Future<void> _onSettingTapped(_SearchableSetting setting) async {
- if (setting.onTap != null) {
- await setting.onTap!();
- } else if (setting.page != null) {
- await Navigator.of(
- context,
- ).push(MaterialPageRoute(builder: (_) => setting.page!));
- }
- }
-
- Future<void> _onLogoutTapped() async {
- await _confirmLogout();
- }
-
- Future<void> _confirmLogout() async {
- final shouldLogout = await showBottomSheetComponent<bool>(
- context: context,
- builder: (sheetContext) => BottomSheetComponent(
- title: context.strings.warning,
- message: context.strings.areYouSureYouWantToLogout,
- illustration: LockerBottomSheetIllustration.warningGrey,
- actions: [
- ButtonComponent(
- label: context.strings.yesLogout,
- variant: ButtonComponentVariant.critical,
- shouldSurfaceExecutionStates: false,
- onTap: () {
- Navigator.of(sheetContext).pop(true);
- },
- ),
- ],
- ),
- );
- if (shouldLogout == true && mounted) {
- await UserService.instance.logout(context);
- }
- }
-
- @override
- Widget build(BuildContext context) {
- final colors = context.componentColors;
-
- return Scaffold(
- backgroundColor: colors.backgroundBase,
- body: SafeArea(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildSearchBar(),
- Expanded(
- child: _searchQuery.isEmpty
- ? _buildSuggestions()
- : _buildSearchResults(),
- ),
- ],
- ),
- ),
- );
- }
-
- Widget _buildSearchBar() {
- final colors = context.componentColors;
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
- child: TextInputComponent(
- controller: _searchController,
- focusNode: _focusNode,
- hintText: context.strings.searchSettings,
- onChanged: _onSearchChanged,
- prefix: HugeIcon(
- icon: HugeIcons.strokeRoundedSearch01,
- size: 20,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- suffix: GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: _searchController.text.isNotEmpty
- ? _clearSearch
- : () => Navigator.of(context).pop(),
- child: SizedBox.square(
- dimension: 24,
- child: HugeIcon(
- icon: HugeIcons.strokeRoundedCancel01,
- size: 18,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- ),
- ),
- ),
- );
- }
-
- void _clearSearch() {
- _searchController.clear();
- _debounceTimer?.cancel();
- setState(() {
- _searchQuery = "";
- _searchResults = [];
- });
- }
-
- Widget _buildSuggestions() {
- return SingleChildScrollView(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 8),
- Text(context.strings.suggestions, style: TextStyles.large),
- const SizedBox(height: 12),
- Wrap(
- spacing: 8,
- runSpacing: 8,
- children: _suggestions
- .map(
- (setting) => FilterChipComponent(
- label: setting.title,
- onChanged: (_) => _onSettingTapped(setting),
- ),
- )
- .toList(),
- ),
- ],
- ),
- );
- }
-
- Widget _buildSearchResults() {
- if (_searchResults.isEmpty) {
- return Center(
- child: Padding(
- padding: const EdgeInsets.all(32),
- child: Text(
- context.strings.noResultsFound,
- style: TextStyles.body.copyWith(
- color: context.componentColors.textLight,
- ),
- ),
- ),
- );
- }
-
- final rows = _buildResultRows();
- return ListView.builder(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- itemCount: rows.length,
- itemBuilder: (context, index) {
- return rows[index];
- },
- );
- }
-
- List<Widget> _buildResultRows() {
- final categoryCounts = <String, int>{};
- for (final entry in _searchResults) {
- categoryCounts.update(
- entry.category,
- (value) => value + 1,
- ifAbsent: () => 1,
- );
- }
-
- final rows = <Widget>[];
- String? currentCategory;
- for (final entry in _searchResults) {
- final shouldShowHeader =
- categoryCounts[entry.category] != null &&
- categoryCounts[entry.category]! >= 2;
- if (shouldShowHeader && currentCategory != entry.category) {
- currentCategory = entry.category;
- rows.add(
- Padding(
- padding: const EdgeInsets.only(top: 12, bottom: 8),
- child: Text(entry.category, style: TextStyles.large),
- ),
- );
- }
- rows.add(_buildSearchResultItem(entry.setting));
- }
- return rows;
- }
-
- Widget _buildSearchResultItem(_SearchableSetting setting) {
- return Padding(
- padding: const EdgeInsets.only(bottom: Spacing.sm),
- child: SettingsItem(
- title: setting.title,
- subtitle: setting.title != setting.category ? setting.category : null,
- icon: setting.icon,
- showOnlyLoadingState: true,
- onTap: () => _onSettingTapped(setting),
- ),
- );
- }
-}
-
-class _SearchableSetting {
- final String title;
- final String category;
- final List<List<dynamic>>? icon;
- final Widget? page;
- final FutureOr<void> Function()? onTap;
-
- const _SearchableSetting({
- required this.title,
- required this.category,
- this.icon,
- this.page,
- this.onTap,
- });
-}
-
-class _SearchResultEntry {
- final _SearchableSetting setting;
- final String category;
-
- const _SearchResultEntry({required this.setting, required this.category});
-}
diff --git a/mobile/apps/locker/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/locker/lib/ui/settings/search/settings_search_registry.dart
new file mode 100644
index 0000000000..241c18f0ef
--- /dev/null
+++ b/mobile/apps/locker/lib/ui/settings/search/settings_search_registry.dart
@@ -0,0 +1,218 @@
+import "dart:io";
+
+import "package:ente_accounts/services/user_service.dart";
+import "package:ente_components/ente_components.dart";
+import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/models/settings_search_item.dart";
+import "package:flutter/foundation.dart";
+import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
+import "package:locker/services/configuration.dart";
+import "package:locker/services/update_service.dart";
+import "package:locker/ui/settings/pages/about_page.dart";
+import "package:locker/ui/settings/pages/account_settings_page.dart";
+import "package:locker/ui/settings/pages/general_settings_page.dart";
+import "package:locker/ui/settings/pages/security_settings_page.dart";
+import "package:locker/ui/settings/pages/support_page.dart";
+import "package:locker/ui/settings/pages/theme_settings_page.dart";
+import "package:locker/utils/bottom_sheet_illustration.dart";
+
+class SettingsSearchRegistry {
+ static List<SettingsSearchItem> getSearchableItems(BuildContext context) {
+ final l10n = context.strings;
+ final hasLoggedIn = Configuration.instance.hasConfiguredAccount();
+
+ return [
+ if (hasLoggedIn) ...[
+ SettingsSearchItem(
+ title: l10n.account,
+ sectionPath: l10n.account,
+ icon: HugeIcons.strokeRoundedUser,
+ routeBuilder: (_) => const AccountSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.changeEmail,
+ sectionPath: l10n.account,
+ icon: HugeIcons.strokeRoundedUser,
+ routeBuilder: (_) => const AccountSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.recoveryKey,
+ sectionPath: l10n.account,
+ icon: HugeIcons.strokeRoundedUser,
+ routeBuilder: (_) => const AccountSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.changePassword,
+ sectionPath: l10n.account,
+ icon: HugeIcons.strokeRoundedUser,
+ routeBuilder: (_) => const AccountSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.deleteAccount,
+ sectionPath: l10n.account,
+ icon: HugeIcons.strokeRoundedUser,
+ routeBuilder: (_) => const AccountSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.security,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedSecurityCheck,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.emailVerificationToggle,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedSecurityCheck,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.passkey,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedSecurityCheck,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.appLock,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedSecurityCheck,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.viewActiveSessions,
+ sectionPath: l10n.security,
+ icon: HugeIcons.strokeRoundedSecurityCheck,
+ routeBuilder: (_) => const SecuritySettingsPage(),
+ ),
+ if (Platform.isAndroid || kDebugMode)
+ SettingsSearchItem(
+ title: l10n.appearance,
+ sectionPath: l10n.appearance,
+ icon: HugeIcons.strokeRoundedSun03,
+ routeBuilder: (_) => const ThemeSettingsPage(),
+ ),
+ ],
+ SettingsSearchItem(
+ title: l10n.general,
+ sectionPath: l10n.general,
+ icon: HugeIcons.strokeRoundedSettings01,
+ routeBuilder: (_) => const GeneralSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.selectLanguage,
+ sectionPath: l10n.general,
+ icon: HugeIcons.strokeRoundedSettings01,
+ routeBuilder: (_) => const GeneralSettingsPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.helpAndSupport,
+ sectionPath: l10n.helpAndSupport,
+ icon: HugeIcons.strokeRoundedHelpCircle,
+ routeBuilder: (_) => const SupportPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.askAQuestion,
+ sectionPath: l10n.helpAndSupport,
+ icon: HugeIcons.strokeRoundedHelpCircle,
+ routeBuilder: (_) => const SupportPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.requestAFeature,
+ sectionPath: l10n.helpAndSupport,
+ icon: HugeIcons.strokeRoundedHelpCircle,
+ routeBuilder: (_) => const SupportPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.reportAnIssue,
+ sectionPath: l10n.helpAndSupport,
+ icon: HugeIcons.strokeRoundedHelpCircle,
+ routeBuilder: (_) => const SupportPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.about,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.weAreOpenSource,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.blog,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.privacy,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutPage(),
+ ),
+ SettingsSearchItem(
+ title: l10n.termsOfServicesTitle,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutPage(),
+ ),
+ if (UpdateService.instance.isIndependent())
+ SettingsSearchItem(
+ title: l10n.checkForUpdates,
+ sectionPath: l10n.about,
+ icon: HugeIcons.strokeRoundedInformationCircle,
+ routeBuilder: (_) => const AboutPage(),
+ ),
+ if (hasLoggedIn)
+ SettingsSearchItem(
+ title: l10n.logout,
+ sectionPath: l10n.logout,
+ icon: HugeIcons.strokeRoundedLogout05,
+ onTap: _confirmLogout,
+ ),
+ ];
+ }
+
+ static List<SettingsSearchSuggestion> getSuggestions(
+ BuildContext context,
+ List<SettingsSearchItem> items,
+ ) {
+ final l10n = context.strings;
+ final titles = Configuration.instance.hasConfiguredAccount()
+ ? {l10n.appLock, l10n.appearance, l10n.selectLanguage, l10n.privacy}
+ : {l10n.selectLanguage, l10n.privacy};
+ return [
+ for (final item in items)
+ if (titles.contains(item.title))
+ SettingsSearchSuggestion(
+ title: item.title,
+ routeBuilder: item.routeBuilder,
+ onTap: item.onTap,
+ ),
+ ];
+ }
+
+ static Future<void> _confirmLogout(BuildContext context) async {
+ final shouldLogout = await showBottomSheetComponent<bool>(
+ context: context,
+ builder: (sheetContext) => BottomSheetComponent(
+ title: context.strings.warning,
+ message: context.strings.areYouSureYouWantToLogout,
+ illustration: LockerBottomSheetIllustration.warningGrey,
+ actions: [
+ ButtonComponent(
+ label: context.strings.yesLogout,
+ variant: ButtonComponentVariant.critical,
+ shouldSurfaceExecutionStates: false,
+ onTap: () => Navigator.of(sheetContext).pop(true),
+ ),
+ ],
+ ),
+ );
+ if (shouldLogout == true && context.mounted) {
+ await UserService.instance.logout(context);
+ }
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart
deleted file mode 100644
index cbe3afa61a..0000000000
--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_page.dart
+++ /dev/null
@@ -1,349 +0,0 @@
-import "package:ente_components/ente_components.dart";
-import "package:ente_pure_utils/ente_pure_utils.dart";
-import "package:ente_strings/ente_strings.dart";
-import "package:flutter/material.dart";
-import "package:hugeicons/hugeicons.dart";
-import "package:photos/ui/settings/search/settings_search_item.dart";
-import "package:photos/ui/settings/search/settings_search_registry.dart";
-
-class SettingsSearchPage extends StatefulWidget {
- const SettingsSearchPage({super.key});
-
- @override
- State<SettingsSearchPage> createState() => _SettingsSearchPageState();
-}
-
-class _SettingsSearchPageState extends State<SettingsSearchPage> {
- final TextEditingController _searchController = TextEditingController();
- final FocusNode _searchFocusNode = FocusNode();
- String _searchQuery = "";
- List<SettingsSearchItem>? _allItems;
- List<_SearchResultEntry> _filteredItems = [];
-
- @override
- void initState() {
- super.initState();
- WidgetsBinding.instance.addPostFrameCallback((_) {
- _searchFocusNode.requestFocus();
- });
- }
-
- @override
- void didChangeDependencies() {
- super.didChangeDependencies();
- // Only initialize once
- _allItems ??= SettingsSearchRegistry.getSearchableItems(context);
- }
-
- @override
- void dispose() {
- _searchController.dispose();
- _searchFocusNode.dispose();
- super.dispose();
- }
-
- void _onSearchChanged(String query) {
- setState(() {
- _searchQuery = query;
- if (query.isEmpty || _allItems == null) {
- _filteredItems = [];
- } else {
- final l10n = context.strings;
- final sectionOrder = <String, int>{};
- for (var i = 0; i < _allItems!.length; i++) {
- final item = _allItems![i];
- final sectionKey = _sectionKey(item.sectionPath);
- sectionOrder.putIfAbsent(sectionKey, () => i);
- }
-
- final freeUpSpacePriority = <String, int>{
- l10n.deleteSuggestions: 0,
- l10n.freeUpDeviceSpace: 1,
- };
-
- final entries = <_SearchResultEntry>[];
- for (var i = 0; i < _allItems!.length; i++) {
- final item = _allItems![i];
- final matchType = item.matchType(query);
- if (matchType == SettingsSearchMatchType.none) {
- continue;
- }
- final sectionKey = _sectionKey(item.sectionPath);
- final intraSectionOrder =
- sectionKey == l10n.freeUpSpace && freeUpSpacePriority.isNotEmpty
- ? (freeUpSpacePriority[item.title] ?? 100 + i)
- : i;
- entries.add(
- _SearchResultEntry(
- item: item,
- matchType: matchType,
- sectionKey: sectionKey,
- sectionOrder: sectionOrder[sectionKey] ?? i,
- itemOrder: i,
- intraSectionOrder: intraSectionOrder,
- ),
- );
- }
-
- final hasSubPageMatch = <String, bool>{};
- for (final entry in entries) {
- if (entry.item.isSubPage) {
- hasSubPageMatch[entry.sectionKey] = true;
- }
- }
-
- final filteredEntries = entries
- .where(
- (entry) =>
- !(hasSubPageMatch[entry.sectionKey] ?? false) ||
- entry.item.isSubPage,
- )
- .toList();
-
- filteredEntries.sort((a, b) {
- final matchPriority = _matchPriority(
- a.matchType,
- ).compareTo(_matchPriority(b.matchType));
- if (matchPriority != 0) return matchPriority;
- final sectionPriority = a.sectionOrder.compareTo(b.sectionOrder);
- if (sectionPriority != 0) return sectionPriority;
- final intraSection = a.intraSectionOrder.compareTo(
- b.intraSectionOrder,
- );
- if (intraSection != 0) return intraSection;
- return a.itemOrder.compareTo(b.itemOrder);
- });
-
- _filteredItems = filteredEntries;
- }
- });
- }
-
- void _clearSearch() {
- _searchController.clear();
- _onSearchChanged("");
- }
-
- void _navigateToSetting(Widget Function(BuildContext) routeBuilder) {
- Navigator.of(context).pop();
- routeToPage(context, routeBuilder(context));
- }
-
- @override
- Widget build(BuildContext context) {
- final colors = context.componentColors;
-
- return Scaffold(
- backgroundColor: colors.backgroundBase,
- body: SafeArea(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildSearchBar(),
- Expanded(
- child: _searchQuery.isEmpty
- ? _buildSuggestions()
- : _buildSearchResults(),
- ),
- ],
- ),
- ),
- );
- }
-
- Widget _buildSearchBar() {
- final colors = context.componentColors;
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
- child: TextInputComponent(
- controller: _searchController,
- focusNode: _searchFocusNode,
- hintText: context.strings.searchSettings,
- onChanged: _onSearchChanged,
- prefix: HugeIcon(
- icon: HugeIcons.strokeRoundedSearch01,
- size: 20,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- suffix: HugeIcon(
- icon: HugeIcons.strokeRoundedCancel01,
- size: 18,
- color: colors.textLight,
- strokeWidth: 1.6,
- ),
- onSuffixTap: _searchQuery.isNotEmpty
- ? _clearSearch
- : () => Navigator.of(context).pop(),
- ),
- );
- }
-
- Widget _buildSuggestions() {
- final suggestions = SettingsSearchRegistry.getSuggestions(
- context,
- (routeBuilder) => _navigateToSetting(routeBuilder),
- );
-
- return SingleChildScrollView(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 8),
- Text(
- context.strings.suggestions,
- style: TextStyles.large.copyWith(
- color: context.componentColors.textBase,
- ),
- ),
- const SizedBox(height: 12),
- Wrap(
- spacing: 8,
- runSpacing: 8,
- children: suggestions
- .map(
- (suggestion) => FilterChipComponent(
- label: suggestion.title,
- onChanged: (_) => suggestion.onTap(),
- ),
- )
- .toList(),
- ),
- ],
- ),
- );
- }
-
- Widget _buildSearchResults() {
- if (_filteredItems.isEmpty) {
- return Center(
- child: Padding(
- padding: const EdgeInsets.all(32),
- child: Text(
- context.strings.noResultsFound,
- style: TextStyles.body.copyWith(
- color: context.componentColors.textLight,
- ),
- ),
- ),
- );
- }
-
- final rows = _buildResultRows();
- return ListView.builder(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- itemCount: rows.length,
- itemBuilder: (context, index) {
- return rows[index];
- },
- );
- }
-
- List<Widget> _buildResultRows() {
- final sectionCounts = <String, int>{};
- for (final entry in _filteredItems) {
- sectionCounts.update(
- entry.sectionKey,
- (value) => value + 1,
- ifAbsent: () => 1,
- );
- }
-
- final rows = <Widget>[];
- String? currentSectionKey;
- for (final entry in _filteredItems) {
- final shouldShowHeader =
- sectionCounts[entry.sectionKey] != null &&
- sectionCounts[entry.sectionKey]! >= 2;
- if (shouldShowHeader && currentSectionKey != entry.sectionKey) {
- currentSectionKey = entry.sectionKey;
- rows.add(
- Padding(
- padding: const EdgeInsets.only(top: 12, bottom: 8),
- child: Text(
- entry.sectionKey,
- style: TextStyles.large.copyWith(
- color: context.componentColors.textBase,
- ),
- ),
- ),
- );
- }
- rows.add(_buildSearchResultItem(entry.item));
- }
- return rows;
- }
-
- Widget _buildSearchResultItem(SettingsSearchItem item) {
- final colors = context.componentColors;
- return Padding(
- padding: const EdgeInsets.only(bottom: Spacing.sm),
- child: MenuComponent(
- title: item.title,
- subtitle: item.sectionPath != item.title ? item.sectionPath : null,
- leading: item.icon == null
- ? null
- : HugeIcon(
- icon: item.icon!,
- color: colors.textLight,
- size: 24,
- strokeWidth: 1.6,
- ),
- trailing: Icon(
- Icons.chevron_right_outlined,
- color: colors.textLight,
- size: IconSizes.medium,
- ),
- showOnlyLoadingState: true,
- onTap: () async => _navigateToSetting(item.routeBuilder),
- ),
- );
- }
-
- String _sectionKey(String sectionPath) {
- final parts = sectionPath.split(" > ");
- return parts.isNotEmpty ? parts.first : sectionPath;
- }
-
- int _matchPriority(SettingsSearchMatchType matchType) {
- switch (matchType) {
- case SettingsSearchMatchType.titlePrefix:
- return 0;
- case SettingsSearchMatchType.title:
- return 1;
- case SettingsSearchMatchType.subtitlePrefix:
- return 2;
- case SettingsSearchMatchType.subtitle:
- return 3;
- case SettingsSearchMatchType.sectionPathPrefix:
- return 4;
- case SettingsSearchMatchType.sectionPath:
- return 5;
- case SettingsSearchMatchType.keywordPrefix:
- return 6;
- case SettingsSearchMatchType.keyword:
- return 7;
- case SettingsSearchMatchType.none:
- return 8;
- }
- }
-}
-
-class _SearchResultEntry {
- final SettingsSearchItem item;
- final SettingsSearchMatchType matchType;
- final String sectionKey;
- final int sectionOrder;
- final int itemOrder;
- final int intraSectionOrder;
-
- _SearchResultEntry({
- required this.item,
- required this.matchType,
- required this.sectionKey,
- required this.sectionOrder,
- required this.itemOrder,
- required this.intraSectionOrder,
- });
-}
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
index 19af1a34b9..54ec6bc9f6 100644
--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
+++ b/mobile/apps/photos/lib/ui/settings/search/settings_search_registry.dart
@@ -1,6 +1,7 @@
import "dart:io";
import "package:ente_strings/ente_strings.dart";
+import "package:ente_ui/models/settings_search_item.dart";
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
@@ -15,7 +16,6 @@ import "package:photos/ui/settings/gallery_settings_screen.dart";
import "package:photos/ui/settings/memories_settings_screen.dart";
import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
import "package:photos/ui/settings/notification_settings_screen.dart";
-import "package:photos/ui/settings/search/settings_search_item.dart";
import "package:photos/ui/settings/security/security_settings_page.dart";
import "package:photos/ui/settings/streaming/video_streaming_settings_page.dart";
import "package:photos/ui/settings/support/help_support_page.dart";
@@ -589,6 +589,7 @@ class SettingsSearchRegistry {
icon: HugeIcons.strokeRoundedRocket01,
routeBuilder: (_) => const FreeUpSpaceOptionsScreen(),
isSubPage: true,
+ sectionItemPriority: 1,
keywords: ["device space", "storage", "delete"],
),
SettingsSearchItem(
@@ -633,6 +634,7 @@ class SettingsSearchRegistry {
icon: HugeIcons.strokeRoundedDelete02,
routeBuilder: (_) => const FreeUpSpaceOptionsScreen(),
isSubPage: true,
+ sectionItemPriority: 0,
keywords: ["delete", "suggestions", "cleanup"],
),
SettingsSearchItem(
@@ -770,10 +772,7 @@ class SettingsSearchRegistry {
}
/// Get suggestions shown when search is empty
- static List<SettingsSearchSuggestion> getSuggestions(
- BuildContext context,
- void Function(Widget Function(BuildContext) routeBuilder) onNavigate,
- ) {
+ static List<SettingsSearchSuggestion> getSuggestions(BuildContext context) {
final l10n = context.strings;
final hasLoggedIn = Configuration.instance.isLoggedIn();
final isLocalGallery = isLocalGalleryMode;
@@ -782,27 +781,25 @@ class SettingsSearchRegistry {
// Gallery suggestion
SettingsSearchSuggestion(
title: l10n.gallery,
- onTap: () => onNavigate(
- (_) =>
- const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),
- ),
+ routeBuilder: (_) =>
+ const GallerySettingsScreen(fromGalleryLayoutSettingsCTA: false),
),
// App lock suggestion
SettingsSearchSuggestion(
title: l10n.appLock,
- onTap: () => onNavigate((_) => const SecuritySettingsPage()),
+ routeBuilder: (_) => const SecuritySettingsPage(),
),
// Free up device space suggestion
if (hasLoggedIn && !isLocalGallery)
SettingsSearchSuggestion(
title: l10n.freeUpDeviceSpace,
- onTap: () => onNavigate((_) => const FreeUpSpaceOptionsScreen()),
+ routeBuilder: (_) => const FreeUpSpaceOptionsScreen(),
),
// Backup settings suggestion
if (hasLoggedIn && !isLocalGallery)
SettingsSearchSuggestion(
title: l10n.backupSettings,
- onTap: () => onNavigate((_) => const BackupSettingsPage()),
+ routeBuilder: (_) => const BackupSettingsPage(),
),
];
}
diff --git a/mobile/apps/photos/lib/ui/settings_page.dart b/mobile/apps/photos/lib/ui/settings_page.dart
index 5ebbb6ac7c..cfbeeab5fc 100644
--- a/mobile/apps/photos/lib/ui/settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings_page.dart
@@ -5,6 +5,7 @@ import "package:ente_strings/ente_strings.dart";
import "package:ente_ui/components/settings/app_engagement_section.dart";
import "package:ente_ui/components/settings/app_version_widget.dart";
import "package:ente_ui/components/settings/social_icons_row.dart";
+import "package:ente_ui/pages/settings_search_page.dart";
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
@@ -32,7 +33,7 @@ import "package:photos/ui/settings/inherited_settings_state.dart";
import "package:photos/ui/settings/memories_settings_screen.dart";
import "package:photos/ui/settings/ml/machine_learning_settings_page.dart";
import "package:photos/ui/settings/notification_settings_screen.dart";
-import "package:photos/ui/settings/search/settings_search_page.dart";
+import "package:photos/ui/settings/search/settings_search_registry.dart";
import "package:photos/ui/settings/security/security_settings_page.dart";
import "package:photos/ui/settings/storage_card_widget.dart";
import "package:photos/ui/settings/streaming/video_streaming_settings_page.dart";
@@ -214,7 +215,16 @@ class _SettingsBody extends StatelessWidget {
icon: const HugeIcon(icon: HugeIcons.strokeRoundedSearch01),
onTap: () {
Navigator.of(context).push(
- MaterialPageRoute(builder: (context) => const SettingsSearchPage()),
+ MaterialPageRoute(
+ builder: (context) => SettingsSearchPage(
+ items: SettingsSearchRegistry.getSearchableItems(context),
+ suggestions: SettingsSearchRegistry.getSuggestions(context),
+ onNavigate: (context, routeBuilder) {
+ Navigator.of(context).pop();
+ routeToPage(context, routeBuilder(context));
+ },
+ ),
+ ),
);
},
),
diff --git a/mobile/apps/photos/lib/ui/settings/search/settings_search_item.dart b/mobile/packages/ui/lib/models/settings_search_item.dart
similarity index 56%
rename from mobile/apps/photos/lib/ui/settings/search/settings_search_item.dart
rename to mobile/packages/ui/lib/models/settings_search_item.dart
index 116d78a8aa..91fd946bbf 100644
--- a/mobile/apps/photos/lib/ui/settings/search/settings_search_item.dart
+++ b/mobile/packages/ui/lib/models/settings_search_item.dart
@@ -1,37 +1,31 @@
-import "package:flutter/material.dart";
+import 'dart:async';
-/// Represents a searchable settings item
-class SettingsSearchItem {
- /// The title of the settings item
- final String title;
-
- /// Optional subtitle for more context
- final String? subtitle;
-
- /// Icon data for the item
- final List<List<dynamic>>? icon;
+import 'package:flutter/material.dart';
- /// The page/section path for navigation breadcrumb
- final String sectionPath;
-
- /// Whether this item represents a nested page
- final bool isSubPage;
-
- /// The route builder to navigate to this setting
- final Widget Function(BuildContext context) routeBuilder;
-
- /// Optional keywords for better search matching
- final List<String> keywords;
+typedef SettingsSearchAction = FutureOr<void> Function(BuildContext context);
+class SettingsSearchItem {
const SettingsSearchItem({
required this.title,
+ required this.sectionPath,
this.subtitle,
this.icon,
- required this.sectionPath,
- required this.routeBuilder,
+ this.routeBuilder,
+ this.onTap,
this.isSubPage = false,
this.keywords = const [],
- });
+ this.sectionItemPriority,
+ }) : assert(routeBuilder != null || onTap != null);
+
+ final String title;
+ final String sectionPath;
+ final String? subtitle;
+ final List<List<dynamic>>? icon;
+ final WidgetBuilder? routeBuilder;
+ final SettingsSearchAction? onTap;
+ final bool isSubPage;
+ final List<String> keywords;
+ final int? sectionItemPriority;
SettingsSearchMatchType matchType(String query) {
final normalizedQuery = query.toLowerCase().trim();
@@ -44,6 +38,7 @@ class SettingsSearchItem {
if (normalizedTitle.contains(normalizedQuery)) {
return SettingsSearchMatchType.title;
}
+
final normalizedSubtitle = subtitle?.toLowerCase();
if (normalizedSubtitle?.startsWith(normalizedQuery) ?? false) {
return SettingsSearchMatchType.subtitlePrefix;
@@ -51,6 +46,7 @@ class SettingsSearchItem {
if (normalizedSubtitle?.contains(normalizedQuery) ?? false) {
return SettingsSearchMatchType.subtitle;
}
+
final normalizedSectionPath = sectionPath.toLowerCase();
if (normalizedSectionPath.startsWith(normalizedQuery)) {
return SettingsSearchMatchType.sectionPathPrefix;
@@ -58,6 +54,7 @@ class SettingsSearchItem {
if (normalizedSectionPath.contains(normalizedQuery)) {
return SettingsSearchMatchType.sectionPath;
}
+
for (final keyword in keywords) {
final normalizedKeyword = keyword.toLowerCase();
if (normalizedKeyword.startsWith(normalizedQuery)) {
@@ -67,37 +64,8 @@ class SettingsSearchItem {
return SettingsSearchMatchType.keyword;
}
}
-
return SettingsSearchMatchType.none;
}
-
- /// Check if this item matches the search query
- bool matchesQuery(String query) {
- final normalizedQuery = query.toLowerCase().trim();
- if (normalizedQuery.isEmpty) return false;
-
- return matchType(normalizedQuery) != SettingsSearchMatchType.none;
- }
-
- bool matchesLabel(String query) {
- final normalizedQuery = query.toLowerCase().trim();
- if (normalizedQuery.isEmpty) return false;
-
- if (title.toLowerCase().contains(normalizedQuery)) return true;
- if (subtitle?.toLowerCase().contains(normalizedQuery) ?? false) return true;
- if (sectionPath.toLowerCase().contains(normalizedQuery)) return true;
- return false;
- }
-
- bool matchesKeyword(String query) {
- final normalizedQuery = query.toLowerCase().trim();
- if (normalizedQuery.isEmpty) return false;
-
- for (final keyword in keywords) {
- if (keyword.toLowerCase().contains(normalizedQuery)) return true;
- }
- return false;
- }
}
enum SettingsSearchMatchType {
@@ -112,15 +80,14 @@ enum SettingsSearchMatchType {
none,
}
-/// Represents a quick suggestion shown when search is empty
class SettingsSearchSuggestion {
- final String title;
- final List<List<dynamic>>? icon;
- final VoidCallback onTap;
-
const SettingsSearchSuggestion({
required this.title,
- this.icon,
- required this.onTap,
- });
+ this.routeBuilder,
+ this.onTap,
+ }) : assert(routeBuilder != null || onTap != null);
+
+ final String title;
+ final WidgetBuilder? routeBuilder;
+ final SettingsSearchAction? onTap;
}
diff --git a/mobile/packages/ui/lib/pages/settings_search_page.dart b/mobile/packages/ui/lib/pages/settings_search_page.dart
new file mode 100644
index 0000000000..45d7526df8
--- /dev/null
+++ b/mobile/packages/ui/lib/pages/settings_search_page.dart
@@ -0,0 +1,299 @@
+import 'dart:async';
+
+import 'package:ente_components/ente_components.dart';
+import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/models/settings_search_item.dart';
+import 'package:flutter/material.dart';
+import 'package:hugeicons/hugeicons.dart';
+
+typedef SettingsSearchNavigation =
+ FutureOr<void> Function(BuildContext context, WidgetBuilder routeBuilder);
+
+class SettingsSearchPage extends StatefulWidget {
+ const SettingsSearchPage({
+ required this.items,
+ required this.suggestions,
+ required this.onNavigate,
+ super.key,
+ });
+
+ final List<SettingsSearchItem> items;
+ final List<SettingsSearchSuggestion> suggestions;
+ final SettingsSearchNavigation onNavigate;
+
+ @override
+ State<SettingsSearchPage> createState() => _SettingsSearchPageState();
+}
+
+class _SettingsSearchPageState extends State<SettingsSearchPage> {
+ final _searchController = TextEditingController();
+ final _searchFocusNode = FocusNode();
+ String _searchQuery = '';
+ List<_SearchResultEntry> _filteredItems = [];
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (mounted) _searchFocusNode.requestFocus();
+ });
+ }
+
+ @override
+ void dispose() {
+ _searchController.dispose();
+ _searchFocusNode.dispose();
+ super.dispose();
+ }
+
+ void _onSearchChanged(String query) {
+ setState(() {
+ _searchQuery = query;
+ if (query.isEmpty) {
+ _filteredItems = [];
+ return;
+ }
+
+ final sectionOrder = <String, int>{};
+ for (var i = 0; i < widget.items.length; i++) {
+ sectionOrder.putIfAbsent(
+ _sectionKey(widget.items[i].sectionPath),
+ () => i,
+ );
+ }
+
+ final entries = <_SearchResultEntry>[];
+ for (var i = 0; i < widget.items.length; i++) {
+ final item = widget.items[i];
+ final matchType = item.matchType(query);
+ if (matchType == SettingsSearchMatchType.none) continue;
+
+ final sectionKey = _sectionKey(item.sectionPath);
+ entries.add(
+ _SearchResultEntry(
+ item: item,
+ matchType: matchType,
+ sectionKey: sectionKey,
+ sectionOrder: sectionOrder[sectionKey] ?? i,
+ itemOrder: i,
+ sectionItemOrder: item.sectionItemPriority ?? 100 + i,
+ ),
+ );
+ }
+
+ final sectionsWithSubPageMatches = <String>{
+ for (final entry in entries)
+ if (entry.item.isSubPage) entry.sectionKey,
+ };
+ _filteredItems =
+ entries
+ .where(
+ (entry) =>
+ !sectionsWithSubPageMatches.contains(entry.sectionKey) ||
+ entry.item.isSubPage,
+ )
+ .toList()
+ ..sort(_compareResults);
+ });
+ }
+
+ void _clearSearch() {
+ _searchController.clear();
+ _onSearchChanged('');
+ }
+
+ Future<void> _open(
+ WidgetBuilder? routeBuilder,
+ SettingsSearchAction? action,
+ ) async {
+ if (action != null) {
+ await action(context);
+ } else {
+ await widget.onNavigate(context, routeBuilder!);
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ backgroundColor: context.componentColors.backgroundBase,
+ body: SafeArea(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _buildSearchBar(),
+ Expanded(
+ child: _searchQuery.isEmpty
+ ? _buildSuggestions()
+ : _buildSearchResults(),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _buildSearchBar() {
+ final colors = context.componentColors;
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
+ child: TextInputComponent(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ hintText: context.strings.searchSettings,
+ onChanged: _onSearchChanged,
+ prefix: HugeIcon(
+ icon: HugeIcons.strokeRoundedSearch01,
+ size: 20,
+ color: colors.textLight,
+ strokeWidth: 1.6,
+ ),
+ suffix: HugeIcon(
+ icon: HugeIcons.strokeRoundedCancel01,
+ size: 18,
+ color: colors.textLight,
+ strokeWidth: 1.6,
+ ),
+ onSuffixTap: _searchQuery.isNotEmpty
+ ? _clearSearch
+ : () => Navigator.of(context).pop(),
+ ),
+ );
+ }
+
+ Widget _buildSuggestions() {
+ return SingleChildScrollView(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 8),
+ Text(
+ context.strings.suggestions,
+ style: TextStyles.large.copyWith(
+ color: context.componentColors.textBase,
+ ),
+ ),
+ const SizedBox(height: 12),
+ Wrap(
+ spacing: 8,
+ runSpacing: 8,
+ children: [
+ for (final suggestion in widget.suggestions)
+ FilterChipComponent(
+ label: suggestion.title,
+ onChanged: (_) =>
+ _open(suggestion.routeBuilder, suggestion.onTap),
+ ),
+ ],
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildSearchResults() {
+ if (_filteredItems.isEmpty) {
+ return Center(
+ child: Padding(
+ padding: const EdgeInsets.all(32),
+ child: Text(
+ context.strings.noResultsFound,
+ style: TextStyles.body.copyWith(
+ color: context.componentColors.textLight,
+ ),
+ ),
+ ),
+ );
+ }
+
+ final rows = _buildResultRows();
+ return ListView.builder(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ itemCount: rows.length,
+ itemBuilder: (_, index) => rows[index],
+ );
+ }
+
+ List<Widget> _buildResultRows() {
+ final sectionCounts = <String, int>{};
+ for (final entry in _filteredItems) {
+ sectionCounts.update(
+ entry.sectionKey,
+ (count) => count + 1,
+ ifAbsent: () => 1,
+ );
+ }
+
+ final rows = <Widget>[];
+ String? currentSection;
+ for (final entry in _filteredItems) {
+ if (sectionCounts[entry.sectionKey]! >= 2 &&
+ currentSection != entry.sectionKey) {
+ currentSection = entry.sectionKey;
+ rows.add(
+ Padding(
+ padding: const EdgeInsets.only(top: 12, bottom: 8),
+ child: Text(
+ entry.sectionKey,
+ style: TextStyles.large.copyWith(
+ color: context.componentColors.textBase,
+ ),
+ ),
+ ),
+ );
+ }
+ rows.add(_buildSearchResultItem(entry.item));
+ }
+ return rows;
+ }
+
+ Widget _buildSearchResultItem(SettingsSearchItem item) {
+ return Padding(
+ padding: const EdgeInsets.only(bottom: Spacing.sm),
+ child: SettingsItem(
+ title: item.title,
+ subtitle: item.sectionPath != item.title ? item.sectionPath : null,
+ icon: item.icon,
+ subtitleMaxLines: 2,
+ showOnlyLoadingState: true,
+ onTap: () => _open(item.routeBuilder, item.onTap),
+ ),
+ );
+ }
+
+ static String _sectionKey(String sectionPath) {
+ return sectionPath.split(' > ').first;
+ }
+
+ static int _compareResults(
+ _SearchResultEntry first,
+ _SearchResultEntry second,
+ ) {
+ var result = first.matchType.index.compareTo(second.matchType.index);
+ if (result != 0) return result;
+ result = first.sectionOrder.compareTo(second.sectionOrder);
+ if (result != 0) return result;
+ result = first.sectionItemOrder.compareTo(second.sectionItemOrder);
+ if (result != 0) return result;
+ return first.itemOrder.compareTo(second.itemOrder);
+ }
+}
+
+class _SearchResultEntry {
+ const _SearchResultEntry({
+ required this.item,
+ required this.matchType,
+ required this.sectionKey,
+ required this.sectionOrder,
+ required this.itemOrder,
+ required this.sectionItemOrder,
+ });
+
+ final SettingsSearchItem item;
+ final SettingsSearchMatchType matchType;
+ final String sectionKey;
+ final int sectionOrder;
+ final int itemOrder;
+ final int sectionItemOrder;
+}