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); } }