Remove Cupertino chat session branches

Keep the Material-only session UI and narrow its tests to the supported host. Preserve public Cupertino parameters for callers while removing unreachable Cupertino widgets and variants.
This commit is contained in:
2026-11-11 14:18:04 +00:00
parent 96de9f5bea
commit ae208699d8
37 changed files with 566 additions and 2121 deletions
@@ -1,18 +1,13 @@
import '../../../../ui/adaptive/segmented_bar_overflow.dart';
import '../../../../ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// Which standard control family this screen renders.
enum ChatControlsStyle { material, cupertino }
/// Cupertino under an explicit Cupertino app, Material everywhere else,
/// whatever the target platform. The shell decides the app class, so a bare
/// Cupertino app never has to grow a Material ancestor just for this screen.
/// Always Material: the app is Material-only, so no screen ever asks for the
/// Cupertino family. The parameter stays for callers.
ChatControlsStyle chatControlsStyleOf(BuildContext context) =>
context.findAncestorWidgetOfExactType<MaterialApp>() == null
? ChatControlsStyle.cupertino
: ChatControlsStyle.material;
ChatControlsStyle.material;
class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
const ChatBarAction({
@@ -27,6 +22,8 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
final String label;
final VoidCallback onPressed;
final IconData materialIcon;
/// Kept for callers; the Material toolbar always draws [materialIcon].
final IconData cupertinoIcon;
final String? identifier;
@@ -40,18 +37,6 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
@override
Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return Semantics(
identifier: identifier,
label: label,
button: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: onPressed,
child: Icon(cupertinoIcon),
),
);
}
return Semantics(
identifier: identifier,
child: IconButton(
@@ -72,20 +57,6 @@ class ChatNewChatButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoButton.filled(
sizeStyle: CupertinoButtonSize.small,
onPressed: onPressed,
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(CupertinoIcons.add, size: 16),
SizedBox(width: 4),
Text('New chat'),
],
),
);
}
return FilledButton.icon(
onPressed: onPressed,
icon: const Icon(Icons.add),
@@ -113,21 +84,15 @@ class ChatSearchField extends StatelessWidget {
@override
Widget build(BuildContext context) {
final field = chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoSearchTextField(
controller: controller,
placeholder: 'Search chats',
onChanged: onChanged,
)
: TextField(
controller: controller,
onChanged: onChanged,
autofocus: autofocus,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
labelText: 'Search chats',
),
);
final field = TextField(
controller: controller,
onChanged: onChanged,
autofocus: autofocus,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
labelText: 'Search chats',
),
);
return Padding(
padding: const EdgeInsets.all(16),
child: trailing.isEmpty
@@ -145,81 +110,9 @@ class ChatSearchField extends StatelessWidget {
}
}
/// A grouped Cupertino card for a message that may wrap onto several lines.
///
/// [CupertinoListTile] forces its title to one ellipsised line, which cut long
/// no-match queries and server reasons. This layout keeps the native card but
/// lets the message wrap, with its action on a separate button below.
class ChatCupertinoMessage extends StatelessWidget {
const ChatCupertinoMessage({
super.key,
required this.message,
this.icon,
this.actionLabel,
this.onAction,
});
final String message;
final IconData? icon;
final String? actionLabel;
final VoidCallback? onAction;
@override
Widget build(BuildContext context) {
return Semantics(
container: true,
explicitChildNodes: true,
child: CupertinoListSection.insetGrouped(
backgroundColor: AppColors.groupedBackground,
children: [
Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (icon != null) ...[
Icon(
icon,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
),
const SizedBox(width: 12),
],
Expanded(
// Cupertino widgets normally supply their own text style.
// This card is also mounted under a bare MaterialApp (the
// iOS/macOS theme path), where Text would otherwise inherit
// MaterialApp's "missing Material" fallback style.
child: DefaultTextStyle.merge(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(message),
if (actionLabel != null && onAction != null)
Align(
alignment: AlignmentDirectional.centerStart,
child: CupertinoButton(
padding: const EdgeInsets.only(top: 8),
onPressed: onAction,
child: Text(actionLabel!),
),
),
],
),
),
),
],
),
),
],
),
);
}
}
/// A row action's refusal, shown at full width beneath its tile.
///
/// It must not sit in a `CupertinoListTile.subtitle`: that slot forces every
/// It must not sit in a list tile's subtitle slot: that slot forces every
/// paragraph to one ellipsised line, which cut the server's reason down to its
/// first few words. Full width also stops a long refusal from turning a single
/// Material row into a column taller than the viewport.
@@ -242,13 +135,7 @@ class ChatRowError extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final style = cupertino
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.systemRed.resolveFrom(context),
)
: TextStyle(color: Theme.of(context).colorScheme.error);
final style = TextStyle(color: Theme.of(context).colorScheme.error);
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 12),
child: Row(
@@ -265,14 +152,7 @@ class ChatRowError extends StatelessWidget {
button: true,
label: 'Dismiss refusal',
excludeSemantics: true,
child: cupertino
? CupertinoButton(
padding: const EdgeInsetsDirectional.only(start: 8),
minimumSize: Size.zero,
onPressed: onDismiss,
child: const Text('OK'),
)
: TextButton(onPressed: onDismiss, child: const Text('OK')),
child: TextButton(onPressed: onDismiss, child: const Text('OK')),
),
],
),
@@ -292,14 +172,6 @@ class ChatErrorNotice extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return ChatCupertinoMessage(
message: message,
icon: CupertinoIcons.exclamationmark_circle,
actionLabel: 'Retry',
onAction: onRetry,
);
}
return MaterialBanner(
content: Text(message),
actions: [TextButton(onPressed: onRetry, child: const Text('Retry'))],
@@ -312,11 +184,7 @@ class ChatLoadingIndicator extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? const CupertinoActivityIndicator()
: const CircularProgressIndicator(),
);
return const Center(child: CircularProgressIndicator());
}
}
@@ -338,28 +206,14 @@ class ChatUndoBar extends StatelessWidget {
children: [
Expanded(
child: DefaultTextStyle.merge(
style: chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: DefaultTextStyle.of(context).style,
style: DefaultTextStyle.of(context).style,
child: Text(message),
),
),
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino)
CupertinoButton(
padding: const EdgeInsetsDirectional.only(start: 12),
onPressed: onUndo,
child: const Text('Undo'),
)
else
TextButton(onPressed: onUndo, child: const Text('Undo')),
TextButton(onPressed: onUndo, child: const Text('Undo')),
],
),
);
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
// A standard Cupertino popup surface: the bar floats over the list, so it
// needs its own painted card and shadow to stay legible.
return CupertinoPopupSurface(child: content);
}
return Material(
elevation: 3,
borderRadius: BorderRadius.circular(8),
@@ -1,28 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../domain/chat_colors.dart';
import 'chat_adaptive.dart';
/// The host's own shade for a chat colour name, tuned for the current
/// brightness: Cupertino's dynamic system colours, and Material's standard
/// swatches (a deeper tone on light surfaces, a lighter one on dark), so the
/// mark keeps its contrast in both. Null for no (or an unknown) colour.
/// brightness: Material's standard swatches (a deeper tone on light surfaces,
/// a lighter one on dark), so the mark keeps its contrast in both. Null for no
/// (or an unknown) colour.
Color? chatColorShade(BuildContext context, String? name) {
if (name == null || !chatColorNames.contains(name)) return null;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
final CupertinoDynamicColor color = switch (name) {
'red' => CupertinoColors.systemRed,
'orange' => CupertinoColors.systemOrange,
'amber' => CupertinoColors.systemYellow,
'green' => CupertinoColors.systemGreen,
'teal' => CupertinoColors.systemTeal,
'blue' => CupertinoColors.systemBlue,
'purple' => CupertinoColors.systemPurple,
_ => CupertinoColors.systemPink,
};
return color.resolveFrom(context);
}
final dark = Theme.of(context).brightness == Brightness.dark;
final MaterialColor swatch = switch (name) {
'red' => Colors.red,
@@ -42,8 +27,6 @@ Color? chatColorShade(BuildContext context, String? name) {
};
}
/// Whether the surrounding theme is dark, on either host.
/// Whether the surrounding theme is dark.
bool chatColorDarkSurface(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoTheme.brightnessOf(context) == Brightness.dark
: Theme.of(context).brightness == Brightness.dark;
Theme.of(context).brightness == Brightness.dark;
@@ -1,14 +1,12 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../ui/layout/app_sheet_header.dart';
import '../../domain/chat_colors.dart';
import 'chat_adaptive.dart';
import 'chat_color_palette.dart';
/// The chat colour choices: None, then the palette, as the host's own icon
/// buttons. The chosen one shows a check. It keeps its own selection, so a
/// pick shows at once inside a sheet that the list's rebuild cannot reach.
/// The chat colour choices: None, then the palette, as icon buttons. The
/// chosen one shows a check. It keeps its own selection, so a pick shows at
/// once inside a sheet that the list's rebuild cannot reach.
class ChatColorSwatches extends StatefulWidget {
const ChatColorSwatches({
super.key,
@@ -51,21 +49,15 @@ class _ChatColorSwatchesState extends State<ChatColorSwatches> {
}
Widget _swatch(BuildContext context, String? name) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final selected = _selected == name;
final label = name == null ? 'No colour' : chatColorLabel(name);
final muted = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final muted = Theme.of(context).colorScheme.onSurfaceVariant;
final color = chatColorShade(context, name) ?? muted;
final IconData icon = name == null
? (cupertino ? CupertinoIcons.nosign : Icons.block)
? Icons.block
: selected
? (cupertino
? CupertinoIcons.checkmark_circle_fill
: Icons.check_circle)
: (cupertino ? CupertinoIcons.circle_fill : Icons.circle);
? Icons.check_circle
: Icons.circle;
final glyph = Icon(icon, color: color, size: 32);
// The None choice has no fill to check, so its selection is a ring.
final mark = name == null && selected
@@ -77,19 +69,12 @@ class _ChatColorSwatchesState extends State<ChatColorSwatches> {
child: Padding(padding: const EdgeInsets.all(2), child: glyph),
)
: glyph;
final button = cupertino
? CupertinoButton(
padding: const EdgeInsets.all(4),
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: () => _pick(name),
child: mark,
)
: IconButton(
tooltip: label,
isSelected: selected,
onPressed: () => _pick(name),
icon: mark,
);
final button = IconButton(
tooltip: label,
isSelected: selected,
onPressed: () => _pick(name),
icon: mark,
);
return Semantics(
key: Key('chat-color-${name ?? 'none'}'),
button: true,
@@ -117,17 +102,9 @@ class ChatColorSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final labelStyle =
(cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodySmall)
?.copyWith(
color: cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant,
);
final labelStyle = Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
return Padding(
key: const Key('chat-color-section'),
padding: padding,
@@ -151,7 +128,6 @@ Future<void> showChatColorPicker(
required String? selected,
required ValueChanged<String?> onSelected,
}) async {
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
Widget content(BuildContext sheet) => Column(
key: const Key('chat-color-sheet'),
mainAxisSize: MainAxisSize.min,
@@ -159,7 +135,7 @@ Future<void> showChatColorPicker(
children: [
AppSheetHeader(
title: 'Colour for $title',
cupertino: cupertino,
cupertino: false,
doneKey: const Key('chat-color-done'),
),
Padding(
@@ -168,20 +144,6 @@ Future<void> showChatColorPicker(
),
],
);
if (cupertino) {
await showCupertinoModalPopup<void>(
context: context,
builder: (sheet) => Align(
alignment: Alignment.bottomCenter,
child: SafeArea(
child: CupertinoPopupSurface(
child: SingleChildScrollView(child: content(sheet)),
),
),
),
);
return;
}
await showModalBottomSheet<void>(
context: context,
showDragHandle: true,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_session_state.dart';
import 'session_activity_badge.dart';
@@ -38,7 +37,6 @@ class ChatCompactAvatar extends StatelessWidget {
top: -2,
start: -5,
child: _Disc(
cupertino: cupertino,
child: Icon(
active ? Icons.radio_button_checked : Icons.visibility_outlined,
size: 14,
@@ -58,7 +56,6 @@ class ChatCompactAvatar extends StatelessWidget {
top: -2,
end: -3,
child: _Disc(
cupertino: cupertino,
child: Icon(
Icons.mark_chat_unread_outlined,
key: const Key('chat-compact-unread'),
@@ -72,16 +69,13 @@ class ChatCompactAvatar extends StatelessWidget {
}
class _Disc extends StatelessWidget {
const _Disc({required this.cupertino, required this.child});
final bool cupertino;
const _Disc({required this.child});
final Widget child;
@override
Widget build(BuildContext context) => DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: cupertino
? CupertinoColors.systemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface,
color: Theme.of(context).colorScheme.surface,
),
child: Padding(padding: const EdgeInsets.all(1), child: child),
);
@@ -1,12 +1,10 @@
import '../../../../core/servers/chat/federated_chat_gateway.dart';
import '../../../../core/servers/server_context.dart';
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_cycle.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import '../../domain/chat_colors.dart';
import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart';
@@ -44,29 +42,18 @@ class ChatCompactSidebar extends StatelessWidget {
VoidCallback onPressed, {
bool selected = false,
}) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
return Semantics(
label: title,
button: true,
selected: selected,
onTap: onPressed,
excludeSemantics: true,
child: cupertino
? Tooltip(
message: title,
child: CupertinoButton(
padding: const EdgeInsets.symmetric(vertical: 8),
onPressed: onPressed,
child: icon,
),
)
: IconButton(
tooltip: title,
onPressed: onPressed,
icon: icon,
color: selected ? Theme.of(context).colorScheme.primary : null,
),
child: IconButton(
tooltip: title,
onPressed: onPressed,
icon: icon,
color: selected ? Theme.of(context).colorScheme.primary : null,
),
);
}
@@ -94,9 +81,7 @@ class ChatCompactSidebar extends StatelessWidget {
].join('\n');
final color =
chatColorShade(context, chatSessionColor(row)) ??
(chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary);
Theme.of(context).colorScheme.primary;
return ChatVisibilityMarker(
sessionId: id,
color: color,
@@ -122,9 +107,7 @@ class ChatCompactSidebar extends StatelessWidget {
running: running,
backgroundTasks: backgroundTasks,
unread: unread,
cupertino:
chatControlsStyleOf(context) ==
ChatControlsStyle.cupertino,
cupertino: false,
),
if (machineName case final name?)
Text(
@@ -159,11 +142,7 @@ class ChatCompactSidebar extends StatelessWidget {
Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoIcons.sidebar_left
: Icons.menu_open,
),
const Icon(Icons.menu_open),
const Text('Expand', textAlign: TextAlign.center),
if (controller.repository.gateway is FederatedChatGateway)
const Text('All machines', textAlign: TextAlign.center)
@@ -1,15 +1,12 @@
import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
/// The create flow's heading and confirm, verbatim from the web client.
const String chatCreateTitle = 'Start a chat';
const String chatCreateConfirmLabel = 'New chat';
/// Native chrome for the create dialog: standard Cupertino alert or Material
/// alert, with the same disabled/submitting state in both hosts.
/// Native chrome for the create dialog: a Material alert, with the same
/// disabled/submitting state for the confirm action.
class ChatCreateDialogFrame extends StatelessWidget {
const ChatCreateDialogFrame({
super.key,
@@ -30,24 +27,6 @@ class ChatCreateDialogFrame extends StatelessWidget {
Widget build(BuildContext context) {
final enabled = canSubmit && !submitting;
final label = submitting ? 'Creating…' : chatCreateConfirmLabel;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoAlertDialog(
title: Text(ServerContext.metadata(context, chatCreateTitle)),
content: content,
actions: [
CupertinoDialogAction(
onPressed: submitting ? null : onCancel,
child: const Text('Cancel'),
),
CupertinoDialogAction(
key: const Key('chat-create-confirm'),
isDefaultAction: true,
onPressed: enabled ? onSubmit : null,
child: Text(label),
),
],
);
}
return AlertDialog(
title: Text(ServerContext.metadata(context, chatCreateTitle)),
content: content,
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
/// The web's directory prompt, also the directory picker's label.
const String chatCreatePrompt = 'Where should this chat live?';
@@ -70,11 +67,9 @@ class ChatCatalogFields extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
if (loading) return const Text('Loading directories…');
if (error != null) {
return _message(cupertino, 'Unable to load chat options: $error');
return _message('Unable to load chat options: $error');
}
final choices = chatDirectoryChoices(directories);
String directoryLabel(String choice) =>
@@ -82,90 +77,50 @@ class ChatCatalogFields extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (cupertino)
CupertinoPickerField(
// Keyed by the value so a folder chosen in the picker replaces the
// dropdown's retained initial value.
KeyedSubtree(
key: ValueKey('chat-create-directory-$directory'),
child: MaterialPickerField(
fieldKey: const Key('chat-create-server-directory'),
label: chatCreatePrompt,
value: directory,
values: choices,
labelOf: directoryLabel,
onSelected: onDirectory,
)
else
// Keyed by the value so a folder chosen in the picker replaces the
// dropdown's retained initial value.
KeyedSubtree(
key: ValueKey('chat-create-directory-$directory'),
child: MaterialPickerField(
fieldKey: const Key('chat-create-server-directory'),
label: chatCreatePrompt,
value: directory,
values: choices,
labelOf: directoryLabel,
onSelected: onDirectory,
),
),
),
if (onBrowse != null)
Align(
alignment: AlignmentDirectional.centerStart,
child: cupertino
? CupertinoButton(
key: const Key('chat-create-choose-folder'),
padding: const EdgeInsets.symmetric(vertical: 4),
onPressed: onBrowse,
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(CupertinoIcons.folder),
SizedBox(width: 6),
Flexible(child: Text(chatChooseFolderLabel)),
],
),
)
: TextButton.icon(
key: const Key('chat-create-choose-folder'),
onPressed: onBrowse,
icon: const Icon(Icons.folder_open),
label: const Text(chatChooseFolderLabel),
),
child: TextButton.icon(
key: const Key('chat-create-choose-folder'),
onPressed: onBrowse,
icon: const Icon(Icons.folder_open),
label: const Text(chatChooseFolderLabel),
),
),
if (backends.length > 1)
if (cupertino)
CupertinoPickerField(
fieldKey: const Key('chat-create-backend'),
label: 'Chat harness',
value: backend,
values: backends,
labelOf: chatBackendLabel,
onSelected: onBackend,
)
else
MaterialPickerField(
fieldKey: const Key('chat-create-backend'),
label: 'Chat harness',
value: backend,
values: backends,
labelOf: chatBackendLabel,
onSelected: onBackend,
),
MaterialPickerField(
fieldKey: const Key('chat-create-backend'),
label: 'Chat harness',
value: backend,
values: backends,
labelOf: chatBackendLabel,
onSelected: onBackend,
),
],
);
}
Widget _message(bool cupertino, String text) {
Widget _message(String text) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(text),
Align(
alignment: AlignmentDirectional.centerStart,
child: cupertino
? CupertinoButton(
padding: EdgeInsets.zero,
onPressed: onRetry,
child: const Text('Retry'),
)
: TextButton(onPressed: onRetry, child: const Text('Retry')),
child: TextButton(onPressed: onRetry, child: const Text('Retry')),
),
],
);
@@ -221,68 +176,3 @@ class MaterialPickerField extends StatelessWidget {
return Text(_text(item), maxLines: 1, overflow: TextOverflow.ellipsis);
}
}
class CupertinoPickerField extends StatelessWidget {
const CupertinoPickerField({
super.key,
required this.fieldKey,
required this.label,
required this.value,
required this.values,
required this.onSelected,
this.labelOf,
});
final String label;
final String? value;
final List<String> values;
final ValueChanged<String> onSelected;
final Key fieldKey;
/// The visible text of a value; the value itself is what is sent.
final String Function(String value)? labelOf;
String _text(String value) => labelOf?.call(value) ?? value;
Future<void> _choose(BuildContext context) async {
final choice = await showCupertinoModalPopup<String>(
context: context,
builder: (sheetContext) => CupertinoActionSheet(
title: Text(label),
actions: [
for (final item in values)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheetContext, item),
child: Text(_text(item)),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheetContext),
child: const Text('Cancel'),
),
),
);
if (choice != null) onSelected(choice);
}
@override
Widget build(BuildContext context) {
return Semantics(
label: '$label: ${value == null ? '' : _text(value!)}',
button: true,
child: CupertinoButton(
key: fieldKey,
padding: const EdgeInsets.symmetric(vertical: 4),
onPressed: () => _choose(context),
child: Row(
children: [
Expanded(
child: Text('$label: ${value == null ? '' : _text(value!)}'),
),
const Icon(CupertinoIcons.chevron_down),
],
),
),
);
}
}
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/servers/server_catalog.dart';
import '../../../../core/servers/server_context.dart';
import 'chat_adaptive.dart';
/// Select the machine before reading its harnesses or directory listing.
Future<SavedServer?> chooseChatMachine(BuildContext context) async {
@@ -11,28 +9,6 @@ Future<SavedServer?> chooseChatMachine(BuildContext context) async {
final servers = scope?.notifier?.catalog.servers ?? const <SavedServer>[];
if (servers.isEmpty) return null;
if (servers.length == 1) return servers.single;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return showCupertinoModalPopup<SavedServer>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('New chat on…'),
message: const Text(
'Choose a machine. Its configured harnesses appear next.',
),
actions: [
for (final server in servers)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, server),
child: Text(server.name),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
}
return showDialog<SavedServer>(
context: context,
builder: (context) => SimpleDialog(
@@ -53,21 +29,6 @@ Future<SavedServer?> chooseChatMachine(BuildContext context) async {
}
Future<void> showChatMachineError(BuildContext context, String message) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text('Machine unavailable'),
content: Text(message),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_create_fields.dart';
@@ -19,6 +18,7 @@ class ChatPromptChooser extends StatelessWidget {
static const careful = 'careful';
static const lastUsed = 'last-used';
/// Kept for callers; the Material switch and picker are always drawn.
final bool cupertino;
final bool enabled;
final String choice;
@@ -42,39 +42,22 @@ class ChatPromptChooser extends StatelessWidget {
Row(
children: [
const Expanded(child: Text('Start with a prompt')),
if (cupertino)
CupertinoSwitch(
key: const Key('chat-create-send-prompt'),
value: enabled,
onChanged: onEnabled,
)
else
Switch(
key: const Key('chat-create-send-prompt'),
value: enabled,
onChanged: onEnabled,
),
Switch(
key: const Key('chat-create-send-prompt'),
value: enabled,
onChanged: onEnabled,
),
],
),
if (enabled)
if (cupertino)
CupertinoPickerField(
fieldKey: const Key('chat-create-prompt-choice'),
label: 'Prompt',
value: choices.contains(choice) ? choice : custom,
values: choices,
labelOf: label,
onSelected: onChoice,
)
else
MaterialPickerField(
fieldKey: const Key('chat-create-prompt-choice'),
label: 'Prompt',
value: choices.contains(choice) ? choice : custom,
values: choices,
labelOf: label,
onSelected: onChoice,
),
MaterialPickerField(
fieldKey: const Key('chat-create-prompt-choice'),
label: 'Prompt',
value: choices.contains(choice) ? choice : custom,
values: choices,
labelOf: label,
onSelected: onChoice,
),
],
);
}
@@ -1,18 +1,12 @@
import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
/// State uses neutral text and shapes; the chat's chosen color stays identity.
Color chatStateForeground(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoColors.label.resolveFrom(context)
: Theme.of(context).colorScheme.onSurface;
Theme.of(context).colorScheme.onSurface;
Color chatMetadataForeground(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoColors.label.resolveFrom(context).withValues(alpha: .82)
: Theme.of(context).colorScheme.onSurfaceVariant;
Theme.of(context).colorScheme.onSurfaceVariant;
class ChatSessionStateLine extends StatelessWidget {
const ChatSessionStateLine({
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_list_cupertino.dart';
import 'session_list_material.dart';
import 'session_row_style.dart';
@@ -90,30 +89,6 @@ class ChatSessionsBody extends StatelessWidget {
if (loading && sessions.isEmpty) return const ChatLoadingIndicator();
final clearSearch = query.trim().isEmpty ? null : onClearSearch;
final duplicateTitles = duplicateChatTitles(visible);
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoSessionList(
selectionOnly: selectionOnly,
sections: sections,
folds: folds,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onStar: onStar,
onColor: onColor,
onHide: onHide,
onClearSearch: clearSearch,
isUnseen: isUnseen,
errorFor: errorFor,
onDismissError: onDismissError,
);
}
return MaterialSessionList(
selectionOnly: selectionOnly,
sections: sections,
@@ -416,18 +416,6 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
);
}
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoPageScaffold(
navigationBar: SegmentedBar(
cupertino: true,
title: 'Chats',
actions: _actions(),
),
// The list scrolls behind the bar, which does not fully obstruct;
// it pads its first row by the bar's height itself.
child: SafeArea(top: false, child: body),
);
}
return Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(
@@ -1,7 +1,6 @@
import '../../../../core/servers/server_context.dart';
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
@@ -11,7 +10,6 @@ import '../../data/chat_repository.dart';
import '../../data/directory_listing.dart';
import '../../domain/chat_commands.dart';
import '../folder_picker/folder_picker_route.dart';
import 'chat_adaptive.dart';
import 'chat_create_dialog_frame.dart';
import 'chat_create_fields.dart';
import 'chat_prompt_chooser.dart';
@@ -58,9 +56,7 @@ Future<JsonMap?> showChatCreateDialog(
prompts: prompts,
),
);
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? showCupertinoDialog<JsonMap>(context: context, builder: (_) => dialog)
: showDialog<JsonMap>(context: context, builder: (_) => dialog);
return showDialog<JsonMap>(context: context, builder: (_) => dialog);
}
class CreateChatDialog extends StatefulWidget {
@@ -306,8 +302,6 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final content = SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -334,21 +328,14 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
const SizedBox(height: 12),
const Text('Name'),
const SizedBox(height: 4),
if (cupertino)
CupertinoTextField(
key: const Key('chat-create-name'),
controller: _name,
onChanged: (_) => _nameEdited = true,
)
else
TextField(
key: const Key('chat-create-name'),
controller: _name,
onChanged: (_) => _nameEdited = true,
),
TextField(
key: const Key('chat-create-name'),
controller: _name,
onChanged: (_) => _nameEdited = true,
),
const SizedBox(height: 12),
ChatPromptChooser(
cupertino: cupertino,
cupertino: false,
enabled: _sendPrompt,
choice: _promptChoice,
hasLastUsed: _savedPrompt?.text.trim().isNotEmpty == true,
@@ -360,38 +347,22 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
),
if (_sendPrompt) ...[
const SizedBox(height: 4),
if (cupertino)
CupertinoTextField(
key: const Key('chat-create-instructions'),
controller: _instructions,
minLines: 2,
maxLines: 4,
placeholder: 'Write your custom prompt',
onChanged: (value) {
setState(() {
_promptTouched = true;
_promptChoice = ChatPromptChooser.custom;
_customPrompt = value;
});
},
)
else
TextField(
key: const Key('chat-create-instructions'),
controller: _instructions,
minLines: 2,
maxLines: 4,
decoration: const InputDecoration(
hintText: 'Write your custom prompt',
),
onChanged: (value) {
setState(() {
_promptTouched = true;
_promptChoice = ChatPromptChooser.custom;
_customPrompt = value;
});
},
TextField(
key: const Key('chat-create-instructions'),
controller: _instructions,
minLines: 2,
maxLines: 4,
decoration: const InputDecoration(
hintText: 'Write your custom prompt',
),
onChanged: (value) {
setState(() {
_promptTouched = true;
_promptChoice = ChatPromptChooser.custom;
_customPrompt = value;
});
},
),
const SizedBox(height: 4),
const Text(chatCreateInstructionsHelper),
],
@@ -408,11 +379,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
const SizedBox(height: 8),
Text(
_formError!,
style: TextStyle(
color: cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error,
),
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
],
],
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
/// Renames one session through the shared server field. Save is disabled while
/// the trimmed name is blank, matching the web dialog. A refusal keeps the
@@ -17,9 +15,7 @@ Future<String?> showRenameChatDialog(
initialTitle: chatSessionTitle(session),
onSubmit: onSubmit,
);
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? showCupertinoDialog<String>(context: context, builder: (_) => dialog)
: showDialog<String>(context: context, builder: (_) => dialog);
return showDialog<String>(context: context, builder: (_) => dialog);
}
class _RenameChatDialog extends StatefulWidget {
@@ -76,44 +72,6 @@ class _RenameChatDialogState extends State<_RenameChatDialog> {
builder: (context, value, _) {
final canSave = !_saving && value.text.trim().isNotEmpty;
final error = _error;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoAlertDialog(
title: const Text('Rename chat'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
CupertinoTextField(
key: const Key('chat-rename-field'),
controller: _title,
autofocus: true,
placeholder: 'Name',
),
const SizedBox(height: 8),
const Text('This name is shared with every device.'),
if (error != null) ...[
const SizedBox(height: 8),
Text(
error,
style: TextStyle(
color: CupertinoColors.systemRed.resolveFrom(context),
),
),
],
],
),
actions: [
CupertinoDialogAction(
onPressed: _saving ? null : () => Navigator.pop(context),
child: const Text('Cancel'),
),
CupertinoDialogAction(
isDefaultAction: true,
onPressed: canSave ? _save : null,
child: const Text('Save'),
),
],
);
}
return AlertDialog(
// A long server refusal plus a 2x helper text can exceed the dialog
// height at 320px; scroll the content instead of clipping it.
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_row_style.dart';
import '../../../../ui/layout/app_overflow_menu.dart';
@@ -84,41 +82,22 @@ List<({SessionAction action, String label})> _items(JsonMap session) {
Future<bool> confirmCloseChat(BuildContext context, JsonMap session) async {
final title = chatSessionTitle(session);
final body = closeChatConfirmation(title);
final confirmed = chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: const Text('Close chat?'),
content: Text(body),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () => Navigator.pop(context, true),
child: const Text('Close chat'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Close chat?'),
content: Text(body),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Close chat'),
),
],
),
);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Close chat?'),
content: Text(body),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Close chat'),
),
],
),
);
return confirmed == true;
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// The corner badge a chat's avatar wears for its live activity: the
@@ -14,7 +13,7 @@ Widget? chatSessionActivityBadge({
return Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino),
child: const _WorkingBadge(),
);
}
if (backgroundTasks <= 0) return null;
@@ -28,23 +27,20 @@ Widget? chatSessionActivityBadge({
excludeFromSemantics: true,
child: Semantics(
label: label,
child: _BackgroundBadge(cupertino: cupertino, count: backgroundTasks),
child: _BackgroundBadge(count: backgroundTasks),
),
);
}
/// The badge's own disc in the surface colour, so it reads over any avatar.
class _BadgeDisc extends StatelessWidget {
const _BadgeDisc({required this.cupertino, required this.child});
const _BadgeDisc({required this.child});
final bool cupertino;
final Widget child;
@override
Widget build(BuildContext context) {
final background = cupertino
? CupertinoColors.systemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface;
final background = Theme.of(context).colorScheme.surface;
return DecoratedBox(
decoration: BoxDecoration(color: background, shape: BoxShape.circle),
child: Padding(padding: const EdgeInsets.all(2), child: child),
@@ -53,37 +49,28 @@ class _BadgeDisc extends StatelessWidget {
}
class _WorkingBadge extends StatelessWidget {
const _WorkingBadge({required this.cupertino});
final bool cupertino;
const _WorkingBadge();
@override
Widget build(BuildContext context) {
return _BadgeDisc(
cupertino: cupertino,
child: cupertino
? const CupertinoActivityIndicator(radius: 6)
: const SizedBox.square(
dimension: 12,
child: CircularProgressIndicator(strokeWidth: 2),
),
return const _BadgeDisc(
child: SizedBox.square(
dimension: 12,
child: CircularProgressIndicator(strokeWidth: 2),
),
);
}
}
class _BackgroundBadge extends StatelessWidget {
const _BackgroundBadge({required this.cupertino, required this.count});
const _BackgroundBadge({required this.count});
final bool cupertino;
final int count;
@override
Widget build(BuildContext context) {
final color = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final color = Theme.of(context).colorScheme.onSurfaceVariant;
return _BadgeDisc(
cupertino: cupertino,
child: Text(
'$count',
style: TextStyle(
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import 'chat_adaptive.dart';
import 'chat_create_fields.dart';
/// Harness identity, independent of favorite/activity state. Native icon sizing
@@ -17,29 +15,14 @@ class SessionHarnessIcon extends StatelessWidget {
Widget build(BuildContext context) {
final value = '${session['backend'] ?? ''}'.trim();
final backend = value.isEmpty ? 'opencode' : value;
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final Widget mark = switch (backend) {
'opencode' || 'claude' => ImageIcon(
AssetImage('assets/harnesses/$backend.png'),
color: color,
),
'codex' => Icon(
cupertino
? CupertinoIcons.chevron_left_slash_chevron_right
: Icons.code,
color: color,
),
'pi' => Icon(
cupertino ? CupertinoIcons.function : Icons.functions,
color: color,
),
_ => Icon(
cupertino
? CupertinoIcons.chevron_left_slash_chevron_right
: Icons.terminal,
color: color,
),
'codex' => Icon(Icons.code, color: color),
'pi' => Icon(Icons.functions, color: color),
_ => Icon(Icons.terminal, color: color),
};
return Semantics(
label: '${chatBackendLabel(backend)} harness',
@@ -1,141 +0,0 @@
import 'package:flutter/cupertino.dart';
import '../../../../core/api_gateway.dart';
import 'chat_adaptive.dart';
import 'chat_sessions_body.dart';
import 'chat_list_viewport.dart';
import 'session_list_items.dart';
import '../../../../ui/adaptive/floating_bar_layout.dart';
class CupertinoSessionList extends StatelessWidget {
const CupertinoSessionList({
super.key,
required this.sections,
required this.emptyMessage,
required this.duplicateTitles,
required this.onOpen,
this.onOpenBeside,
this.onOpenBelow,
required this.onRename,
required this.onClose,
required this.onReopen,
required this.onStar,
this.onColor,
required this.onHide,
required this.onClearSearch,
required this.isUnseen,
required this.errorFor,
this.folds,
this.activeSessionId,
this.visibleSessionIds = const {},
this.onDismissError,
this.selectionOnly = false,
});
final List<ChatSessionSection> sections;
final bool selectionOnly;
final ChatSectionFolds? folds;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap>? onOpenBeside;
final ValueChanged<JsonMap>? onOpenBelow;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
final ValueChanged<JsonMap> onStar;
final ValueChanged<JsonMap>? onColor;
final ValueChanged<JsonMap> onHide;
final VoidCallback? onClearSearch;
final bool Function(JsonMap) isUnseen;
final String? Function(String sessionId) errorFor;
final ValueChanged<String>? onDismissError;
@override
Widget build(BuildContext context) => ChatListViewport(
builder: (context) {
return CustomScrollView(
slivers: [
SliverPadding(
// Starts below a floating top bar (its height arrives as media top
// padding) and ends clear of a floating bottom bar.
padding: withFloatingBarClearance(
context,
EdgeInsets.only(
top: MediaQuery.paddingOf(context).top,
bottom: 24,
),
),
sliver: SliverMainAxisGroup(
slivers: [
for (final section in sections) _section(section),
if (emptyMessage != null)
SliverToBoxAdapter(
child: ChatCupertinoMessage(
message: emptyMessage!,
actionLabel: onClearSearch == null
? null
: 'Clear search',
onAction: onClearSearch,
),
),
],
),
),
],
);
},
);
Widget _section(ChatSessionSection section) => chatSessionSection(
section: section,
folds: folds ?? ChatSectionFolds(),
directoryHeader: _DirectoryHeader.new,
row: (session, {required divider}) => chatSessionRowItem(
session,
selectionOnly: selectionOnly,
divider: divider,
activeSessionId: activeSessionId,
visibleSessionIds: visibleSessionIds,
duplicateTitles: duplicateTitles,
isUnseen: isUnseen,
onOpen: onOpen,
onOpenBeside: onOpenBeside,
onOpenBelow: onOpenBelow,
onStar: onStar,
onColor: onColor,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onHide: onHide,
),
errorFor: errorFor,
onDismissError: onDismissError,
);
}
/// A directory's name above its chats, like a grouped table's header.
class _DirectoryHeader extends StatelessWidget {
const _DirectoryHeader(this.directory);
final String directory;
@override
Widget build(BuildContext context) {
final style = CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 13,
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 6),
child: Text(
directory,
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
);
}
}
@@ -12,7 +12,7 @@ import 'session_row_memo.dart';
typedef SessionListItem = ({Key key, WidgetBuilder build});
/// A chat section as a sliver: its heading and its rows, built only when on
/// screen. Material and Cupertino supply their own directory header.
/// screen. Material supplies its own directory header.
Widget chatSessionSection({
required ChatSessionSection section,
required ChatSectionFolds folds,
@@ -1,5 +1,4 @@
import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
@@ -10,7 +9,6 @@ import '../../../../ui/motion/container_transform_source.dart';
import '../../domain/chat_colors.dart';
import '../../domain/chat_list_activity.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart';
import 'chat_session_state.dart';
@@ -63,20 +61,11 @@ class ChatSessionRow extends StatelessWidget {
@override
Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}';
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final accent = Theme.of(context).colorScheme.primary;
final shade = chatColorShade(context, chatSessionColor(session));
final marker = shade ?? accent;
final tint = AppListRow.tintFor(context, shade, cupertino: cupertino);
final background = cupertino
? CupertinoDynamicColor.resolve(
CupertinoTheme.of(context).scaffoldBackgroundColor,
context,
)
: Theme.of(context).scaffoldBackgroundColor;
final tint = AppListRow.tintFor(context, shade, cupertino: false);
final background = Theme.of(context).scaffoldBackgroundColor;
// On a phone the chat's page grows out of this row and shrinks back
// into it; the surface it starts from is the row's tint over the list.
return ContainerTransformSource(
@@ -89,8 +78,6 @@ class ChatSessionRow extends StatelessWidget {
}
Widget _marked(BuildContext context, String id, Color marker, Color accent) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
final unread = unseen && !closed;
final text = chatSessionSubtitle(session);
@@ -110,7 +97,7 @@ class ChatSessionRow extends StatelessWidget {
active: selected,
child: AppListRow(
key: Key('chat-row-$id'),
cupertino: cupertino,
cupertino: false,
selected: selected,
selectedFill: Colors.transparent,
emphasized: unread,
@@ -131,7 +118,7 @@ class ChatSessionRow extends StatelessWidget {
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: _Star(cupertino: cupertino, color: accent),
child: _Star(color: accent),
),
),
],
@@ -191,16 +178,15 @@ DateTime? _chatSessionInstant(Object? updatedAt) {
/// As tall as the title's text, so it follows text scaling.
class _Star extends StatelessWidget {
const _Star({required this.cupertino, required this.color});
const _Star({required this.color});
final bool cupertino;
final Color color;
@override
Widget build(BuildContext context) {
final size = DefaultTextStyle.of(context).style.fontSize ?? 14;
return Icon(
cupertino ? CupertinoIcons.star_fill : Icons.star,
Icons.star,
key: const Key('chat-row-starred'),
size: MediaQuery.textScalerOf(context).scale(size),
color: color,
@@ -229,8 +215,6 @@ class ChatSessionAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final Color fill;
final Color mark;
final color = chatColorShade(context, chatSessionColor(session));
@@ -241,12 +225,6 @@ class ChatSessionAvatar extends StatelessWidget {
fill = color.withValues(
alpha: chatColorDarkSurface(context) ? 0.26 : 0.16,
);
} else if (cupertino) {
final primary = CupertinoTheme.of(context).primaryColor;
fill = selected
? primary.withValues(alpha: 0.2)
: CupertinoColors.systemGrey5.resolveFrom(context);
mark = selected ? primary : CupertinoColors.label.resolveFrom(context);
} else {
final scheme = Theme.of(context).colorScheme;
fill = selected
@@ -258,7 +236,7 @@ class ChatSessionAvatar extends StatelessWidget {
foreground: mark,
background: fill,
badge: chatSessionActivityBadge(
cupertino: cupertino,
cupertino: false,
running: running,
backgroundTasks: backgroundTasks,
),
@@ -1,6 +1,5 @@
import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
@@ -10,104 +9,94 @@ import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
void main() {
for (final cupertino in [false, true]) {
for (final brightness in Brightness.values) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} $brightness: active row '
'follows selection, survives refresh and clears with the route',
(tester) async {
final semantics = tester.ensureSemantics();
try {
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 'a', 'title': 'Same title'},
{'id': 'b', 'title': 'Same title'},
],
};
addTearDown(gateway.pushed.close);
final store = MemoryChatSessionLocalStore();
String? selected = 'a'; // A routed chat need not have been tapped.
late StateSetter rebuild;
final screen = StatefulBuilder(
builder: (context, setState) {
rebuild = setState;
return ChatSessionsScreen(
gateway: gateway,
localStore: store,
activeSessionId: selected,
onOpen: (session) => setState(() => selected = session['id']),
);
},
for (final brightness in Brightness.values) {
testWidgets('Material $brightness: active row '
'follows selection, survives refresh and clears with the route', (
tester,
) async {
final semantics = tester.ensureSemantics();
try {
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 'a', 'title': 'Same title'},
{'id': 'b', 'title': 'Same title'},
],
};
addTearDown(gateway.pushed.close);
final store = MemoryChatSessionLocalStore();
String? selected = 'a'; // A routed chat need not have been tapped.
late StateSetter rebuild;
final screen = StatefulBuilder(
builder: (context, setState) {
rebuild = setState;
return ChatSessionsScreen(
gateway: gateway,
localStore: store,
activeSessionId: selected,
onOpen: (session) => setState(() => selected = session['id']),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: screen,
)
: MaterialApp(
theme: ThemeData(brightness: brightness),
home: screen,
),
);
await tester.pumpAndSettle();
},
);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(brightness: brightness),
home: screen,
),
);
await tester.pumpAndSettle();
void expectRow(String id, bool active) {
final row = find.byKey(Key('chat-row-$id'));
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
active,
);
expect(tester.widget<AppListRow>(row).selected, active);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
final color = cupertino
? tester.widget<ColoredBox>(surface).color
: tester.widget<Material>(surface).color;
expect(color, const Color(0x00000000));
final highlight = tester.widget<AnimatedContainer>(
find.byKey(ValueKey('chat-visibility-$id')),
);
final gradient =
(highlight.decoration as BoxDecoration).gradient!
as LinearGradient;
expect(gradient.colors.first.a > 0, active);
expect(gradient.colors.last.a > 0, active);
}
void expectRow(String id, bool active) {
final row = find.byKey(Key('chat-row-$id'));
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
active,
);
expect(tester.widget<AppListRow>(row).selected, active);
final surface = find.descendant(
of: row,
matching: find.byKey(appListRowSurfaceKey),
);
final color = tester.widget<Material>(surface).color;
expect(color, const Color(0x00000000));
final highlight = tester.widget<AnimatedContainer>(
find.byKey(ValueKey('chat-visibility-$id')),
);
final gradient =
(highlight.decoration as BoxDecoration).gradient!
as LinearGradient;
expect(gradient.colors.first.a > 0, active);
expect(gradient.colors.last.a > 0, active);
}
expectRow('a', true);
expectRow('b', false);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', true);
expectRow('a', true);
expectRow('b', false);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', true);
gateway.sessionsReply = {
'chat_sessions': [
{'id': 'b', 'title': 'Renamed active chat'},
{'id': 'a', 'title': 'Same title'},
],
};
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
expectRow('b', true);
expectRow('a', false);
gateway.sessionsReply = {
'chat_sessions': [
{'id': 'b', 'title': 'Renamed active chat'},
{'id': 'a', 'title': 'Same title'},
],
};
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
expectRow('b', true);
expectRow('a', false);
rebuild(() => selected = null);
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', false);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
} finally {
semantics.dispose();
}
},
);
}
rebuild(() => selected = null);
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', false);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
} finally {
semantics.dispose();
}
});
}
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -39,7 +38,6 @@ FakeChatGateway _gateway() {
Future<void> _pump(
WidgetTester tester,
FakeChatGateway gateway, {
required bool cupertino,
required Brightness brightness,
}) async {
final screen = ChatSessionsScreen(
@@ -48,21 +46,13 @@ Future<void> _pump(
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: MediaQuery(
data: MediaQueryData(platformBrightness: brightness),
child: screen,
),
)
: MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: brightness,
),
home: screen,
),
MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: brightness,
),
home: screen,
),
);
await tester.pumpAndSettle();
}
@@ -78,110 +68,83 @@ Color _accentColor(WidgetTester tester, String id) =>
tester.widget<AppListRow>(_accent(id)).accent!;
void main() {
// The row menu is Material only.
for (final cupertino in [false]) {
for (final brightness in Brightness.values) {
final host = '${cupertino ? 'Cupertino' : 'Material'} ${brightness.name}';
for (final brightness in Brightness.values) {
final host = 'Material ${brightness.name}';
testWidgets('$host: a coloured chat wears its colour, a plain one none', (
tester,
) async {
await _pump(
tester,
_gateway(),
cupertino: cupertino,
brightness: brightness,
);
expect(_accent('s1'), findsOneWidget);
expect(_accent('s2'), findsNothing);
final accent = _accentColor(tester, 's1');
// The avatar takes the same colour as the bar.
final avatar = tester.widget<AppListAvatar>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byType(AppListAvatar),
),
);
expect(avatar.foreground, accent);
// A teal shade, not the host's accent or a grey.
expect(accent.g, greaterThan(accent.r));
expect(accent.b, greaterThan(accent.r));
// The row tint is faint: the selected fill stays the stronger mark.
final tint = cupertino
? tester
.widget<ColoredBox>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey),
),
)
.color
: tester
.widget<Material>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey),
),
)
.color!;
expect(tint.a, inInclusiveRange(0.05, 0.13));
// Shades are tuned per brightness.
final shade = accent.computeLuminance();
if (brightness == Brightness.dark) {
expect(shade, greaterThan(0.2));
} else {
expect(shade, lessThan(0.55));
}
testWidgets('$host: a coloured chat wears its colour, a plain one none', (
tester,
) async {
await _pump(tester, _gateway(), brightness: brightness);
expect(_accent('s1'), findsOneWidget);
expect(_accent('s2'), findsNothing);
final accent = _accentColor(tester, 's1');
// The avatar takes the same colour as the bar.
final avatar = tester.widget<AppListAvatar>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byType(AppListAvatar),
),
);
expect(avatar.foreground, accent);
// A teal shade, not the host's accent or a grey.
expect(accent.g, greaterThan(accent.r));
expect(accent.b, greaterThan(accent.r));
// The row tint is faint: the selected fill stays the stronger mark.
final tint = tester
.widget<Material>(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey),
),
)
.color!;
expect(tint.a, inInclusiveRange(0.05, 0.13));
// Shades are tuned per brightness.
final shade = accent.computeLuminance();
if (brightness == Brightness.dark) {
expect(shade, greaterThan(0.2));
} else {
expect(shade, lessThan(0.55));
}
});
testWidgets('$host: the row menu sets and clears the colour', (
tester,
) async {
final gateway = _gateway();
await _pump(tester, gateway, brightness: brightness);
await tester.tap(
find.descendant(
of: find.byKey(const Key('chat-actions-s2')),
matching: find.byType(IconButton),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Colour…'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-purple')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': 'purple'},
});
// The row shows it at once, before the list re-reads.
expect(_accent('s2'), findsOneWidget);
testWidgets('$host: the row menu sets and clears the colour', (
tester,
) async {
final gateway = _gateway();
await _pump(
tester,
gateway,
cupertino: cupertino,
brightness: brightness,
);
await tester.tap(
find.descendant(
of: find.byKey(const Key('chat-actions-s2')),
matching: find.byType(cupertino ? CupertinoButton : IconButton),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Colour…'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-purple')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': 'purple'},
});
// The row shows it at once, before the list re-reads.
expect(_accent('s2'), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-none')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': null},
});
await tester.tap(find.byKey(const Key('chat-color-done')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsNothing);
await tester.tap(find.byKey(const Key('chat-color-none')));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_color'), {
'chat_query': {'session_id': 's2', 'color': null},
});
}
await tester.tap(find.byKey(const Key('chat-color-done')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsNothing);
});
}
testWidgets('a long-press on a row opens the colour choice', (tester) async {
final gateway = _gateway();
await _pump(
tester,
gateway,
cupertino: false,
brightness: Brightness.light,
);
await _pump(tester, gateway, brightness: Brightness.light);
await tester.longPress(find.text('Plain chat'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
@@ -1,6 +1,6 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -76,13 +76,13 @@ void main() {
},
);
testWidgets('Cupertino create dialog keeps the draft when catalogs fail', (
testWidgets('create dialog keeps the draft when catalogs fail', (
tester,
) async {
final gateway = FakeChatGateway();
gateway.directoriesHandler = () =>
Future.error(StateError('Server did not return chat directories.'));
await pumpCupertinoChat(tester, gateway);
await pumpMaterialChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
@@ -124,77 +124,6 @@ void main() {
expect(fields.containsKey('instructions'), isFalse);
});
testWidgets('Cupertino create dialog uses native selectors and fields', (
tester,
) async {
final gateway = FakeChatGateway();
JsonMap? opened;
await pumpCupertinoChat(
tester,
gateway,
onOpen: (session) => opened = session,
);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(find.text('Start a chat'), findsOneWidget);
expect(find.byKey(const Key('chat-create-instructions')), findsNothing);
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
await tester.pumpAndSettle();
expect(
find.text('Where should this chat live?: Home (~) — /work'),
findsOneWidget,
);
expect(find.text('Chat harness: OpenCode'), findsOneWidget);
await tester.ensureVisible(
find.byKey(const Key('chat-create-prompt-choice')),
);
await tester.tap(find.byKey(const Key('chat-create-prompt-choice')));
await tester.pumpAndSettle();
await tester.tap(find.text('Careful coding'));
await tester.pumpAndSettle();
expect(
find.textContaining('Act as a careful coding agent.'),
findsOneWidget,
);
await tester.ensureVisible(find.byKey(const Key('chat-create-backend')));
await tester.tap(find.byKey(const Key('chat-create-backend')));
await tester.pumpAndSettle();
await tester.tap(find.text('Codex'));
await tester.pumpAndSettle();
expect(find.text('Chat harness: Codex'), findsOneWidget);
await tester.ensureVisible(
find.byKey(const Key('chat-create-server-directory')),
);
await tester.tap(find.byKey(const Key('chat-create-server-directory')));
await tester.pumpAndSettle();
expect(find.text('/archive'), findsOneWidget);
await tester.tap(find.text('/archive'));
await tester.pumpAndSettle();
expect(find.text('Where should this chat live?: /archive'), findsOneWidget);
expect(find.text('Start in /archive'), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-create-instructions')),
'Be careful',
);
await tester.ensureVisible(find.byKey(const Key('chat-create-confirm')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-create-confirm')));
await tester.pumpAndSettle();
final fields =
gateway.lastFields('chat_create')!['chat_create']! as JsonMap;
expect(fields['title'], 'Archive Codex');
expect(fields['directory'], '/archive');
expect(fields['backend'], 'codex');
expect(fields['instructions'], 'Be careful');
expect(opened?['id'], 'created');
});
testWidgets('a created chat opens before the list refresh completes', (
tester,
) async {
@@ -1,7 +1,6 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/data/chat_create_prompt_store.dart';
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
@@ -243,36 +242,6 @@ void main() {
'Saved preset',
);
});
testWidgets('Cupertino prompt chooser has native preset and custom choices', (
tester,
) async {
final prompts = _MemoryPrompts();
await tester.pumpWidget(
CupertinoApp(
home: CupertinoPageScaffold(
child: CreateChatDialog(
repository: ChatRepository(FakeChatGateway()),
operationId: 'op',
prompts: prompts,
onSubmit: (_, _) async => {'id': 'new'},
),
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-create-send-prompt')), findsOneWidget);
expect(find.byKey(const Key('chat-create-instructions')), findsNothing);
await tester.tap(find.byKey(const Key('chat-create-send-prompt')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-create-prompt-choice')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsOneWidget);
expect(find.text('Careful coding'), findsOneWidget);
await tester.tap(find.text('Cancel').last);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
});
}
Future<void> _pickPrompt(WidgetTester tester, String label) async {
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -69,30 +68,6 @@ void main() {
});
});
testWidgets('Cupertino close confirmation uses the action sheet flow', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Close chat…'));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
expect(
find.textContaining('marks it closed on every device'),
findsOneWidget,
);
await tester.tap(find.text('Close chat'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_close'), {
'chat_query': {'session_id': 's2'},
});
});
testWidgets('material rename disables Save while the name is blank', (
tester,
) async {
@@ -114,27 +89,6 @@ void main() {
expect(gateway.count('chat_rename'), 0);
});
testWidgets('Cupertino rename disables Save while the name is blank', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' ');
await tester.pump();
final save = tester.widget<CupertinoDialogAction>(
find.widgetWithText(CupertinoDialogAction, 'Save'),
);
expect(save.onPressed, isNull);
expect(gateway.count('chat_rename'), 0);
});
testWidgets('material rename helper wraps instead of truncating at 2x', (
tester,
) async {
@@ -29,29 +29,6 @@ void main() {
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino rename refusal fits 320px at 2x', (tester) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
],
}
..failures['chat_rename'] = 'a title with usable text is required';
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('chat-rename-field')), ' x ');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('a title with usable text is required'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('Material create catalog fits real paths at 320px and 2x', (
tester,
) async {
@@ -88,21 +65,4 @@ void main() {
expect(tester.takeException(), isNull);
expect(find.byKey(const Key('chat-create-instructions')), findsOneWidget);
});
testWidgets('Cupertino create catalog fits real paths at 320px and 2x', (
tester,
) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway();
await pumpCupertinoChat(tester, gateway);
await tester.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle();
expect(
find.textContaining('Where should this chat live?:'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -158,57 +157,4 @@ void main() {
);
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino row refusal is readable at 320px 2x dark', (
tester,
) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{
'id': 's4',
'title': 'Closed chat',
'directory': '/work',
'closed_at': '2026-01-01',
},
],
}
..failures['chat_reopen'] = _refusal;
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
await expandClosedChats(tester);
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
await tester.tap(find.byKey(const Key('chat-actions-s4')));
await tester.pumpAndSettle();
await tester.tap(find.text('Reopen'));
await tester.pumpAndSettle();
// Regression: `CupertinoListTile.subtitle` is wrapped by the SDK in
// `DefaultTextStyle(maxLines: 1, overflow: ellipsis)`. The full sentence
// must be readable, so it cannot live inside that tile.
final paragraph = tester.renderObject<RenderParagraph>(
find.byKey(const Key('chat-row-error-s4')),
);
expect(paragraph.didExceedMaxLines, isFalse);
expect(find.text(_refusal), findsOneWidget);
expect(
find.ancestor(
of: find.byKey(const Key('chat-row-error-s4')),
matching: find.byType(CupertinoListTile),
),
findsNothing,
);
expect(tester.takeException(), isNull);
});
}
@@ -1,281 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_style.dart';
/// The Cupertino list, the host the web client runs on macOS/iOS.
Future<void> _pumpRows(
WidgetTester tester,
List<JsonMap> sessions, {
bool Function(JsonMap)? isUnseen,
}) async {
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: CupertinoSessionList(
sections: [(title: 'Chats', sessions: sessions)],
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: (_) {},
onHide: (_) {},
onClearSearch: null,
isUnseen: isUnseen ?? (_) => false,
errorFor: (_) => null,
),
),
),
);
// A running row's activity badge animates for as long as it runs.
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
}
void _useNarrowText(WidgetTester tester) {
tester.view.physicalSize = const Size(320, 640);
tester.view.devicePixelRatio = 1;
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
}
/// The resolved style a text is painted with, after merging with the host's
/// own `DefaultTextStyle`.
TextStyle _styleOf(WidgetTester tester, String text) =>
tester.renderObject<RenderParagraph>(find.textContaining(text)).text.style!;
void main() {
test(
'relative recency uses shared compact wording and never invents a time',
() {
final now = DateTime(2026, 10, 22, 12);
final from = now.subtract;
expect(relativeChatSessionTime(null, now: now), '');
expect(relativeChatSessionTime(0, now: now), '');
expect(
relativeChatSessionTime(now.millisecondsSinceEpoch, now: now),
'just now',
);
expect(
relativeChatSessionTime(
from(const Duration(minutes: 5)).millisecondsSinceEpoch,
now: now,
),
'5m',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 3)).millisecondsSinceEpoch,
now: now,
),
'3h',
);
expect(
relativeChatSessionTime(
from(const Duration(hours: 25)).millisecondsSinceEpoch,
now: now,
),
'1d',
);
expect(
relativeChatSessionTime(
from(const Duration(days: 3)).millisecondsSinceEpoch,
now: now,
),
'3d',
);
expect(
relativeChatSessionTime(
DateTime(2026, 10, 1, 9).millisecondsSinceEpoch,
now: now,
),
'1 Oct',
);
// The web formats with `Intl.DateTimeFormat('en-GB', …)`, whose short
// September is `Sept`; its own test asserts `12 Sept`.
expect(
relativeChatSessionTime(
DateTime(2026, 9, 12, 9).millisecondsSinceEpoch,
now: now,
),
'12 Sep',
);
},
);
test('the subtitle and status come only from the row', () {
expect(
chatSessionSubtitle({'directory': '/work', 'model': 'model-a'}),
'model-a · /work',
);
expect(chatSessionSubtitle({'directory': '/work'}), '/work');
expect(chatSessionSubtitle({}), '');
// The harness is the avatar, not a word; the home folder reads as ~.
expect(
chatSessionSubtitle({
'backend': 'claude',
'model': 'opus',
'directory': '/Users/alan/repos/pipelines',
}),
'opus · ~/repos/pipelines',
);
expect(homeRelativePath('/home/dev/x'), '~/x');
expect(homeRelativePath('/Users/alan'), '~');
expect(homeRelativePath('/srv/work'), '/srv/work');
expect(chatSessionRowStatus({}, unseen: false), isNull);
expect(chatSessionRowStatus({}, unseen: true), 'New');
expect(chatSessionRowStatus({'running': true}, unseen: true), 'New');
expect(chatSessionRowStatus({'running': true}, unseen: false), isNull);
expect(
chatSessionRowStatus({'closed_at': '2026-01-01'}, unseen: true),
'Closed',
);
});
testWidgets('a row reads avatar, title with time, one muted line and menu', (
tester,
) async {
final now = DateTime.now();
final sessions = <JsonMap>[
{
'id': 's1',
'title': 'Unread chat',
'backend': 'claude',
'directory': '/work',
'model': 'model-a',
'starred': true,
'updated_at': now
.subtract(const Duration(minutes: 5))
.millisecondsSinceEpoch,
},
{
'id': 's2',
'title': 'Read chat',
'directory': '/work',
'running': true,
'updated_at': now
.subtract(const Duration(hours: 2, minutes: 30))
.millisecondsSinceEpoch,
},
];
await _pumpRows(
tester,
sessions,
isUnseen: (session) => session['id'] == 's1',
);
final title = tester.getRect(find.textContaining('Unread chat'));
final time = tester.getRect(find.text('5m'));
final subtitle = tester.getRect(find.text('model-a · /work'));
final avatar = tester.getRect(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byType(ChatSessionAvatar),
),
);
// Avatar leads, the time trails the title on its line, the muted line
// sits beneath, and the menu trails the whole row.
expect(avatar.right, lessThanOrEqualTo(title.left));
expect(time.left, greaterThan(title.right));
expect(time.center.dy, closeTo(title.center.dy, 2));
expect(subtitle.top, greaterThanOrEqualTo(title.bottom - 1));
expect(
tester.getRect(find.byKey(const Key('chat-actions-s1'))).left,
greaterThanOrEqualTo(time.right),
);
// Unread is bold with an accent time and dot; read rows are not.
expect(_styleOf(tester, 'Unread chat').fontWeight, FontWeight.w700);
expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w600);
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
final accent = CupertinoTheme.of(
tester.element(find.text('5m')),
).primaryColor;
expect(_styleOf(tester, '5m').color, accent);
expect(_styleOf(tester, '2h').color, isNot(accent));
// Starred shows a small star by the title; running a badge on the avatar.
expect(
find.descendant(
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(const Key('chat-row-starred')),
),
findsOneWidget,
);
expect(
find.descendant(
of: find.byKey(const Key('chat-row-s2')),
matching: find.byKey(const Key('chat-row-working')),
),
findsOneWidget,
);
expect(find.byType(AppListRow), findsNWidgets(2));
expect(
tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy,
greaterThanOrEqualTo(
tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy,
),
);
});
testWidgets('at 320px 2x the long title and subtitle ellipsise', (
tester,
) async {
_useNarrowText(tester);
final now = DateTime.now();
await _pumpRows(tester, [
{
'id': 's1',
'title': 'A conversation title long enough to need an ellipsis',
'directory': '/a/very/long/directory/that/must/ellipsise',
'model': 'provider/an-extremely-long-recorded-model-id',
'updated_at': now
.subtract(const Duration(days: 3))
.millisecondsSinceEpoch,
},
{
'id': 'c1',
'title': 'A closed conversation',
'directory': '/work',
'closed_at': '2026-01-01',
},
], isUnseen: (session) => session['id'] == 's1');
expect(tester.takeException(), isNull);
final title = tester.renderObject<RenderParagraph>(
find.text('A conversation title long enough to need an ellipsis'),
);
expect(title.maxLines, 1);
expect(title.didExceedMaxLines, isTrue);
final subtitle = tester.renderObject<RenderParagraph>(
find.text(
'provider/an-extremely-long-recorded-model-id · '
'/a/very/long/directory/that/must/ellipsise',
),
);
expect(subtitle.maxLines, 1);
expect(subtitle.didExceedMaxLines, isTrue);
// The time and the Closed word stay inside their row.
for (final (row, word) in [('s1', '3d'), ('c1', 'Closed')]) {
expect(
tester.getRect(find.textContaining(word)).right,
lessThanOrEqualTo(
tester.getRect(find.byKey(Key('chat-row-$row'))).right,
),
);
}
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -56,23 +55,17 @@ Finder _spinner(String id) => find.descendant(
matching: find.byKey(const Key('chat-row-working')),
);
Future<void> _pump(
WidgetTester tester,
FakeChatGateway fake, {
bool cupertino = false,
}) async {
Future<void> _pump(WidgetTester tester, FakeChatGateway fake) async {
final screen = ChatSessionsScreen(
gateway: fake,
onOpen: (_) {},
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: screen)
: MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: screen,
),
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
home: screen,
),
);
// A spinner never settles, so pump a few frames instead.
for (var i = 0; i < 5; i++) {
@@ -177,21 +170,6 @@ void main() {
expect(_badge('s1'), findsNothing);
});
testWidgets('the Cupertino host shows the background task count', (
tester,
) async {
final fake = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [_row('bg', activity: _activity(tasks: 1))],
};
await _pump(tester, fake, cupertino: true);
expect(
find.descendant(of: _badge('bg'), matching: find.text('1')),
findsOneWidget,
);
expect(_label(1), findsOneWidget);
});
group('controller', () {
late FakeChatGateway fake;
late ChatSessionsController controller;
@@ -16,35 +16,27 @@ List<JsonMap> _many() => [
];
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('Material list scrolls behind the bar and starts below it', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': _many()};
await pumpMaterialChat(tester, gateway);
testWidgets('$host list scrolls behind the bar and starts below it', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': _many()};
if (cupertino) {
await pumpCupertinoChat(tester, gateway);
} else {
await pumpMaterialChat(tester, gateway);
}
final bar = tester.getRect(find.byType(SegmentedBar));
final list = tester.getRect(find.byType(CustomScrollView).first);
// The list reaches under the bar ...
expect(list.top, lessThan(bar.bottom));
// ... yet at rest its first row is clear of it.
final first = tester.getRect(
find.descendant(
of: find.byKey(const ValueKey('chat-section-Chats')),
matching: find.byType(SectionHeading),
),
);
expect(first.top, greaterThanOrEqualTo(bar.bottom));
expect(tester.takeException(), isNull);
});
}
final bar = tester.getRect(find.byType(SegmentedBar));
final list = tester.getRect(find.byType(CustomScrollView).first);
// The list reaches under the bar ...
expect(list.top, lessThan(bar.bottom));
// ... yet at rest its first row is clear of it.
final first = tester.getRect(
find.descendant(
of: find.byKey(const ValueKey('chat-section-Chats')),
matching: find.byType(SectionHeading),
),
);
expect(first.top, greaterThanOrEqualTo(bar.bottom));
expect(tester.takeException(), isNull);
});
testWidgets('the standalone Material list has one New chat, in the bar', (
tester,
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -29,22 +28,6 @@ Future<void> _pump(
await tester.pumpAndSettle();
}
Future<void> _pumpCupertino(
WidgetTester tester,
FakeChatGateway gateway,
) async {
await tester.pumpWidget(
CupertinoApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
localStore: _store,
),
),
);
await tester.pumpAndSettle();
}
late MemoryChatSessionLocalStore _store;
class _DeferredStore implements ChatSessionLocalStore {
@@ -339,31 +322,4 @@ void main() {
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(delayed.saved?.isUnseen('s1'), isFalse);
});
testWidgets('Cupertino rows load, mark a real answer New, then read it', (
tester,
) async {
final fake = gateway();
await _pumpCupertino(tester, fake);
fake.pushed.add({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'kind': 'step',
'step': {'status': 'started'},
},
});
await tester.pump();
await tester.pump();
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
fake.pushed.add(_event('s1'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-unread')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-row-s1')));
await tester.pump();
await tester.pump();
expect(find.byKey(const Key('chat-row-unread')), findsNothing);
});
}
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -96,87 +95,31 @@ void main() {
expect(find.textContaining('No chats match'), findsNothing);
});
testWidgets(
'Cupertino app renders standard controls, groups and renames without Material',
(tester) async {
_inventoryViewport(tester);
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
await pumpCupertinoChat(tester, gateway);
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
// The list has no search field; New chat and Refresh are the actions.
expect(find.byType(CupertinoSearchTextField), findsNothing);
expect(find.byType(Scaffold), findsNothing);
// Directory groups sit under their section's heading.
expect(find.byKey(const ValueKey('chat-section-Chats')), findsOneWidget);
expect(find.text('/work'), findsWidgets);
expect(find.text('/else'), findsWidgets);
// Starring lives in the row's actions menu.
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_star'), {
'chat_query': {'session_id': 's2', 'starred': true},
});
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Rename…'), findsOneWidget);
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
await tester.enterText(
find.byKey(const Key('chat-rename-field')),
'Renamed on Cupertino',
testWidgets('load failure wraps the reason and hides the empty message', (
tester,
) async {
usePhoneSurface(tester);
final gateway = FakeChatGateway()
..sessionsHandler = () => Future.error(
StateError(
'server unavailable while listing chat sessions for this operator',
),
);
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_rename'), {
'chat_rename': {'session_id': 's2', 'title': 'Renamed on Cupertino'},
});
await pumpMaterialChat(tester, gateway);
await expandClosedChats(tester);
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4')));
await tester.tap(find.byKey(const Key('chat-actions-s4')));
await tester.pumpAndSettle();
await tester.tap(find.text('Reopen'));
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_reopen'), {
'chat_query': {'session_id': 's4'},
});
},
);
testWidgets(
'Cupertino load failure wraps the reason and hides the empty message',
(tester) async {
usePhoneSurface(tester);
final gateway = FakeChatGateway()
..sessionsHandler = () => Future.error(
StateError(
'server unavailable while listing chat sessions for this operator',
),
);
await pumpCupertinoChat(tester, gateway);
const message =
'Bad state: server unavailable while listing chat sessions '
'for this operator';
expect(find.text(message), findsOneWidget);
expect(find.text('No chat sessions on this server yet.'), findsNothing);
final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(
messageBox.size.height,
greaterThan(30),
reason: 'the server reason must wrap instead of being cut to one line',
);
expect(find.widgetWithText(CupertinoButton, 'Retry'), findsOneWidget);
},
);
const message =
'Bad state: server unavailable while listing chat sessions '
'for this operator';
expect(find.text(message), findsOneWidget);
expect(find.text('No chat sessions on this server yet.'), findsNothing);
final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(
messageBox.size.height,
greaterThan(30),
reason: 'the server reason must wrap instead of being cut to one line',
);
expect(find.widgetWithText(TextButton, 'Retry'), findsOneWidget);
});
testWidgets('closed chats start folded away behind their heading', (
tester,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -9,126 +8,105 @@ import 'fake_chat_gateway.dart';
void main() {
// The row menu is Material only.
for (final cupertino in [false]) {
for (final beside in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} split menu passes selected chat ${beside ? 'beside' : 'below'}',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final opened = <JsonMap>[];
final right = <JsonMap>[];
final below = <JsonMap>[];
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: opened.add,
onOpenBeside: right.add,
onOpenBelow: below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsOneWidget);
if (cupertino) {
expect(find.byType(CupertinoActionSheet), findsOneWidget);
}
await tester.tap(
find.text(beside ? 'Open to the right' : 'Open below'),
);
await tester.pumpAndSettle();
expect(opened, isEmpty);
expect(beside ? right : below, hasLength(1));
expect((beside ? right : below).single['id'], 's2');
expect((beside ? right : below).single['title'], 'Open chat');
expect(beside ? below : right, isEmpty);
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
expect(find.text('Open to the right'), findsNothing);
},
);
}
for (final beside in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} updates available directions on mounted rows',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final right = <JsonMap>[];
final below = <JsonMap>[];
Future<void> show({required bool horizontal}) async {
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
onOpenBeside: horizontal ? right.add : null,
onOpenBelow: horizontal ? null : below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
}
await show(horizontal: true);
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsNothing);
if (cupertino) {
await tester.tap(find.text('Cancel'));
} else {
await tester.tapAt(const Offset(5, 5));
}
await tester.pumpAndSettle();
await show(horizontal: false);
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsOneWidget);
await tester.tap(find.text('Open below'));
await tester.pumpAndSettle();
expect(right, isEmpty);
expect(below.single['id'], 's2');
},
);
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} hides unavailable split choices and keeps row open',
'Material split menu passes selected chat ${beside ? 'beside' : 'below'}',
(tester) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final opened = <JsonMap>[];
final right = <JsonMap>[];
final below = <JsonMap>[];
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: opened.add,
onOpenBeside: right.add,
onOpenBelow: below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsOneWidget);
await tester.tap(
find.text(beside ? 'Open to the right' : 'Open below'),
);
await tester.pumpAndSettle();
expect(opened, isEmpty);
expect(beside ? right : below, hasLength(1));
expect((beside ? right : below).single['id'], 's2');
expect((beside ? right : below).single['title'], 'Open chat');
expect(beside ? below : right, isEmpty);
expect(
gateway.calls.where((call) => call.type != 'chat_sessions'),
isEmpty,
);
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsNothing);
if (cupertino) {
await tester.tap(find.text('Cancel'));
} else {
await tester.tapAt(const Offset(5, 5));
}
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-s2')));
await tester.pumpAndSettle();
expect(opened.single['id'], 's2');
},
);
}
testWidgets('Material updates available directions on mounted rows', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final right = <JsonMap>[];
final below = <JsonMap>[];
Future<void> show({required bool horizontal}) async {
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: (_) {},
onOpenBeside: horizontal ? right.add : null,
onOpenBelow: horizontal ? null : below.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
}
await show(horizontal: true);
expect(find.text('Open to the right'), findsOneWidget);
expect(find.text('Open below'), findsNothing);
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
await show(horizontal: false);
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsOneWidget);
await tester.tap(find.text('Open below'));
await tester.pumpAndSettle();
expect(right, isEmpty);
expect(below.single['id'], 's2');
});
testWidgets('Material hides unavailable split choices and keeps row open', (
tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close);
final opened = <JsonMap>[];
final screen = ChatSessionsScreen(
gateway: gateway,
onOpen: opened.add,
localStore: MemoryChatSessionLocalStore(),
);
await tester.pumpWidget(MaterialApp(home: screen));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
expect(find.text('Open to the right'), findsNothing);
expect(find.text('Open below'), findsNothing);
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-row-s2')));
await tester.pumpAndSettle();
expect(opened.single['id'], 's2');
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_state.dart';
@@ -161,69 +160,53 @@ void main() {
semantics.dispose();
});
for (final cupertino in [false, true]) {
for (final brightness in Brightness.values) {
testWidgets(
'native metadata and state contrast on tinted rows $cupertino $brightness',
(tester) async {
late BuildContext context;
final theme = ThemeData(brightness: brightness);
final body = Builder(
builder: (value) {
context = value;
return const SizedBox();
},
for (final brightness in Brightness.values) {
testWidgets(
'native metadata and state contrast on tinted rows $brightness',
(tester) async {
late BuildContext context;
final theme = ThemeData(brightness: brightness);
final body = Builder(
builder: (value) {
context = value;
return const SizedBox();
},
);
await tester.pumpWidget(MaterialApp(theme: theme, home: body));
final surface = theme.colorScheme.surface;
for (final name in [
'red',
'orange',
'amber',
'green',
'teal',
'blue',
'purple',
'pink',
]) {
final color = chatColorShade(context, name)!;
final background = Color.alphaBlend(
color.withValues(alpha: brightness == Brightness.dark ? .30 : .22),
surface,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: body,
)
: MaterialApp(theme: theme, home: body),
);
final surface = cupertino
? CupertinoDynamicColor.resolve(
CupertinoTheme.of(context).scaffoldBackgroundColor,
context,
)
: theme.colorScheme.surface;
for (final name in [
'red',
'orange',
'amber',
'green',
'teal',
'blue',
'purple',
'pink',
for (final foreground in [
chatStateForeground(context),
chatMetadataForeground(context),
]) {
final color = chatColorShade(context, name)!;
final background = Color.alphaBlend(
color.withValues(
alpha: brightness == Brightness.dark ? .30 : .22,
),
surface,
final rendered = Color.alphaBlend(foreground, background);
final a = rendered.computeLuminance(),
b = background.computeLuminance();
final ratio = (a > b
? (a + .05) / (b + .05)
: (b + .05) / (a + .05));
expect(
ratio,
greaterThanOrEqualTo(4.5),
reason: '$name metadata contrast',
);
for (final foreground in [
chatStateForeground(context),
chatMetadataForeground(context),
]) {
final rendered = Color.alphaBlend(foreground, background);
final a = rendered.computeLuminance(),
b = background.computeLuminance();
final ratio = (a > b
? (a + .05) / (b + .05)
: (b + .05) / (a + .05));
expect(
ratio,
greaterThanOrEqualTo(4.5),
reason: '$name metadata contrast',
);
}
}
},
);
}
}
},
);
}
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -57,23 +56,6 @@ Future<void> pumpMaterialChat(
await tester.pumpAndSettle();
}
Future<void> pumpCupertinoChat(
WidgetTester tester,
FakeChatGateway gateway, {
ValueChanged<JsonMap>? onOpen,
}) async {
await tester.pumpWidget(
CupertinoApp(
home: ChatSessionsScreen(
gateway: gateway,
onOpen: onOpen ?? (_) {},
localStore: MemoryChatSessionLocalStore(),
),
),
);
await tester.pumpAndSettle();
}
/// The screen's iOS/macOS path: Cupertino controls under the app's ordinary
/// `MaterialApp` root, with no Material or CupertinoTheme ancestor.
Future<void> pumpIosMaterialChat(
@@ -35,29 +35,4 @@ void main() {
expect(find.text('Open chat'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('Cupertino Undo bar fits 320px at 2x', (tester) async {
useSmallTextSurface(tester);
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 's2', 'title': 'Open chat', 'directory': '/work'},
],
};
await pumpCupertinoChat(tester, gateway);
await tester.ensureVisible(find.byKey(const Key('chat-actions-s2')));
await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle();
await tester.tap(find.text('Hide on this device'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-undo-hide')), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Undo'));
await tester.pumpAndSettle();
expect(find.text('Open chat'), findsOneWidget);
expect(tester.takeException(), isNull);
});
}
@@ -1,104 +1,80 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_harness_icon.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart';
void main() {
for (final cupertino in [false, true]) {
for (final backend in ['opencode', 'claude']) {
testWidgets(
'$backend avatar beside title; the menu stars and unstars ($cupertino)',
(tester) async {
var starred = true;
final body = StatefulBuilder(
builder: (context, setState) {
final sections = [
(
title: 'Chats',
sessions: [
<String, dynamic>{
'id': 's',
'title': 'Harness chat',
'backend': backend,
'starred': starred,
},
],
),
];
void star(Map<String, dynamic> _) =>
setState(() => starred = !starred);
return cupertino
? CupertinoSessionList(
sections: sections,
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: star,
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
)
: MaterialSessionList(
sections: sections,
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: star,
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
);
},
for (final backend in ['opencode', 'claude']) {
testWidgets('$backend avatar beside title; the menu stars and unstars', (
tester,
) async {
var starred = true;
final body = StatefulBuilder(
builder: (context, setState) {
final sections = [
(
title: 'Chats',
sessions: [
<String, dynamic>{
'id': 's',
'title': 'Harness chat',
'backend': backend,
'starred': starred,
},
],
),
];
void star(Map<String, dynamic> _) =>
setState(() => starred = !starred);
return MaterialSessionList(
sections: sections,
emptyMessage: null,
duplicateTitles: const {},
onOpen: (_) {},
onRename: (_) {},
onClose: (_) {},
onReopen: (_) {},
onStar: star,
onHide: (_) {},
onClearSearch: null,
isUnseen: (_) => false,
errorFor: (_) => null,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: body))
: MaterialApp(home: Scaffold(body: body)),
);
await tester.pumpAndSettle();
final mark = find.byType(SessionHarnessIcon);
expect(mark, findsOneWidget);
expect(
tester.widget<ImageIcon>(find.byType(ImageIcon)).image,
AssetImage('assets/harnesses/$backend.png'),
);
final title = tester.getRect(find.textContaining('Harness chat'));
final icon = tester.getRect(mark);
expect(icon.right, lessThanOrEqualTo(title.left));
expect(icon.top, lessThan(title.bottom));
expect(icon.bottom, greaterThan(title.top));
expect(find.byKey(const Key('chat-row-starred')), findsOneWidget);
// Star and unstar live in the row's menu, not a separate button.
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Unstar'));
await tester.pumpAndSettle();
expect(starred, isFalse);
expect(find.byKey(const Key('chat-row-starred')), findsNothing);
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(starred, isTrue);
expect(
find.byType(SessionHarnessIcon),
findsOneWidget,
reason: 'Changing favorite must not change harness identity',
);
expect(tester.takeException(), isNull);
},
);
}
await tester.pumpWidget(MaterialApp(home: Scaffold(body: body)));
await tester.pumpAndSettle();
final mark = find.byType(SessionHarnessIcon);
expect(mark, findsOneWidget);
expect(
tester.widget<ImageIcon>(find.byType(ImageIcon)).image,
AssetImage('assets/harnesses/$backend.png'),
);
final title = tester.getRect(find.textContaining('Harness chat'));
final icon = tester.getRect(mark);
expect(icon.right, lessThanOrEqualTo(title.left));
expect(icon.top, lessThan(title.bottom));
expect(icon.bottom, greaterThan(title.top));
expect(find.byKey(const Key('chat-row-starred')), findsOneWidget);
// Star and unstar live in the row's menu, not a separate button.
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Unstar'));
await tester.pumpAndSettle();
expect(starred, isFalse);
expect(find.byKey(const Key('chat-row-starred')), findsNothing);
await tester.tap(find.byKey(const Key('chat-actions-s')));
await tester.pumpAndSettle();
await tester.tap(find.text('Star'));
await tester.pumpAndSettle();
expect(starred, isTrue);
expect(
find.byType(SessionHarnessIcon),
findsOneWidget,
reason: 'Changing favorite must not change harness identity',
);
expect(tester.takeException(), isNull);
});
}
}