import 'dart:async'; import 'package:flutter/material.dart'; import '../chat/stack/mobile_chat_navigation.dart'; import 'settings_group.dart'; import 'settings_theme.dart'; /// Chat navigation: how a phone-width window moves between the open chats, /// with the next chat's peek (Quick switch) or a floating stack of them /// (Chat stack). Saved on this device and applied at once. class SettingsChatNavigationSection extends StatelessWidget { const SettingsChatNavigationSection({super.key, this.controller}); final MobileChatNavigationController? controller; static const title = 'Mobile chat navigation'; @override Widget build(BuildContext context) { final navigation = controller ?? MobileChatNavigationController.instance; return ListenableBuilder( listenable: navigation, builder: (context, _) => SettingsGroup( title: title, footer: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Text( 'Saved on this device. Applies on a phone-width window; the ' 'Chat stack also stays on a wide phone or tablet layout (an ' 'unfolded foldable), beside the chat list.', ), if (navigation.saveFailed) Text( 'Could not save; applies until reload.', style: TextStyle(color: settingsErrorColor(context)), ), ], ), children: [ SettingsGroupItem( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Semantics( label: title, child: Align( alignment: AlignmentDirectional.centerStart, child: SegmentedButton( segments: [ for (final mode in MobileChatNavigation.values) ButtonSegment( value: mode, label: Text( mode.label, key: ValueKey( 'settings-chat-navigation-${mode.name}', ), ), icon: Icon( mode == MobileChatNavigation.quickSwitch ? Icons.splitscreen_outlined : Icons.layers_outlined, ), ), ], selected: {navigation.value}, onSelectionChanged: (modes) => unawaited(navigation.setValue(modes.first)), ), ), ), const SizedBox(height: 8), Text(navigation.value.description), ], ), ), ], ), ); } }