Redesign Settings as grouped searchable page
Replace the tabbed Settings flow with a single grouped page that searches and lazily loads server-backed sections. Preserve existing settings behavior while adding inline loading and retry states and updating coverage for the new navigation model.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// One headed group of the single Settings page.
|
||||
///
|
||||
/// A section is searchable by its [title] and [keywords], listed in the wide
|
||||
/// layout's jump index, and built on demand when it is [lazy]: a server-backed
|
||||
/// section shows a skeleton until the page is scrolled near it or a search
|
||||
/// matches it, so the page never waits for the server.
|
||||
class SettingsSection {
|
||||
const SettingsSection({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.builder,
|
||||
this.keywords = '',
|
||||
this.lazy = false,
|
||||
});
|
||||
|
||||
/// A stable identifier for keys and jump links.
|
||||
final String id;
|
||||
|
||||
/// The heading shown in the index, the skeleton and the group.
|
||||
final String title;
|
||||
|
||||
/// Extra words the search also matches (setting names, descriptions).
|
||||
final String keywords;
|
||||
|
||||
/// Whether this section reads the server and loads only when near or searched.
|
||||
final bool lazy;
|
||||
|
||||
final WidgetBuilder builder;
|
||||
|
||||
/// Whether every word of [query] appears in the title or keywords, ignoring
|
||||
/// case. An empty query matches every section.
|
||||
bool matches(String query) {
|
||||
final words = query
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((word) => word.isNotEmpty);
|
||||
if (words.isEmpty) return true;
|
||||
final haystack = '$title $keywords'.toLowerCase();
|
||||
return words.every(haystack.contains);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user