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/adaptive/segmented_bar_overflow.dart';
import '../../../../ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Which standard control family this screen renders. /// Which standard control family this screen renders.
enum ChatControlsStyle { material, cupertino } enum ChatControlsStyle { material, cupertino }
/// Cupertino under an explicit Cupertino app, Material everywhere else, /// Always Material: the app is Material-only, so no screen ever asks for the
/// whatever the target platform. The shell decides the app class, so a bare /// Cupertino family. The parameter stays for callers.
/// Cupertino app never has to grow a Material ancestor just for this screen.
ChatControlsStyle chatControlsStyleOf(BuildContext context) => ChatControlsStyle chatControlsStyleOf(BuildContext context) =>
context.findAncestorWidgetOfExactType<MaterialApp>() == null ChatControlsStyle.material;
? ChatControlsStyle.cupertino
: ChatControlsStyle.material;
class ChatBarAction extends StatelessWidget implements SegmentedOverflowable { class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
const ChatBarAction({ const ChatBarAction({
@@ -27,6 +22,8 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
final String label; final String label;
final VoidCallback onPressed; final VoidCallback onPressed;
final IconData materialIcon; final IconData materialIcon;
/// Kept for callers; the Material toolbar always draws [materialIcon].
final IconData cupertinoIcon; final IconData cupertinoIcon;
final String? identifier; final String? identifier;
@@ -40,18 +37,6 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
@override @override
Widget build(BuildContext context) { 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( return Semantics(
identifier: identifier, identifier: identifier,
child: IconButton( child: IconButton(
@@ -72,20 +57,6 @@ class ChatNewChatButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { 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( return FilledButton.icon(
onPressed: onPressed, onPressed: onPressed,
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
@@ -113,21 +84,15 @@ class ChatSearchField extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final field = chatControlsStyleOf(context) == ChatControlsStyle.cupertino final field = TextField(
? CupertinoSearchTextField( controller: controller,
controller: controller, onChanged: onChanged,
placeholder: 'Search chats', autofocus: autofocus,
onChanged: onChanged, decoration: const InputDecoration(
) prefixIcon: Icon(Icons.search),
: TextField( labelText: 'Search chats',
controller: controller, ),
onChanged: onChanged, );
autofocus: autofocus,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
labelText: 'Search chats',
),
);
return Padding( return Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: trailing.isEmpty 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. /// 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 /// 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 /// first few words. Full width also stops a long refusal from turning a single
/// Material row into a column taller than the viewport. /// Material row into a column taller than the viewport.
@@ -242,13 +135,7 @@ class ChatRowError extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = final style = TextStyle(color: Theme.of(context).colorScheme.error);
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);
return Padding( return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 12), padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 12),
child: Row( child: Row(
@@ -265,14 +152,7 @@ class ChatRowError extends StatelessWidget {
button: true, button: true,
label: 'Dismiss refusal', label: 'Dismiss refusal',
excludeSemantics: true, excludeSemantics: true,
child: cupertino child: TextButton(onPressed: onDismiss, child: const Text('OK')),
? CupertinoButton(
padding: const EdgeInsetsDirectional.only(start: 8),
minimumSize: Size.zero,
onPressed: onDismiss,
child: const Text('OK'),
)
: TextButton(onPressed: onDismiss, child: const Text('OK')),
), ),
], ],
), ),
@@ -292,14 +172,6 @@ class ChatErrorNotice extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return ChatCupertinoMessage(
message: message,
icon: CupertinoIcons.exclamationmark_circle,
actionLabel: 'Retry',
onAction: onRetry,
);
}
return MaterialBanner( return MaterialBanner(
content: Text(message), content: Text(message),
actions: [TextButton(onPressed: onRetry, child: const Text('Retry'))], actions: [TextButton(onPressed: onRetry, child: const Text('Retry'))],
@@ -312,11 +184,7 @@ class ChatLoadingIndicator extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return const Center(child: CircularProgressIndicator());
child: chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? const CupertinoActivityIndicator()
: const CircularProgressIndicator(),
);
} }
} }
@@ -338,28 +206,14 @@ class ChatUndoBar extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: DefaultTextStyle.merge( child: DefaultTextStyle.merge(
style: chatControlsStyleOf(context) == ChatControlsStyle.cupertino style: DefaultTextStyle.of(context).style,
? CupertinoTheme.of(context).textTheme.textStyle
: DefaultTextStyle.of(context).style,
child: Text(message), child: Text(message),
), ),
), ),
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) TextButton(onPressed: onUndo, child: const Text('Undo')),
CupertinoButton(
padding: const EdgeInsetsDirectional.only(start: 12),
onPressed: onUndo,
child: const Text('Undo'),
)
else
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( return Material(
elevation: 3, elevation: 3,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
@@ -1,28 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../domain/chat_colors.dart'; import '../../domain/chat_colors.dart';
import 'chat_adaptive.dart';
/// The host's own shade for a chat colour name, tuned for the current /// The host's own shade for a chat colour name, tuned for the current
/// brightness: Cupertino's dynamic system colours, and Material's standard /// brightness: Material's standard swatches (a deeper tone on light surfaces,
/// swatches (a deeper tone on light surfaces, a lighter one on dark), so the /// a lighter one on dark), so the mark keeps its contrast in both. Null for no
/// mark keeps its contrast in both. Null for no (or an unknown) colour. /// (or an unknown) colour.
Color? chatColorShade(BuildContext context, String? name) { Color? chatColorShade(BuildContext context, String? name) {
if (name == null || !chatColorNames.contains(name)) return null; 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 dark = Theme.of(context).brightness == Brightness.dark;
final MaterialColor swatch = switch (name) { final MaterialColor swatch = switch (name) {
'red' => Colors.red, '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) => bool chatColorDarkSurface(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino Theme.of(context).brightness == Brightness.dark;
? CupertinoTheme.brightnessOf(context) == Brightness.dark
: Theme.of(context).brightness == Brightness.dark;
@@ -1,14 +1,12 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../ui/layout/app_sheet_header.dart'; import '../../../../ui/layout/app_sheet_header.dart';
import '../../domain/chat_colors.dart'; import '../../domain/chat_colors.dart';
import 'chat_adaptive.dart';
import 'chat_color_palette.dart'; import 'chat_color_palette.dart';
/// The chat colour choices: None, then the palette, as the host's own icon /// The chat colour choices: None, then the palette, as icon buttons. The
/// buttons. The chosen one shows a check. It keeps its own selection, so a /// chosen one shows a check. It keeps its own selection, so a pick shows at
/// pick shows at once inside a sheet that the list's rebuild cannot reach. /// once inside a sheet that the list's rebuild cannot reach.
class ChatColorSwatches extends StatefulWidget { class ChatColorSwatches extends StatefulWidget {
const ChatColorSwatches({ const ChatColorSwatches({
super.key, super.key,
@@ -51,21 +49,15 @@ class _ChatColorSwatchesState extends State<ChatColorSwatches> {
} }
Widget _swatch(BuildContext context, String? name) { Widget _swatch(BuildContext context, String? name) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final selected = _selected == name; final selected = _selected == name;
final label = name == null ? 'No colour' : chatColorLabel(name); final label = name == null ? 'No colour' : chatColorLabel(name);
final muted = cupertino final muted = Theme.of(context).colorScheme.onSurfaceVariant;
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final color = chatColorShade(context, name) ?? muted; final color = chatColorShade(context, name) ?? muted;
final IconData icon = name == null final IconData icon = name == null
? (cupertino ? CupertinoIcons.nosign : Icons.block) ? Icons.block
: selected : selected
? (cupertino ? Icons.check_circle
? CupertinoIcons.checkmark_circle_fill : Icons.circle;
: Icons.check_circle)
: (cupertino ? CupertinoIcons.circle_fill : Icons.circle);
final glyph = Icon(icon, color: color, size: 32); final glyph = Icon(icon, color: color, size: 32);
// The None choice has no fill to check, so its selection is a ring. // The None choice has no fill to check, so its selection is a ring.
final mark = name == null && selected final mark = name == null && selected
@@ -77,19 +69,12 @@ class _ChatColorSwatchesState extends State<ChatColorSwatches> {
child: Padding(padding: const EdgeInsets.all(2), child: glyph), child: Padding(padding: const EdgeInsets.all(2), child: glyph),
) )
: glyph; : glyph;
final button = cupertino final button = IconButton(
? CupertinoButton( tooltip: label,
padding: const EdgeInsets.all(4), isSelected: selected,
minimumSize: const Size.square(kMinInteractiveDimensionCupertino), onPressed: () => _pick(name),
onPressed: () => _pick(name), icon: mark,
child: mark, );
)
: IconButton(
tooltip: label,
isSelected: selected,
onPressed: () => _pick(name),
icon: mark,
);
return Semantics( return Semantics(
key: Key('chat-color-${name ?? 'none'}'), key: Key('chat-color-${name ?? 'none'}'),
button: true, button: true,
@@ -117,17 +102,9 @@ class ChatColorSection extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino = final labelStyle = Theme.of(context).textTheme.bodySmall?.copyWith(
chatControlsStyleOf(context) == ChatControlsStyle.cupertino; color: Theme.of(context).colorScheme.onSurfaceVariant,
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,
);
return Padding( return Padding(
key: const Key('chat-color-section'), key: const Key('chat-color-section'),
padding: padding, padding: padding,
@@ -151,7 +128,6 @@ Future<void> showChatColorPicker(
required String? selected, required String? selected,
required ValueChanged<String?> onSelected, required ValueChanged<String?> onSelected,
}) async { }) async {
final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
Widget content(BuildContext sheet) => Column( Widget content(BuildContext sheet) => Column(
key: const Key('chat-color-sheet'), key: const Key('chat-color-sheet'),
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -159,7 +135,7 @@ Future<void> showChatColorPicker(
children: [ children: [
AppSheetHeader( AppSheetHeader(
title: 'Colour for $title', title: 'Colour for $title',
cupertino: cupertino, cupertino: false,
doneKey: const Key('chat-color-done'), doneKey: const Key('chat-color-done'),
), ),
Padding( 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>( await showModalBottomSheet<void>(
context: context, context: context,
showDragHandle: true, showDragHandle: true,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'chat_session_state.dart'; import 'chat_session_state.dart';
import 'session_activity_badge.dart'; import 'session_activity_badge.dart';
@@ -38,7 +37,6 @@ class ChatCompactAvatar extends StatelessWidget {
top: -2, top: -2,
start: -5, start: -5,
child: _Disc( child: _Disc(
cupertino: cupertino,
child: Icon( child: Icon(
active ? Icons.radio_button_checked : Icons.visibility_outlined, active ? Icons.radio_button_checked : Icons.visibility_outlined,
size: 14, size: 14,
@@ -58,7 +56,6 @@ class ChatCompactAvatar extends StatelessWidget {
top: -2, top: -2,
end: -3, end: -3,
child: _Disc( child: _Disc(
cupertino: cupertino,
child: Icon( child: Icon(
Icons.mark_chat_unread_outlined, Icons.mark_chat_unread_outlined,
key: const Key('chat-compact-unread'), key: const Key('chat-compact-unread'),
@@ -72,16 +69,13 @@ class ChatCompactAvatar extends StatelessWidget {
} }
class _Disc extends StatelessWidget { class _Disc extends StatelessWidget {
const _Disc({required this.cupertino, required this.child}); const _Disc({required this.child});
final bool cupertino;
final Widget child; final Widget child;
@override @override
Widget build(BuildContext context) => DecoratedBox( Widget build(BuildContext context) => DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
color: cupertino color: Theme.of(context).colorScheme.surface,
? CupertinoColors.systemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface,
), ),
child: Padding(padding: const EdgeInsets.all(1), child: child), child: Padding(padding: const EdgeInsets.all(1), child: child),
); );
@@ -1,12 +1,10 @@
import '../../../../core/servers/chat/federated_chat_gateway.dart'; import '../../../../core/servers/chat/federated_chat_gateway.dart';
import '../../../../core/servers/server_context.dart'; import '../../../../core/servers/server_context.dart';
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../domain/chat_cycle.dart'; import '../../domain/chat_cycle.dart';
import '../../domain/chat_sessions.dart'; import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import '../../domain/chat_colors.dart'; import '../../domain/chat_colors.dart';
import 'chat_color_palette.dart'; import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart'; import 'chat_visibility_marker.dart';
@@ -44,29 +42,18 @@ class ChatCompactSidebar extends StatelessWidget {
VoidCallback onPressed, { VoidCallback onPressed, {
bool selected = false, bool selected = false,
}) { }) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
return Semantics( return Semantics(
label: title, label: title,
button: true, button: true,
selected: selected, selected: selected,
onTap: onPressed, onTap: onPressed,
excludeSemantics: true, excludeSemantics: true,
child: cupertino child: IconButton(
? Tooltip( tooltip: title,
message: title, onPressed: onPressed,
child: CupertinoButton( icon: icon,
padding: const EdgeInsets.symmetric(vertical: 8), color: selected ? Theme.of(context).colorScheme.primary : null,
onPressed: onPressed, ),
child: icon,
),
)
: 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'); ].join('\n');
final color = final color =
chatColorShade(context, chatSessionColor(row)) ?? chatColorShade(context, chatSessionColor(row)) ??
(chatControlsStyleOf(context) == ChatControlsStyle.cupertino Theme.of(context).colorScheme.primary;
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary);
return ChatVisibilityMarker( return ChatVisibilityMarker(
sessionId: id, sessionId: id,
color: color, color: color,
@@ -122,9 +107,7 @@ class ChatCompactSidebar extends StatelessWidget {
running: running, running: running,
backgroundTasks: backgroundTasks, backgroundTasks: backgroundTasks,
unread: unread, unread: unread,
cupertino: cupertino: false,
chatControlsStyleOf(context) ==
ChatControlsStyle.cupertino,
), ),
if (machineName case final name?) if (machineName case final name?)
Text( Text(
@@ -159,11 +142,7 @@ class ChatCompactSidebar extends StatelessWidget {
Column( Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Icon( const Icon(Icons.menu_open),
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
? CupertinoIcons.sidebar_left
: Icons.menu_open,
),
const Text('Expand', textAlign: TextAlign.center), const Text('Expand', textAlign: TextAlign.center),
if (controller.repository.gateway is FederatedChatGateway) if (controller.repository.gateway is FederatedChatGateway)
const Text('All machines', textAlign: TextAlign.center) const Text('All machines', textAlign: TextAlign.center)
@@ -1,15 +1,12 @@
import '../../../../core/servers/server_context.dart'; import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
/// The create flow's heading and confirm, verbatim from the web client. /// The create flow's heading and confirm, verbatim from the web client.
const String chatCreateTitle = 'Start a chat'; const String chatCreateTitle = 'Start a chat';
const String chatCreateConfirmLabel = 'New chat'; const String chatCreateConfirmLabel = 'New chat';
/// Native chrome for the create dialog: standard Cupertino alert or Material /// Native chrome for the create dialog: a Material alert, with the same
/// alert, with the same disabled/submitting state in both hosts. /// disabled/submitting state for the confirm action.
class ChatCreateDialogFrame extends StatelessWidget { class ChatCreateDialogFrame extends StatelessWidget {
const ChatCreateDialogFrame({ const ChatCreateDialogFrame({
super.key, super.key,
@@ -30,24 +27,6 @@ class ChatCreateDialogFrame extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final enabled = canSubmit && !submitting; final enabled = canSubmit && !submitting;
final label = submitting ? 'Creating…' : chatCreateConfirmLabel; 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( return AlertDialog(
title: Text(ServerContext.metadata(context, chatCreateTitle)), title: Text(ServerContext.metadata(context, chatCreateTitle)),
content: content, content: content,
@@ -1,8 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
/// The web's directory prompt, also the directory picker's label. /// The web's directory prompt, also the directory picker's label.
const String chatCreatePrompt = 'Where should this chat live?'; const String chatCreatePrompt = 'Where should this chat live?';
@@ -70,11 +67,9 @@ class ChatCatalogFields extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
if (loading) return const Text('Loading directories…'); if (loading) return const Text('Loading directories…');
if (error != null) { if (error != null) {
return _message(cupertino, 'Unable to load chat options: $error'); return _message('Unable to load chat options: $error');
} }
final choices = chatDirectoryChoices(directories); final choices = chatDirectoryChoices(directories);
String directoryLabel(String choice) => String directoryLabel(String choice) =>
@@ -82,90 +77,50 @@ class ChatCatalogFields extends StatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
if (cupertino) // Keyed by the value so a folder chosen in the picker replaces the
CupertinoPickerField( // dropdown's retained initial value.
KeyedSubtree(
key: ValueKey('chat-create-directory-$directory'),
child: MaterialPickerField(
fieldKey: const Key('chat-create-server-directory'), fieldKey: const Key('chat-create-server-directory'),
label: chatCreatePrompt, label: chatCreatePrompt,
value: directory, value: directory,
values: choices, values: choices,
labelOf: directoryLabel, labelOf: directoryLabel,
onSelected: onDirectory, 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) if (onBrowse != null)
Align( Align(
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
child: cupertino child: TextButton.icon(
? CupertinoButton( key: const Key('chat-create-choose-folder'),
key: const Key('chat-create-choose-folder'), onPressed: onBrowse,
padding: const EdgeInsets.symmetric(vertical: 4), icon: const Icon(Icons.folder_open),
onPressed: onBrowse, label: const Text(chatChooseFolderLabel),
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),
),
), ),
if (backends.length > 1) if (backends.length > 1)
if (cupertino) MaterialPickerField(
CupertinoPickerField( fieldKey: const Key('chat-create-backend'),
fieldKey: const Key('chat-create-backend'), label: 'Chat harness',
label: 'Chat harness', value: backend,
value: backend, values: backends,
values: backends, labelOf: chatBackendLabel,
labelOf: chatBackendLabel, onSelected: onBackend,
onSelected: onBackend, ),
)
else
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( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(text), Text(text),
Align( Align(
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
child: cupertino child: TextButton(onPressed: onRetry, child: const Text('Retry')),
? CupertinoButton(
padding: EdgeInsets.zero,
onPressed: onRetry,
child: const Text('Retry'),
)
: TextButton(onPressed: onRetry, child: const Text('Retry')),
), ),
], ],
); );
@@ -221,68 +176,3 @@ class MaterialPickerField extends StatelessWidget {
return Text(_text(item), maxLines: 1, overflow: TextOverflow.ellipsis); 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 'package:flutter/material.dart';
import '../../../../core/servers/server_catalog.dart'; import '../../../../core/servers/server_catalog.dart';
import '../../../../core/servers/server_context.dart'; import '../../../../core/servers/server_context.dart';
import 'chat_adaptive.dart';
/// Select the machine before reading its harnesses or directory listing. /// Select the machine before reading its harnesses or directory listing.
Future<SavedServer?> chooseChatMachine(BuildContext context) async { Future<SavedServer?> chooseChatMachine(BuildContext context) async {
@@ -11,28 +9,6 @@ Future<SavedServer?> chooseChatMachine(BuildContext context) async {
final servers = scope?.notifier?.catalog.servers ?? const <SavedServer>[]; final servers = scope?.notifier?.catalog.servers ?? const <SavedServer>[];
if (servers.isEmpty) return null; if (servers.isEmpty) return null;
if (servers.length == 1) return servers.single; 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>( return showDialog<SavedServer>(
context: context, context: context,
builder: (context) => SimpleDialog( builder: (context) => SimpleDialog(
@@ -53,21 +29,6 @@ Future<SavedServer?> chooseChatMachine(BuildContext context) async {
} }
Future<void> showChatMachineError(BuildContext context, String message) { 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>( return showDialog<void>(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'chat_create_fields.dart'; import 'chat_create_fields.dart';
@@ -19,6 +18,7 @@ class ChatPromptChooser extends StatelessWidget {
static const careful = 'careful'; static const careful = 'careful';
static const lastUsed = 'last-used'; static const lastUsed = 'last-used';
/// Kept for callers; the Material switch and picker are always drawn.
final bool cupertino; final bool cupertino;
final bool enabled; final bool enabled;
final String choice; final String choice;
@@ -42,39 +42,22 @@ class ChatPromptChooser extends StatelessWidget {
Row( Row(
children: [ children: [
const Expanded(child: Text('Start with a prompt')), const Expanded(child: Text('Start with a prompt')),
if (cupertino) Switch(
CupertinoSwitch( key: const Key('chat-create-send-prompt'),
key: const Key('chat-create-send-prompt'), value: enabled,
value: enabled, onChanged: onEnabled,
onChanged: onEnabled, ),
)
else
Switch(
key: const Key('chat-create-send-prompt'),
value: enabled,
onChanged: onEnabled,
),
], ],
), ),
if (enabled) if (enabled)
if (cupertino) MaterialPickerField(
CupertinoPickerField( fieldKey: const Key('chat-create-prompt-choice'),
fieldKey: const Key('chat-create-prompt-choice'), label: 'Prompt',
label: 'Prompt', value: choices.contains(choice) ? choice : custom,
value: choices.contains(choice) ? choice : custom, values: choices,
values: choices, labelOf: label,
labelOf: label, onSelected: onChoice,
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,
),
], ],
); );
} }
@@ -1,18 +1,12 @@
import '../../../../core/servers/server_context.dart'; import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'chat_adaptive.dart';
/// State uses neutral text and shapes; the chat's chosen color stays identity. /// State uses neutral text and shapes; the chat's chosen color stays identity.
Color chatStateForeground(BuildContext context) => Color chatStateForeground(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino Theme.of(context).colorScheme.onSurface;
? CupertinoColors.label.resolveFrom(context)
: Theme.of(context).colorScheme.onSurface;
Color chatMetadataForeground(BuildContext context) => Color chatMetadataForeground(BuildContext context) =>
chatControlsStyleOf(context) == ChatControlsStyle.cupertino Theme.of(context).colorScheme.onSurfaceVariant;
? CupertinoColors.label.resolveFrom(context).withValues(alpha: .82)
: Theme.of(context).colorScheme.onSurfaceVariant;
class ChatSessionStateLine extends StatelessWidget { class ChatSessionStateLine extends StatelessWidget {
const ChatSessionStateLine({ const ChatSessionStateLine({
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart'; import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart'; import 'chat_adaptive.dart';
import 'session_list_cupertino.dart';
import 'session_list_material.dart'; import 'session_list_material.dart';
import 'session_row_style.dart'; import 'session_row_style.dart';
@@ -90,30 +89,6 @@ class ChatSessionsBody extends StatelessWidget {
if (loading && sessions.isEmpty) return const ChatLoadingIndicator(); if (loading && sessions.isEmpty) return const ChatLoadingIndicator();
final clearSearch = query.trim().isEmpty ? null : onClearSearch; final clearSearch = query.trim().isEmpty ? null : onClearSearch;
final duplicateTitles = duplicateChatTitles(visible); 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( return MaterialSessionList(
selectionOnly: selectionOnly, selectionOnly: selectionOnly,
sections: sections, 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( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: SegmentedBar( appBar: SegmentedBar(
@@ -1,7 +1,6 @@
import '../../../../core/servers/server_context.dart'; import '../../../../core/servers/server_context.dart';
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
@@ -11,7 +10,6 @@ import '../../data/chat_repository.dart';
import '../../data/directory_listing.dart'; import '../../data/directory_listing.dart';
import '../../domain/chat_commands.dart'; import '../../domain/chat_commands.dart';
import '../folder_picker/folder_picker_route.dart'; import '../folder_picker/folder_picker_route.dart';
import 'chat_adaptive.dart';
import 'chat_create_dialog_frame.dart'; import 'chat_create_dialog_frame.dart';
import 'chat_create_fields.dart'; import 'chat_create_fields.dart';
import 'chat_prompt_chooser.dart'; import 'chat_prompt_chooser.dart';
@@ -58,9 +56,7 @@ Future<JsonMap?> showChatCreateDialog(
prompts: prompts, prompts: prompts,
), ),
); );
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino return showDialog<JsonMap>(context: context, builder: (_) => dialog);
? showCupertinoDialog<JsonMap>(context: context, builder: (_) => dialog)
: showDialog<JsonMap>(context: context, builder: (_) => dialog);
} }
class CreateChatDialog extends StatefulWidget { class CreateChatDialog extends StatefulWidget {
@@ -306,8 +302,6 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final content = SingleChildScrollView( final content = SingleChildScrollView(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -334,21 +328,14 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
const SizedBox(height: 12), const SizedBox(height: 12),
const Text('Name'), const Text('Name'),
const SizedBox(height: 4), const SizedBox(height: 4),
if (cupertino) TextField(
CupertinoTextField( key: const Key('chat-create-name'),
key: const Key('chat-create-name'), controller: _name,
controller: _name, onChanged: (_) => _nameEdited = true,
onChanged: (_) => _nameEdited = true, ),
)
else
TextField(
key: const Key('chat-create-name'),
controller: _name,
onChanged: (_) => _nameEdited = true,
),
const SizedBox(height: 12), const SizedBox(height: 12),
ChatPromptChooser( ChatPromptChooser(
cupertino: cupertino, cupertino: false,
enabled: _sendPrompt, enabled: _sendPrompt,
choice: _promptChoice, choice: _promptChoice,
hasLastUsed: _savedPrompt?.text.trim().isNotEmpty == true, hasLastUsed: _savedPrompt?.text.trim().isNotEmpty == true,
@@ -360,38 +347,22 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
), ),
if (_sendPrompt) ...[ if (_sendPrompt) ...[
const SizedBox(height: 4), const SizedBox(height: 4),
if (cupertino) TextField(
CupertinoTextField( key: const Key('chat-create-instructions'),
key: const Key('chat-create-instructions'), controller: _instructions,
controller: _instructions, minLines: 2,
minLines: 2, maxLines: 4,
maxLines: 4, decoration: const InputDecoration(
placeholder: 'Write your custom prompt', hintText: '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;
});
},
), ),
onChanged: (value) {
setState(() {
_promptTouched = true;
_promptChoice = ChatPromptChooser.custom;
_customPrompt = value;
});
},
),
const SizedBox(height: 4), const SizedBox(height: 4),
const Text(chatCreateInstructionsHelper), const Text(chatCreateInstructionsHelper),
], ],
@@ -408,11 +379,7 @@ class _CreateChatDialogState extends State<CreateChatDialog> {
const SizedBox(height: 8), const SizedBox(height: 8),
Text( Text(
_formError!, _formError!,
style: TextStyle( style: TextStyle(color: Theme.of(context).colorScheme.error),
color: cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error,
),
), ),
], ],
], ],
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart'; import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
/// Renames one session through the shared server field. Save is disabled while /// 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 /// the trimmed name is blank, matching the web dialog. A refusal keeps the
@@ -17,9 +15,7 @@ Future<String?> showRenameChatDialog(
initialTitle: chatSessionTitle(session), initialTitle: chatSessionTitle(session),
onSubmit: onSubmit, onSubmit: onSubmit,
); );
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino return showDialog<String>(context: context, builder: (_) => dialog);
? showCupertinoDialog<String>(context: context, builder: (_) => dialog)
: showDialog<String>(context: context, builder: (_) => dialog);
} }
class _RenameChatDialog extends StatefulWidget { class _RenameChatDialog extends StatefulWidget {
@@ -76,44 +72,6 @@ class _RenameChatDialogState extends State<_RenameChatDialog> {
builder: (context, value, _) { builder: (context, value, _) {
final canSave = !_saving && value.text.trim().isNotEmpty; final canSave = !_saving && value.text.trim().isNotEmpty;
final error = _error; 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( return AlertDialog(
// A long server refusal plus a 2x helper text can exceed the dialog // A long server refusal plus a 2x helper text can exceed the dialog
// height at 320px; scroll the content instead of clipping it. // 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 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart'; import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_row_style.dart'; import 'session_row_style.dart';
import '../../../../ui/layout/app_overflow_menu.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 { Future<bool> confirmCloseChat(BuildContext context, JsonMap session) async {
final title = chatSessionTitle(session); final title = chatSessionTitle(session);
final body = closeChatConfirmation(title); final body = closeChatConfirmation(title);
final confirmed = chatControlsStyleOf(context) == ChatControlsStyle.cupertino final confirmed = await showDialog<bool>(
? await showCupertinoDialog<bool>( context: context,
context: context, builder: (context) => AlertDialog(
builder: (context) => CupertinoAlertDialog( title: const Text('Close chat?'),
title: const Text('Close chat?'), content: Text(body),
content: Text(body), actions: [
actions: [ TextButton(
CupertinoDialogAction( onPressed: () => Navigator.pop(context, false),
onPressed: () => Navigator.pop(context, false), child: const Text('Cancel'),
child: const Text('Cancel'), ),
), FilledButton(
CupertinoDialogAction( onPressed: () => Navigator.pop(context, true),
isDestructiveAction: true, child: const Text('Close chat'),
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'),
),
],
),
);
return confirmed == true; return confirmed == true;
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// The corner badge a chat's avatar wears for its live activity: the /// The corner badge a chat's avatar wears for its live activity: the
@@ -14,7 +13,7 @@ Widget? chatSessionActivityBadge({
return Semantics( return Semantics(
key: const Key('chat-row-working'), key: const Key('chat-row-working'),
label: 'Chat is working', label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino), child: const _WorkingBadge(),
); );
} }
if (backgroundTasks <= 0) return null; if (backgroundTasks <= 0) return null;
@@ -28,23 +27,20 @@ Widget? chatSessionActivityBadge({
excludeFromSemantics: true, excludeFromSemantics: true,
child: Semantics( child: Semantics(
label: label, 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. /// The badge's own disc in the surface colour, so it reads over any avatar.
class _BadgeDisc extends StatelessWidget { class _BadgeDisc extends StatelessWidget {
const _BadgeDisc({required this.cupertino, required this.child}); const _BadgeDisc({required this.child});
final bool cupertino;
final Widget child; final Widget child;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final background = cupertino final background = Theme.of(context).colorScheme.surface;
? CupertinoColors.systemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface;
return DecoratedBox( return DecoratedBox(
decoration: BoxDecoration(color: background, shape: BoxShape.circle), decoration: BoxDecoration(color: background, shape: BoxShape.circle),
child: Padding(padding: const EdgeInsets.all(2), child: child), child: Padding(padding: const EdgeInsets.all(2), child: child),
@@ -53,37 +49,28 @@ class _BadgeDisc extends StatelessWidget {
} }
class _WorkingBadge extends StatelessWidget { class _WorkingBadge extends StatelessWidget {
const _WorkingBadge({required this.cupertino}); const _WorkingBadge();
final bool cupertino;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _BadgeDisc( return const _BadgeDisc(
cupertino: cupertino, child: SizedBox.square(
child: cupertino dimension: 12,
? const CupertinoActivityIndicator(radius: 6) child: CircularProgressIndicator(strokeWidth: 2),
: const SizedBox.square( ),
dimension: 12,
child: CircularProgressIndicator(strokeWidth: 2),
),
); );
} }
} }
class _BackgroundBadge extends StatelessWidget { class _BackgroundBadge extends StatelessWidget {
const _BackgroundBadge({required this.cupertino, required this.count}); const _BackgroundBadge({required this.count});
final bool cupertino;
final int count; final int count;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final color = cupertino final color = Theme.of(context).colorScheme.onSurfaceVariant;
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
return _BadgeDisc( return _BadgeDisc(
cupertino: cupertino,
child: Text( child: Text(
'$count', '$count',
style: TextStyle( style: TextStyle(
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart'; import '../../../../core/api_gateway.dart';
import 'chat_adaptive.dart';
import 'chat_create_fields.dart'; import 'chat_create_fields.dart';
/// Harness identity, independent of favorite/activity state. Native icon sizing /// Harness identity, independent of favorite/activity state. Native icon sizing
@@ -17,29 +15,14 @@ class SessionHarnessIcon extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final value = '${session['backend'] ?? ''}'.trim(); final value = '${session['backend'] ?? ''}'.trim();
final backend = value.isEmpty ? 'opencode' : value; final backend = value.isEmpty ? 'opencode' : value;
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final Widget mark = switch (backend) { final Widget mark = switch (backend) {
'opencode' || 'claude' => ImageIcon( 'opencode' || 'claude' => ImageIcon(
AssetImage('assets/harnesses/$backend.png'), AssetImage('assets/harnesses/$backend.png'),
color: color, color: color,
), ),
'codex' => Icon( 'codex' => Icon(Icons.code, color: color),
cupertino 'pi' => Icon(Icons.functions, color: color),
? CupertinoIcons.chevron_left_slash_chevron_right _ => Icon(Icons.terminal, color: color),
: 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,
),
}; };
return Semantics( return Semantics(
label: '${chatBackendLabel(backend)} harness', 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}); typedef SessionListItem = ({Key key, WidgetBuilder build});
/// A chat section as a sliver: its heading and its rows, built only when on /// 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({ Widget chatSessionSection({
required ChatSessionSection section, required ChatSessionSection section,
required ChatSectionFolds folds, required ChatSectionFolds folds,
@@ -1,5 +1,4 @@
import '../../../../core/servers/server_context.dart'; import '../../../../core/servers/server_context.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../core/api_gateway.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_colors.dart';
import '../../domain/chat_list_activity.dart'; import '../../domain/chat_list_activity.dart';
import '../../domain/chat_sessions.dart'; import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_color_palette.dart'; import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart'; import 'chat_visibility_marker.dart';
import 'chat_session_state.dart'; import 'chat_session_state.dart';
@@ -63,20 +61,11 @@ class ChatSessionRow extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}'; final id = '${session['id'] ?? ''}';
final cupertino = final accent = Theme.of(context).colorScheme.primary;
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final shade = chatColorShade(context, chatSessionColor(session)); final shade = chatColorShade(context, chatSessionColor(session));
final marker = shade ?? accent; final marker = shade ?? accent;
final tint = AppListRow.tintFor(context, shade, cupertino: cupertino); final tint = AppListRow.tintFor(context, shade, cupertino: false);
final background = cupertino final background = Theme.of(context).scaffoldBackgroundColor;
? CupertinoDynamicColor.resolve(
CupertinoTheme.of(context).scaffoldBackgroundColor,
context,
)
: Theme.of(context).scaffoldBackgroundColor;
// On a phone the chat's page grows out of this row and shrinks back // 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. // into it; the surface it starts from is the row's tint over the list.
return ContainerTransformSource( return ContainerTransformSource(
@@ -89,8 +78,6 @@ class ChatSessionRow extends StatelessWidget {
} }
Widget _marked(BuildContext context, String id, Color marker, Color accent) { Widget _marked(BuildContext context, String id, Color marker, Color accent) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed'; final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
final unread = unseen && !closed; final unread = unseen && !closed;
final text = chatSessionSubtitle(session); final text = chatSessionSubtitle(session);
@@ -110,7 +97,7 @@ class ChatSessionRow extends StatelessWidget {
active: selected, active: selected,
child: AppListRow( child: AppListRow(
key: Key('chat-row-$id'), key: Key('chat-row-$id'),
cupertino: cupertino, cupertino: false,
selected: selected, selected: selected,
selectedFill: Colors.transparent, selectedFill: Colors.transparent,
emphasized: unread, emphasized: unread,
@@ -131,7 +118,7 @@ class ChatSessionRow extends StatelessWidget {
alignment: PlaceholderAlignment.middle, alignment: PlaceholderAlignment.middle,
child: Padding( child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4), 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. /// As tall as the title's text, so it follows text scaling.
class _Star extends StatelessWidget { class _Star extends StatelessWidget {
const _Star({required this.cupertino, required this.color}); const _Star({required this.color});
final bool cupertino;
final Color color; final Color color;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final size = DefaultTextStyle.of(context).style.fontSize ?? 14; final size = DefaultTextStyle.of(context).style.fontSize ?? 14;
return Icon( return Icon(
cupertino ? CupertinoIcons.star_fill : Icons.star, Icons.star,
key: const Key('chat-row-starred'), key: const Key('chat-row-starred'),
size: MediaQuery.textScalerOf(context).scale(size), size: MediaQuery.textScalerOf(context).scale(size),
color: color, color: color,
@@ -229,8 +215,6 @@ class ChatSessionAvatar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final Color fill; final Color fill;
final Color mark; final Color mark;
final color = chatColorShade(context, chatSessionColor(session)); final color = chatColorShade(context, chatSessionColor(session));
@@ -241,12 +225,6 @@ class ChatSessionAvatar extends StatelessWidget {
fill = color.withValues( fill = color.withValues(
alpha: chatColorDarkSurface(context) ? 0.26 : 0.16, 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 { } else {
final scheme = Theme.of(context).colorScheme; final scheme = Theme.of(context).colorScheme;
fill = selected fill = selected
@@ -258,7 +236,7 @@ class ChatSessionAvatar extends StatelessWidget {
foreground: mark, foreground: mark,
background: fill, background: fill,
badge: chatSessionActivityBadge( badge: chatSessionActivityBadge(
cupertino: cupertino, cupertino: false,
running: running, running: running,
backgroundTasks: backgroundTasks, backgroundTasks: backgroundTasks,
), ),
@@ -1,6 +1,5 @@
import 'dart:ui' show Tristate; import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/layout/app_list_row.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'; import 'fake_chat_gateway.dart';
void main() { void main() {
for (final cupertino in [false, true]) { for (final brightness in Brightness.values) {
for (final brightness in Brightness.values) { testWidgets('Material $brightness: active row '
testWidgets( 'follows selection, survives refresh and clears with the route', (
'${cupertino ? 'Cupertino' : 'Material'} $brightness: active row ' tester,
'follows selection, survives refresh and clears with the route', ) async {
(tester) async { final semantics = tester.ensureSemantics();
final semantics = tester.ensureSemantics(); try {
try { final gateway = FakeChatGateway()
final gateway = FakeChatGateway() ..sessionsReply = {
..sessionsReply = { 'chat_sessions': [
'chat_sessions': [ {'id': 'a', 'title': 'Same title'},
{'id': 'a', 'title': 'Same title'}, {'id': 'b', 'title': 'Same title'},
{'id': 'b', 'title': 'Same title'}, ],
], };
}; addTearDown(gateway.pushed.close);
addTearDown(gateway.pushed.close); final store = MemoryChatSessionLocalStore();
final store = MemoryChatSessionLocalStore(); String? selected = 'a'; // A routed chat need not have been tapped.
String? selected = 'a'; // A routed chat need not have been tapped. late StateSetter rebuild;
late StateSetter rebuild; final screen = StatefulBuilder(
final screen = StatefulBuilder( builder: (context, setState) {
builder: (context, setState) { rebuild = setState;
rebuild = setState; return ChatSessionsScreen(
return ChatSessionsScreen( gateway: gateway,
gateway: gateway, localStore: store,
localStore: store, activeSessionId: selected,
activeSessionId: selected, onOpen: (session) => setState(() => selected = session['id']),
onOpen: (session) => setState(() => selected = session['id']),
);
},
); );
await tester.pumpWidget( },
cupertino );
? CupertinoApp( await tester.pumpWidget(
theme: CupertinoThemeData(brightness: brightness), MaterialApp(
home: screen, theme: ThemeData(brightness: brightness),
) home: screen,
: MaterialApp( ),
theme: ThemeData(brightness: brightness), );
home: screen, await tester.pumpAndSettle();
),
);
await tester.pumpAndSettle();
void expectRow(String id, bool active) { void expectRow(String id, bool active) {
final row = find.byKey(Key('chat-row-$id')); final row = find.byKey(Key('chat-row-$id'));
expect( expect(
tester.getSemantics(row).flagsCollection.isSelected == tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue, Tristate.isTrue,
active, active,
); );
expect(tester.widget<AppListRow>(row).selected, active); expect(tester.widget<AppListRow>(row).selected, active);
final surface = find.descendant( final surface = find.descendant(
of: row, of: row,
matching: find.byKey(appListRowSurfaceKey), matching: find.byKey(appListRowSurfaceKey),
); );
final color = cupertino final color = tester.widget<Material>(surface).color;
? tester.widget<ColoredBox>(surface).color expect(color, const Color(0x00000000));
: tester.widget<Material>(surface).color; final highlight = tester.widget<AnimatedContainer>(
expect(color, const Color(0x00000000)); find.byKey(ValueKey('chat-visibility-$id')),
final highlight = tester.widget<AnimatedContainer>( );
find.byKey(ValueKey('chat-visibility-$id')), final gradient =
); (highlight.decoration as BoxDecoration).gradient!
final gradient = as LinearGradient;
(highlight.decoration as BoxDecoration).gradient! expect(gradient.colors.first.a > 0, active);
as LinearGradient; expect(gradient.colors.last.a > 0, active);
expect(gradient.colors.first.a > 0, active); }
expect(gradient.colors.last.a > 0, active);
}
expectRow('a', true); expectRow('a', true);
expectRow('b', false); expectRow('b', false);
await tester.tap(find.byKey(const Key('chat-row-b'))); await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expectRow('a', false); expectRow('a', false);
expectRow('b', true); expectRow('b', true);
gateway.sessionsReply = { gateway.sessionsReply = {
'chat_sessions': [ 'chat_sessions': [
{'id': 'b', 'title': 'Renamed active chat'}, {'id': 'b', 'title': 'Renamed active chat'},
{'id': 'a', 'title': 'Same title'}, {'id': 'a', 'title': 'Same title'},
], ],
}; };
await tester.tap(find.byKey(const Key('chat-refresh'))); await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expectRow('b', true); expectRow('b', true);
expectRow('a', false); expectRow('a', false);
rebuild(() => selected = null); rebuild(() => selected = null);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expectRow('a', false); expectRow('a', false);
expectRow('b', false); expectRow('b', false);
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink()); await tester.pumpWidget(const SizedBox.shrink());
} finally { } finally {
semantics.dispose(); semantics.dispose();
} }
}, });
);
}
} }
} }
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -39,7 +38,6 @@ FakeChatGateway _gateway() {
Future<void> _pump( Future<void> _pump(
WidgetTester tester, WidgetTester tester,
FakeChatGateway gateway, { FakeChatGateway gateway, {
required bool cupertino,
required Brightness brightness, required Brightness brightness,
}) async { }) async {
final screen = ChatSessionsScreen( final screen = ChatSessionsScreen(
@@ -48,21 +46,13 @@ Future<void> _pump(
localStore: MemoryChatSessionLocalStore(), localStore: MemoryChatSessionLocalStore(),
); );
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp( theme: ThemeData(
theme: CupertinoThemeData(brightness: brightness), platform: TargetPlatform.android,
home: MediaQuery( brightness: brightness,
data: MediaQueryData(platformBrightness: brightness), ),
child: screen, home: screen,
), ),
)
: MaterialApp(
theme: ThemeData(
platform: TargetPlatform.android,
brightness: brightness,
),
home: screen,
),
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
@@ -78,110 +68,83 @@ Color _accentColor(WidgetTester tester, String id) =>
tester.widget<AppListRow>(_accent(id)).accent!; tester.widget<AppListRow>(_accent(id)).accent!;
void main() { void main() {
// The row menu is Material only. for (final brightness in Brightness.values) {
for (final cupertino in [false]) { final host = 'Material ${brightness.name}';
for (final brightness in Brightness.values) {
final host = '${cupertino ? 'Cupertino' : 'Material'} ${brightness.name}';
testWidgets('$host: a coloured chat wears its colour, a plain one none', ( testWidgets('$host: a coloured chat wears its colour, a plain one none', (
tester, tester,
) async { ) async {
await _pump( await _pump(tester, _gateway(), brightness: brightness);
tester, expect(_accent('s1'), findsOneWidget);
_gateway(), expect(_accent('s2'), findsNothing);
cupertino: cupertino, final accent = _accentColor(tester, 's1');
brightness: brightness, // The avatar takes the same colour as the bar.
); final avatar = tester.widget<AppListAvatar>(
expect(_accent('s1'), findsOneWidget); find.descendant(
expect(_accent('s2'), findsNothing); of: find.byKey(const Key('chat-row-s1')),
final accent = _accentColor(tester, 's1'); matching: find.byType(AppListAvatar),
// The avatar takes the same colour as the bar. ),
final avatar = tester.widget<AppListAvatar>( );
find.descendant( expect(avatar.foreground, accent);
of: find.byKey(const Key('chat-row-s1')), // A teal shade, not the host's accent or a grey.
matching: find.byType(AppListAvatar), expect(accent.g, greaterThan(accent.r));
), expect(accent.b, greaterThan(accent.r));
); // The row tint is faint: the selected fill stays the stronger mark.
expect(avatar.foreground, accent); final tint = tester
// A teal shade, not the host's accent or a grey. .widget<Material>(
expect(accent.g, greaterThan(accent.r)); find.descendant(
expect(accent.b, greaterThan(accent.r)); of: find.byKey(const Key('chat-row-s1')),
// The row tint is faint: the selected fill stays the stronger mark. matching: find.byKey(appListRowSurfaceKey),
final tint = cupertino ),
? tester )
.widget<ColoredBox>( .color!;
find.descendant( expect(tint.a, inInclusiveRange(0.05, 0.13));
of: find.byKey(const Key('chat-row-s1')), // Shades are tuned per brightness.
matching: find.byKey(appListRowSurfaceKey), final shade = accent.computeLuminance();
), if (brightness == Brightness.dark) {
) expect(shade, greaterThan(0.2));
.color } else {
: tester expect(shade, lessThan(0.55));
.widget<Material>( }
find.descendant( });
of: find.byKey(const Key('chat-row-s1')),
matching: find.byKey(appListRowSurfaceKey), testWidgets('$host: the row menu sets and clears the colour', (
), tester,
) ) async {
.color!; final gateway = _gateway();
expect(tint.a, inInclusiveRange(0.05, 0.13)); await _pump(tester, gateway, brightness: brightness);
// Shades are tuned per brightness. await tester.tap(
final shade = accent.computeLuminance(); find.descendant(
if (brightness == Brightness.dark) { of: find.byKey(const Key('chat-actions-s2')),
expect(shade, greaterThan(0.2)); matching: find.byType(IconButton),
} else { ),
expect(shade, lessThan(0.55)); );
} 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', ( await tester.tap(find.byKey(const Key('chat-color-none')));
tester, await tester.pumpAndSettle();
) async { expect(gateway.lastFields('chat_color'), {
final gateway = _gateway(); 'chat_query': {'session_id': 's2', 'color': null},
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-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 { testWidgets('a long-press on a row opens the colour choice', (tester) async {
final gateway = _gateway(); final gateway = _gateway();
await _pump( await _pump(tester, gateway, brightness: Brightness.light);
tester,
gateway,
cupertino: false,
brightness: Brightness.light,
);
await tester.longPress(find.text('Plain chat')); await tester.longPress(find.text('Plain chat'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget); expect(find.byKey(const Key('chat-color-sheet')), findsOneWidget);
@@ -1,6 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.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, tester,
) async { ) async {
final gateway = FakeChatGateway(); final gateway = FakeChatGateway();
gateway.directoriesHandler = () => gateway.directoriesHandler = () =>
Future.error(StateError('Server did not return chat directories.')); 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.tap(find.byKey(const Key('chat-new-chat')));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
@@ -124,77 +124,6 @@ void main() {
expect(fields.containsKey('instructions'), isFalse); 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', ( testWidgets('a created chat opens before the list refresh completes', (
tester, tester,
) async { ) async {
@@ -1,7 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.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_create_prompt_store.dart';
import 'package:pipelines_app/features/chat/data/chat_repository.dart'; import 'package:pipelines_app/features/chat/data/chat_repository.dart';
@@ -243,36 +242,6 @@ void main() {
'Saved preset', '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 { 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.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', ( testWidgets('material rename disables Save while the name is blank', (
tester, tester,
) async { ) async {
@@ -114,27 +89,6 @@ void main() {
expect(gateway.count('chat_rename'), 0); 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', ( testWidgets('material rename helper wraps instead of truncating at 2x', (
tester, tester,
) async { ) async {
@@ -29,29 +29,6 @@ void main() {
expect(tester.takeException(), isNull); 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', ( testWidgets('Material create catalog fits real paths at 320px and 2x', (
tester, tester,
) async { ) async {
@@ -88,21 +65,4 @@ void main() {
expect(tester.takeException(), isNull); expect(tester.takeException(), isNull);
expect(find.byKey(const Key('chat-create-instructions')), findsOneWidget); 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/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -158,57 +157,4 @@ void main() {
); );
expect(tester.takeException(), isNull); 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.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')), matching: find.byKey(const Key('chat-row-working')),
); );
Future<void> _pump( Future<void> _pump(WidgetTester tester, FakeChatGateway fake) async {
WidgetTester tester,
FakeChatGateway fake, {
bool cupertino = false,
}) async {
final screen = ChatSessionsScreen( final screen = ChatSessionsScreen(
gateway: fake, gateway: fake,
onOpen: (_) {}, onOpen: (_) {},
localStore: MemoryChatSessionLocalStore(), localStore: MemoryChatSessionLocalStore(),
); );
await tester.pumpWidget( await tester.pumpWidget(
cupertino MaterialApp(
? CupertinoApp(home: screen) theme: ThemeData(platform: TargetPlatform.android),
: MaterialApp( home: screen,
theme: ThemeData(platform: TargetPlatform.android), ),
home: screen,
),
); );
// A spinner never settles, so pump a few frames instead. // A spinner never settles, so pump a few frames instead.
for (var i = 0; i < 5; i++) { for (var i = 0; i < 5; i++) {
@@ -177,21 +170,6 @@ void main() {
expect(_badge('s1'), findsNothing); 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', () { group('controller', () {
late FakeChatGateway fake; late FakeChatGateway fake;
late ChatSessionsController controller; late ChatSessionsController controller;
@@ -16,35 +16,27 @@ List<JsonMap> _many() => [
]; ];
void main() { void main() {
for (final cupertino in [false, true]) { testWidgets('Material list scrolls behind the bar and starts below it', (
final host = cupertino ? 'Cupertino' : 'Material'; tester,
) async {
final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': _many()};
await pumpMaterialChat(tester, gateway);
testWidgets('$host list scrolls behind the bar and starts below it', ( final bar = tester.getRect(find.byType(SegmentedBar));
tester, final list = tester.getRect(find.byType(CustomScrollView).first);
) async { // The list reaches under the bar ...
final gateway = FakeChatGateway() expect(list.top, lessThan(bar.bottom));
..sessionsReply = {'chat_sessions': _many()}; // ... yet at rest its first row is clear of it.
if (cupertino) { final first = tester.getRect(
await pumpCupertinoChat(tester, gateway); find.descendant(
} else { of: find.byKey(const ValueKey('chat-section-Chats')),
await pumpMaterialChat(tester, gateway); matching: find.byType(SectionHeading),
} ),
);
final bar = tester.getRect(find.byType(SegmentedBar)); expect(first.top, greaterThanOrEqualTo(bar.bottom));
final list = tester.getRect(find.byType(CustomScrollView).first); expect(tester.takeException(), isNull);
// 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', ( testWidgets('the standalone Material list has one New chat, in the bar', (
tester, tester,
@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -29,22 +28,6 @@ Future<void> _pump(
await tester.pumpAndSettle(); 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; late MemoryChatSessionLocalStore _store;
class _DeferredStore implements ChatSessionLocalStore { class _DeferredStore implements ChatSessionLocalStore {
@@ -339,31 +322,4 @@ void main() {
expect(find.byKey(const Key('chat-row-unread')), findsNothing); expect(find.byKey(const Key('chat-row-unread')), findsNothing);
expect(delayed.saved?.isUnseen('s1'), isFalse); 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 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -96,87 +95,31 @@ void main() {
expect(find.textContaining('No chats match'), findsNothing); expect(find.textContaining('No chats match'), findsNothing);
}); });
testWidgets( testWidgets('load failure wraps the reason and hides the empty message', (
'Cupertino app renders standard controls, groups and renames without Material', tester,
(tester) async { ) async {
_inventoryViewport(tester); usePhoneSurface(tester);
final gateway = FakeChatGateway() final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()}; ..sessionsHandler = () => Future.error(
await pumpCupertinoChat(tester, gateway); StateError(
'server unavailable while listing chat sessions for this operator',
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',
); );
await tester.tap(find.text('Save')); await pumpMaterialChat(tester, gateway);
await tester.pumpAndSettle();
expect(gateway.lastFields('chat_rename'), {
'chat_rename': {'session_id': 's2', 'title': 'Renamed on Cupertino'},
});
await expandClosedChats(tester); const message =
await tester.ensureVisible(find.byKey(const Key('chat-actions-s4'))); 'Bad state: server unavailable while listing chat sessions '
await tester.tap(find.byKey(const Key('chat-actions-s4'))); 'for this operator';
await tester.pumpAndSettle(); expect(find.text(message), findsOneWidget);
await tester.tap(find.text('Reopen')); expect(find.text('No chat sessions on this server yet.'), findsNothing);
await tester.pumpAndSettle(); final messageBox = tester.renderObject<RenderBox>(find.text(message));
expect(gateway.lastFields('chat_reopen'), { expect(
'chat_query': {'session_id': 's4'}, 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( });
'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);
},
);
testWidgets('closed chats start folded away behind their heading', ( testWidgets('closed chats start folded away behind their heading', (
tester, tester,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -9,126 +8,105 @@ import 'fake_chat_gateway.dart';
void main() { void main() {
// The row menu is Material only. // The row menu is Material only.
for (final cupertino in [false]) { for (final beside in [false, true]) {
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);
},
);
}
testWidgets( testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} updates available directions on mounted rows', 'Material split menu passes selected chat ${beside ? 'beside' : 'below'}',
(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',
(tester) async { (tester) async {
final gateway = FakeChatGateway() final gateway = FakeChatGateway()
..sessionsReply = {'chat_sessions': sampleSessions()}; ..sessionsReply = {'chat_sessions': sampleSessions()};
addTearDown(gateway.pushed.close); addTearDown(gateway.pushed.close);
final opened = <JsonMap>[]; final opened = <JsonMap>[];
final right = <JsonMap>[];
final below = <JsonMap>[];
final screen = ChatSessionsScreen( final screen = ChatSessionsScreen(
gateway: gateway, gateway: gateway,
onOpen: opened.add, onOpen: opened.add,
onOpenBeside: right.add,
onOpenBelow: below.add,
localStore: MemoryChatSessionLocalStore(), localStore: MemoryChatSessionLocalStore(),
); );
await tester.pumpWidget( await tester.pumpWidget(MaterialApp(home: screen));
cupertino ? CupertinoApp(home: screen) : MaterialApp(home: screen),
);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-actions-s2'))); await tester.tap(find.byKey(const Key('chat-actions-s2')));
await tester.pumpAndSettle(); 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 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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_session_state.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_session_state.dart';
@@ -161,69 +160,53 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
for (final cupertino in [false, true]) { for (final brightness in Brightness.values) {
for (final brightness in Brightness.values) { testWidgets(
testWidgets( 'native metadata and state contrast on tinted rows $brightness',
'native metadata and state contrast on tinted rows $cupertino $brightness', (tester) async {
(tester) async { late BuildContext context;
late BuildContext context; final theme = ThemeData(brightness: brightness);
final theme = ThemeData(brightness: brightness); final body = Builder(
final body = Builder( builder: (value) {
builder: (value) { context = value;
context = value; return const SizedBox();
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( for (final foreground in [
cupertino chatStateForeground(context),
? CupertinoApp( chatMetadataForeground(context),
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',
]) { ]) {
final color = chatColorShade(context, name)!; final rendered = Color.alphaBlend(foreground, background);
final background = Color.alphaBlend( final a = rendered.computeLuminance(),
color.withValues( b = background.computeLuminance();
alpha: brightness == Brightness.dark ? .30 : .22, final ratio = (a > b
), ? (a + .05) / (b + .05)
surface, : (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/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/api_gateway.dart';
@@ -57,23 +56,6 @@ Future<void> pumpMaterialChat(
await tester.pumpAndSettle(); 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 /// The screen's iOS/macOS path: Cupertino controls under the app's ordinary
/// `MaterialApp` root, with no Material or CupertinoTheme ancestor. /// `MaterialApp` root, with no Material or CupertinoTheme ancestor.
Future<void> pumpIosMaterialChat( Future<void> pumpIosMaterialChat(
@@ -35,29 +35,4 @@ void main() {
expect(find.text('Open chat'), findsOneWidget); expect(find.text('Open chat'), findsOneWidget);
expect(tester.takeException(), isNull); 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/material.dart';
import 'package:flutter_test/flutter_test.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_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'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart';
void main() { void main() {
for (final cupertino in [false, true]) { for (final backend in ['opencode', 'claude']) {
for (final backend in ['opencode', 'claude']) { testWidgets('$backend avatar beside title; the menu stars and unstars', (
testWidgets( tester,
'$backend avatar beside title; the menu stars and unstars ($cupertino)', ) async {
(tester) async { var starred = true;
var starred = true; final body = StatefulBuilder(
final body = StatefulBuilder( builder: (context, setState) {
builder: (context, setState) { final sections = [
final sections = [ (
( title: 'Chats',
title: 'Chats', sessions: [
sessions: [ <String, dynamic>{
<String, dynamic>{ 'id': 's',
'id': 's', 'title': 'Harness chat',
'title': 'Harness chat', 'backend': backend,
'backend': backend, 'starred': starred,
'starred': starred, },
}, ],
], ),
), ];
]; void star(Map<String, dynamic> _) =>
void star(Map<String, dynamic> _) => setState(() => starred = !starred);
setState(() => starred = !starred); return MaterialSessionList(
return cupertino sections: sections,
? CupertinoSessionList( emptyMessage: null,
sections: sections, duplicateTitles: const {},
emptyMessage: null, onOpen: (_) {},
duplicateTitles: const {}, onRename: (_) {},
onOpen: (_) {}, onClose: (_) {},
onRename: (_) {}, onReopen: (_) {},
onClose: (_) {}, onStar: star,
onReopen: (_) {}, onHide: (_) {},
onStar: star, onClearSearch: null,
onHide: (_) {}, isUnseen: (_) => false,
onClearSearch: null, errorFor: (_) => 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,
);
},
); );
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);
});
} }
} }