import 'package:flutter/material.dart'; import '../features/chat/screen.dart'; import '../ui/adaptive/host.dart'; import 'app_session.dart'; import 'connection_status.dart'; import 'server_endpoint.dart'; /// The Chat destination: the shared session list and one read-only thread. /// /// Before the shared socket accepts its first connection nothing is requested, /// so an offline launch cannot look like an empty chat list. After that the /// screen stays mounted through drops; a reconnect advances [syncToken] so the /// open conversation re-subscribes and re-reads without losing its selection. class ChatDestination extends StatelessWidget { const ChatDestination({ super.key, required this.session, required this.server, this.initialSessionId, this.onSessionSelected, this.onBack, }); final AppSession session; final ServerEndpoint server; final String? initialSessionId; final ValueChanged? onSessionSelected; final VoidCallback? onBack; @override Widget build(BuildContext context) => AnimatedBuilder( animation: session, builder: (context, _) { final cupertino = usesCupertinoHost(context); if ((server.requiresConfiguration || server.error != null) && session.endpoint == null) { return ConnectionGate( session: session, server: server, cupertino: cupertino, ); } if (!session.everConnected) { if (session.connected) return _chatScreen(); return ConnectionGate( session: session, server: server, cupertino: cupertino, ); } return Column( children: [ if (!session.connected) ConnectionBanner(session: session, cupertino: cupertino), Expanded(child: _chatScreen()), ], ); }, ); Widget _chatScreen() => ChatScreen( gateway: session.gateway, initialSessionId: initialSessionId, syncToken: session.connectionEpoch, onSessionSelected: onSessionSelected, onBack: onBack, ); }