import 'package:flutter/material.dart'; import '../../../ui/adaptive/segmented_bar.dart'; enum ChatSidebarMode { expanded, compact, hidden } /// Native list-layout selector, also available in the chat actions menu. class ChatSidebarButton extends StatelessWidget implements SegmentedOverflowable { const ChatSidebarButton({ super.key, required this.mode, required this.onChanged, }); final ChatSidebarMode mode; final ValueChanged onChanged; @override SegmentedOverflowEntry get overflowEntry => SegmentedOverflowEntry( label: 'Chat list layout', icon: Icons.view_sidebar_outlined, choices: [ for (final value in ChatSidebarMode.values) SegmentedMenuChoice( label: _label(value), selected: value == mode, onSelected: () => onChanged(value), ), ], ); Future _choose(BuildContext context) async { final choice = await showDialog( context: context, builder: (context) => SimpleDialog( title: const Text('Chat list'), children: [ for (final value in ChatSidebarMode.values) SimpleDialogOption( onPressed: () => Navigator.pop(context, value), child: Row( children: [ Expanded(child: Text(_label(value))), if (value == mode) const Icon(Icons.check), ], ), ), ], ), ); if (choice != null && context.mounted) onChanged(choice); } static String _label(ChatSidebarMode value) => switch (value) { ChatSidebarMode.expanded => 'Expanded chat list', ChatSidebarMode.compact => 'Compact chat list', ChatSidebarMode.hidden => 'Hide chat list', }; @override Widget build(BuildContext context) => IconButton( tooltip: 'Chat list layout', onPressed: () => _choose(context), icon: const Icon(Icons.view_sidebar_outlined), ); }