import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/segmented_bar_overflow.dart'; import 'chat_shell_runs_controller.dart'; const String chatShellDismissLabel = 'Dismiss'; const String chatShellDismissAllLabel = 'Dismiss all finished commands'; /// The card's Dismiss button, offered once the command has finished. class ChatShellDismissButton extends StatelessWidget { const ChatShellDismissButton({ super.key, required this.cupertino, required this.onPressed, }); final bool cupertino; final VoidCallback onPressed; @override Widget build(BuildContext context) { if (!cupertino) { return IconButton( key: const Key('chat-shell-run-dismiss'), tooltip: chatShellDismissLabel, icon: const Icon(Icons.close), onPressed: onPressed, ); } return Semantics( label: chatShellDismissLabel, button: true, excludeSemantics: true, child: CupertinoButton( key: const Key('chat-shell-run-dismiss'), padding: const EdgeInsets.symmetric(horizontal: 8), onPressed: onPressed, child: const Icon(CupertinoIcons.xmark), ), ); } } /// The conversation's "Dismiss all finished commands" More menu entry. Widget chatShellDismissAllMenuAction({required VoidCallback onPressed}) => SegmentedOverflowAction( key: const ValueKey('chat-shell-dismiss-all-action'), overflowEntry: SegmentedOverflowEntry( label: chatShellDismissAllLabel, icon: Icons.clear_all, onPressed: onPressed, ), child: const SizedBox.shrink(), ); /// Dismisses [ids] for every client of the chat. The card simply goes away; /// no notice is shown. A refusal goes to [onRefused]. Future dismissChatShellRuns( BuildContext context, ChatShellRunsController controller, List ids, { required bool cupertino, void Function(String refusal)? onRefused, }) async { if (ids.isEmpty) return; final refusal = await controller.dismiss(ids); if (refusal != null) onRefused?.call(refusal); }