import 'package:flutter/material.dart'; import 'settings_section.dart'; /// The sections a phone shows first, in this order: how to reach the server /// (Connection, Servers, Sign in) and then how it reaches you (the /// notification sections). The rest keep their order after them. const settingsPhoneFirstIds = [ 'managed-connection', 'connection', 'servers', 'sign-in', 'notifications', 'device-delivery', 'phone-notifications', ]; /// [sections] reordered for a phone: [settingsPhoneFirstIds] first. List settingsPhoneOrder(List sections) { int rank(SettingsSection section) { final index = settingsPhoneFirstIds.indexOf(section.id); return index < 0 ? settingsPhoneFirstIds.length : index; } final indexed = sections.indexed.toList() ..sort((a, b) { final byRank = rank(a.$2).compareTo(rank(b.$2)); return byRank != 0 ? byRank : a.$1.compareTo(b.$1); }); return [for (final (_, section) in indexed) section]; } const settingsTopicMenuKey = ValueKey('settings.topics'); /// The phone's "Jump to topic" menu beside the search field: every shown /// section by title; picking one scrolls to it (the wide layout has an index /// column instead). class SettingsTopicMenu extends StatelessWidget { const SettingsTopicMenu({ super.key, required this.sections, required this.onJump, }); final List sections; final ValueChanged onJump; @override Widget build(BuildContext context) => PopupMenuButton( key: settingsTopicMenuKey, tooltip: 'Jump to topic', icon: const Icon(Icons.toc), onSelected: onJump, itemBuilder: (_) => [ for (final section in sections) PopupMenuItem(value: section.id, child: Text(section.title)), ], ); }