Dismiss command cards without a notice

Dismissing a finished command, or all of them, now just removes the cards;
the SnackBar / overlay with Undo is gone.
This commit is contained in:
2026-11-09 22:24:53 +00:00
parent 9bbd9e0c9b
commit 371d29224c
3 changed files with 13 additions and 133 deletions
@@ -4,16 +4,11 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../ui/sessions/chat_adaptive.dart';
import 'chat_shell_runs_controller.dart';
const String chatShellDismissLabel = 'Dismiss';
const String chatShellDismissAllLabel = 'Dismiss all finished commands';
const String chatShellUndoLabel = 'Undo';
/// How long the Undo notice stays. The server keeps a dismissed run
/// restorable for longer (protocol ChatShellRunUndoWindow, 30 s).
const Duration chatShellUndoDuration = Duration(seconds: 5);
/// The card's Dismiss button, offered once the command has finished.
class ChatShellDismissButton extends StatelessWidget {
@@ -62,9 +57,8 @@ Widget chatShellDismissAllMenuAction({required VoidCallback onPressed}) =>
child: const SizedBox.shrink(),
);
/// Dismisses [ids] for every client of the chat, then offers Undo for
/// [chatShellUndoDuration]: a Material SnackBar, or a transient Cupertino
/// notice floating over the conversation. A refusal goes to [onRefused].
/// Dismisses [ids] for every client of the chat. The card simply goes away;
/// no notice is shown. A refusal goes to [onRefused].
Future<void> dismissChatShellRuns(
BuildContext context,
ChatShellRunsController controller,
@@ -73,94 +67,6 @@ Future<void> dismissChatShellRuns(
void Function(String refusal)? onRefused,
}) async {
if (ids.isEmpty) return;
final messenger = cupertino ? null : ScaffoldMessenger.maybeOf(context);
final overlay = Overlay.maybeOf(context, rootOverlay: true);
final refusal = await controller.dismiss(ids);
if (refusal != null) {
onRefused?.call(refusal);
return;
}
void show(String message, {VoidCallback? onUndo}) {
if (messenger != null) {
messenger.hideCurrentSnackBar();
messenger.showSnackBar(
SnackBar(
key: const Key('chat-shell-undo-notice'),
content: Text(message),
duration: chatShellUndoDuration,
// An action would otherwise keep it until dismissed by hand.
persist: false,
action: onUndo == null
? null
: SnackBarAction(label: chatShellUndoLabel, onPressed: onUndo),
),
);
} else if (overlay != null && overlay.mounted) {
_showOverlayNotice(overlay, message, onUndo);
}
}
show(
ids.length == 1 ? 'Command dismissed' : '${ids.length} commands dismissed',
onUndo: () => unawaited(() async {
final failed = await controller.restore(ids);
if (failed != null) show("Couldn't restore: $failed");
}()),
);
}
OverlayEntry? _overlayNotice;
Timer? _overlayTimer;
void _hideOverlayNotice() {
_overlayTimer?.cancel();
_overlayTimer = null;
final entry = _overlayNotice;
_overlayNotice = null;
if (entry != null && entry.mounted) entry.remove();
}
void _showOverlayNotice(
OverlayState overlay,
String message,
VoidCallback? onUndo,
) {
_hideOverlayNotice();
final entry = OverlayEntry(
builder: (context) => Positioned(
left: 16,
right: 16,
bottom: 16,
child: SafeArea(
child: Semantics(
container: true,
explicitChildNodes: true,
liveRegion: true,
child: KeyedSubtree(
key: const Key('chat-shell-undo-notice'),
child: onUndo == null
? CupertinoPopupSurface(
child: Padding(
padding: const EdgeInsets.all(16),
child: DefaultTextStyle.merge(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: Text(message),
),
),
)
: ChatUndoBar(
message: message,
onUndo: () {
_hideOverlayNotice();
onUndo();
},
),
),
),
),
),
);
_overlayNotice = entry;
overlay.insert(entry);
_overlayTimer = Timer(chatShellUndoDuration, _hideOverlayNotice);
if (refusal != null) onRefused?.call(refusal);
}