import 'package:flutter/material.dart'; import '../notify/agent_notices.dart'; /// The toast's root, so tests and captures can find it. const agentNoticeToastKey = ValueKey('agent-notice-toast'); /// How long an agent notice toast stays up. Long enough to read while coming /// back to the window; the Open action keeps it reachable. const agentNoticeToastDuration = Duration(seconds: 10); /// The in-app toast for one agent notice: the `: ` headline, the /// message, and an Open action that opens the chat. SnackBar agentNoticeSnackBar(AgentToast toast) => SnackBar( key: agentNoticeToastKey, behavior: SnackBarBehavior.floating, duration: agentNoticeToastDuration, showCloseIcon: true, content: Builder( builder: (context) { final theme = Theme.of(context).snackBarTheme.contentTextStyle; return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( toast.headline, style: theme?.copyWith(fontWeight: FontWeight.w600) ?? const TextStyle(fontWeight: FontWeight.w600), ), if (toast.message.isNotEmpty) Text(toast.message, maxLines: 4, overflow: TextOverflow.ellipsis), ], ); }, ), action: SnackBarAction(label: 'Open', onPressed: toast.open), ); /// Shows [toast] through [messenger], after any toast already showing. void showAgentNoticeToast(ScaffoldMessengerState? messenger, AgentToast toast) { messenger?.showSnackBar(agentNoticeSnackBar(toast)); }