Keep chat controls readable and expose labeled app navigation

This commit is contained in:
2026-11-07 20:46:02 +00:00
parent 68c0ad3caa
commit 4bbbe01633
20 changed files with 582 additions and 159 deletions
@@ -29,6 +29,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
final mode = selected == null || !beside
? ChatSidebarMode.expanded
: _sidebarMode;
final navigation = ShellBarScope.maybeOf(context);
return Stack(
fit: StackFit.expand,
children: [
@@ -41,6 +42,15 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
),
if (mode == ChatSidebarMode.compact)
ChatCompactSidebar(
navigation: navigation?.registry.canNavigate == true
? ShellDestinationMenu(
cupertino:
chatControlsStyleOf(context) ==
ChatControlsStyle.cupertino,
current: AppDestination.chat,
onSelected: navigation!.registry.navigateTo,
)
: null,
controller: _sessionsForSidebar,
folds: _foldsForSidebar,
activeSessionId: selected,
@@ -1,6 +1,7 @@
import 'package:flutter/widgets.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/segmented_bar_overlay.dart';
import '../domain/chat_colors.dart';
import '../ui/sessions/chat_color_palette.dart';
@@ -65,12 +66,13 @@ class ChatColorWash extends StatelessWidget {
);
}
final top = MediaQuery.paddingOf(context).top;
final barHeight = top + SegmentedBarOverlay.reservedHeightOf(context);
return Positioned(
top: top,
left: 0,
right: 0,
height: fadeBelowBar,
child: wash(top, top, top + fadeBelowBar),
child: wash(barHeight, barHeight, barHeight + fadeBelowBar),
);
}
}
@@ -23,8 +23,10 @@ class ChatModeControl extends StatefulWidget {
required this.mode,
required this.modeName,
this.onChanged,
this.showLabel = false,
});
final bool showLabel;
final ApiGateway gateway;
final String sessionId;
@@ -98,7 +100,8 @@ class _ChatModeControlState extends State<ChatModeControl> {
final label = _name;
// At phone widths the title and a named mode cannot both remain useful.
// Keep the mode's shield, whose semantic label and picker still name it.
final iconOnly = MediaQuery.sizeOf(context).width < 600;
final iconOnly =
!widget.showLabel && MediaQuery.sizeOf(context).width < 600;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -22,6 +22,7 @@ class ChatModelControl extends StatefulWidget {
required this.sessionId,
required this.session,
this.onChanged,
this.showLabel = false,
this.answeredBy = '',
});
@@ -29,6 +30,7 @@ class ChatModelControl extends StatefulWidget {
/// no model on record.
final String answeredBy;
final bool showLabel;
final ApiGateway gateway;
final String sessionId;
@@ -116,7 +118,7 @@ class _ChatModelControlState extends State<ChatModelControl> {
: widget.answeredBy.isNotEmpty
? widget.answeredBy
: '${backend.isEmpty ? 'opencode' : backend} default';
final compact = MediaQuery.sizeOf(context).width < 600;
final compact = !widget.showLabel && MediaQuery.sizeOf(context).width < 600;
final content = compact
? const Icon(Icons.memory_outlined)
: Row(
@@ -48,55 +48,86 @@ class ChatThreadHeader extends StatelessWidget {
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
return SegmentedBar(
cupertino: cupertino,
automaticallyImplyLeading: false,
// The platform's own Back, so it reads and behaves as every other
// page's Back; its key stays for finders.
leading: showBack
? SegmentedBackButton(
key: const Key('chat-back'),
cupertino: cupertino,
onPressed: onBack,
)
: null,
title: title.isEmpty ? 'Chat' : title,
subtitle: folder,
subtitleIcon: cupertino ? CupertinoIcons.folder : Icons.folder_outlined,
onTitlePressed: onInfo,
titleSemanticLabel: 'Chat information',
titleKey: const Key('chat-info'),
separateActionIslands: true,
actions: [
if (controls.isNotEmpty)
_ControlIsland(
key: const Key('chat-model-permission-island'),
children: controls,
),
if (actions.isNotEmpty || moreActions.isNotEmpty)
Row(
key: const Key('chat-actions-island'),
return LayoutBuilder(
builder: (context, constraints) {
final narrow = constraints.maxWidth < 800;
final bar = SegmentedBar(
cupertino: cupertino,
automaticallyImplyLeading: false,
// The platform's own Back, so it reads and behaves as every other
// page's Back; its key stays for finders.
leading: showBack
? SegmentedBackButton(
key: const Key('chat-back'),
cupertino: cupertino,
onPressed: onBack,
)
: null,
title: title.isEmpty ? 'Chat' : title,
subtitle: folder,
subtitleIcon: cupertino
? CupertinoIcons.folder
: Icons.folder_outlined,
onTitlePressed: onInfo,
titleSemanticLabel: 'Chat information',
titleKey: const Key('chat-info'),
separateActionIslands: true,
actions: [
if (!narrow && controls.isNotEmpty)
_ControlIsland(
key: const Key('chat-model-permission-island'),
children: controls,
),
if (actions.isNotEmpty || moreActions.isNotEmpty)
Row(
key: const Key('chat-actions-island'),
mainAxisSize: MainAxisSize.min,
children: [
...actions,
// Unknown action widgets retain their original behavior and stay
// visible; only the explicit overflow contract becomes a menu.
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
SegmentedMoreButton(
cupertino: cupertino,
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
],
),
],
),
],
bottomPadding: narrow ? 8 : 16,
backdrop: backdrop,
);
return ColoredBox(
color: cupertino
? CupertinoTheme.of(context).scaffoldBackgroundColor
: Theme.of(context).colorScheme.surface,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
...actions,
// Unknown action widgets retain their original behavior and stay
// visible; only the explicit overflow contract becomes a menu.
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
SegmentedMoreButton(
cupertino: cupertino,
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
],
bar,
if (narrow && controls.isNotEmpty)
Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 8),
child: SegmentedPill(
cupertino: cupertino,
child: _ControlIsland(
key: const Key('chat-model-permission-island'),
fill: true,
vertical: constraints.maxWidth < 340,
children: controls,
),
),
),
],
),
],
bottomPadding: 16,
backdrop: backdrop,
);
},
);
}
}
@@ -104,11 +135,27 @@ class ChatThreadHeader extends StatelessWidget {
/// Related selectors share the available width. Each remains a real control;
/// they never migrate into the unrelated actions menu.
class _ControlIsland extends StatelessWidget {
const _ControlIsland({super.key, required this.children});
const _ControlIsland({
super.key,
required this.children,
this.fill = false,
this.vertical = false,
});
final List<Widget> children;
final bool fill;
final bool vertical;
@override
Widget build(BuildContext context) => Row(
mainAxisSize: MainAxisSize.min,
children: [for (final child in children) Flexible(child: child)],
);
Widget build(BuildContext context) => vertical
? Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
)
: Row(
mainAxisSize: fill ? MainAxisSize.max : MainAxisSize.min,
children: [
for (final child in children)
if (fill) Expanded(child: child) else Flexible(child: child),
],
);
}
@@ -1040,8 +1040,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
// Under the app shell the conversation takes over the app's bar (title,
// Back, model, information) instead of drawing a second bar below it.
final inShellBar = ShellBar.available(context);
// The conversation's bar floats over the transcript's top and history
// scrolls behind it; the transcript ends at the composer's top edge, so
// The measured header owns its space so scrolled text never falls
// behind the controls; the transcript ends at the composer's top edge, so
// nothing renders behind the composer and the viewport shrinks as the
// composer grows.
// Every input of the composer comes from this widget's configuration,
@@ -1072,6 +1072,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
final page = FloatingBarOverlay(
bar: ChatPaneBarReveal(bar: composerBar),
child: SegmentedBarOverlay(
reserveSpace: true,
bar: ChatPaneBarReveal(bar: _header(context, inShellBar)),
child: NotificationListener<ScrollMetricsNotification>(
onNotification: _onScrollMetrics,
@@ -1341,6 +1342,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
controls: [
if (hasModel)
ChatModelControl(
showLabel: true,
key: ValueKey<String>('chat-model-${widget.sessionId}'),
gateway: widget.gateway,
sessionId: widget.sessionId,
@@ -1356,6 +1358,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
/// The session's permission mode, keyed per session so another chat
/// re-reads its own modes.
Widget _modeControl() => ChatModeControl(
showLabel: true,
key: ValueKey<String>('chat-mode-${widget.sessionId}'),
gateway: widget.gateway,
sessionId: widget.sessionId,
+1
View File
@@ -1,5 +1,6 @@
import '../../shell/destination.dart';
import '../../shell/shell_bar.dart';
import '../../shell/shell_destination_menu.dart';
import '../../shell/detail_page.dart';
import '../../shell/empty_detail_pane.dart';
import '../../shell/list_detail.dart';
+2
View File
@@ -74,6 +74,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
@override
void initState() {
super.initState();
_bar.onNavigate = _select;
_selected = widget.destination ?? AppDestination.pipelines;
_visited.add(_selected);
HardwareKeyboard.instance.addHandler(_handleDestinationKeyEvent);
@@ -192,6 +193,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
preferredWidth: _paneWidths.widthFor(_selected.name),
alignment: AlignmentDirectional.bottomStart,
child: FloatingDestinationBar(
showLabels: true,
cupertino: widget.cupertino,
currentIndex: index,
onTap: (value) => _select(shellTabDestinations[value]),
+6
View File
@@ -64,6 +64,12 @@ class ShellBarSpec {
/// on a run event) then rebuilds nothing, and a badge change rebuilds only
/// the tab bar.
class ShellBarRegistry extends ChangeNotifier {
ValueChanged<AppDestination>? onNavigate;
bool get canNavigate => onNavigate != null && !_disposed;
void navigateTo(AppDestination destination) {
if (!_disposed) onNavigate?.call(destination);
}
final Map<AppDestination, (Object, ShellBarSpec)> _specs = {};
final Map<(AppDestination, ShellBadgeKind), int> _badges = {};
final _Notifier _bar = _Notifier();
+69
View File
@@ -0,0 +1,69 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'destination.dart';
/// Native, labeled destination access when the full tab bar cannot fit a rail.
class ShellDestinationMenu extends StatelessWidget {
const ShellDestinationMenu({
super.key,
required this.cupertino,
required this.current,
required this.onSelected,
});
final bool cupertino;
final AppDestination current;
final ValueChanged<AppDestination> onSelected;
Future<void> _choose(BuildContext context) async {
final value = await showCupertinoModalPopup<AppDestination>(
context: context,
builder: (context) => CupertinoActionSheet(
title: const Text('Main navigation'),
actions: [
for (final destination in AppDestination.values)
CupertinoActionSheetAction(
isDefaultAction: destination == current,
onPressed: () => Navigator.pop(context, destination),
child: Text(destinationDetails(destination).label),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (value != null && context.mounted) onSelected(value);
}
@override
Widget build(BuildContext context) {
final child = Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(cupertino ? CupertinoIcons.square_grid_2x2 : Icons.apps),
const Text('Menu'),
],
);
if (cupertino) {
return Semantics(
button: true,
label: 'Main navigation',
child: CupertinoButton(onPressed: () => _choose(context), child: child),
);
}
return PopupMenuButton<AppDestination>(
tooltip: 'Main navigation',
onSelected: onSelected,
itemBuilder: (context) => [
for (final destination in AppDestination.values)
CheckedPopupMenuItem(
value: destination,
checked: destination == current,
child: Text(destinationDetails(destination).label),
),
],
child: Padding(padding: const EdgeInsets.all(8), child: child),
);
}
}
@@ -7,6 +7,7 @@ import '../motion/motion.dart';
import 'floating_bar_layout.dart';
import 'floating_tab_button.dart';
import 'floating_tab_motion.dart';
import 'floating_destination_labels.dart';
/// A tab bar which floats above the bottom edge as a row of separate round
/// frosted [GlassPill] buttons, one per tab, instead of a full-width system
@@ -37,10 +38,14 @@ class FloatingDestinationBar extends StatefulWidget {
required this.items,
this.edge = FloatingBarEdge.bottom,
this.alignment,
this.showLabels = false,
});
final bool cupertino;
/// Main app navigation keeps names visible; dense page tabs can stay icons.
final bool showLabels;
/// Where the row sits in the width it is given, at [FloatingBarEdge.bottom]:
/// the trailing end by default. The shell centres its tabs under the list
/// pane while a list shows beside an open item.
@@ -194,6 +199,17 @@ class _FloatingDestinationBarState extends State<FloatingDestinationBar>
}
Widget _row(BuildContext context, double width) {
if (widget.showLabels) {
return FloatingDestinationLabels(
key: FloatingDestinationBar.rowKey,
cupertino: cupertino,
labels: [for (final item in items) item.label],
selected: currentIndex,
buttonBuilder: (index) => _button(context, index),
onTap: widget.onTap,
backdrop: _backdrop,
);
}
final gap = _gap(width);
// As tall as the selected (largest) button; the others are centred on
// it, and every gap stays the same while a button grows or shrinks.
@@ -0,0 +1,84 @@
import 'dart:ui' show SemanticsRole;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// Content-driven main navigation captions keep names visible without scaling
/// down touch targets. Narrow lists and large text wrap into another row.
class FloatingDestinationLabels extends StatelessWidget {
const FloatingDestinationLabels({
super.key,
required this.cupertino,
required this.labels,
required this.selected,
required this.buttonBuilder,
required this.onTap,
required this.backdrop,
});
final bool cupertino;
final List<String> labels;
final int selected;
final Widget Function(int) buttonBuilder;
final ValueChanged<int> onTap;
final BackdropKey backdrop;
@override
Widget build(BuildContext context) {
final color = cupertino
? CupertinoColors.label.resolveFrom(context)
: Theme.of(context).colorScheme.onSurface;
final surface = cupertino
? CupertinoColors.secondarySystemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainer;
final style = cupertino
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle
: Theme.of(context).textTheme.labelSmall!;
return Semantics(
role: SemanticsRole.tabBar,
container: true,
explicitChildNodes: true,
child: DecoratedBox(
decoration: BoxDecoration(
color: surface,
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.all(8),
child: BackdropGroup(
backdropKey: backdrop,
child: Wrap(
alignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 8,
runSpacing: 8,
children: [
for (var index = 0; index < labels.length; index++)
GestureDetector(
key: ValueKey('destination-label-${labels[index]}'),
excludeFromSemantics: true,
onTap: () => onTap(index),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
buttonBuilder(index),
ExcludeSemantics(
child: Text(
labels[index],
style: style.copyWith(
color: color,
fontWeight: index == selected
? FontWeight.w600
: style.fontWeight,
),
),
),
],
),
),
],
),
),
),
),
);
}
}
+38 -6
View File
@@ -12,14 +12,24 @@ class SegmentedBarOverlay extends StatelessWidget {
super.key,
required this.bar,
required this.child,
this.reserveSpace = false,
});
final Widget bar;
final Widget child;
/// Gives reading content its own viewport below the measured bar.
final bool reserveSpace;
static double reservedHeightOf(BuildContext context) =>
context
.dependOnInheritedWidgetOfExactType<_ReservedBarHeight>()
?.height ??
0;
@override
Widget build(BuildContext context) => CustomMultiChildLayout(
delegate: _OverlayLayout(),
delegate: _OverlayLayout(reserveSpace),
children: [
// Painted first, so the bar draws (and takes taps) above it.
LayoutId(
@@ -32,9 +42,14 @@ class SegmentedBarOverlay extends StatelessWidget {
final media = MediaQuery.of(context);
return MediaQuery(
data: media.copyWith(
padding: media.padding.copyWith(top: barHeight),
padding: media.padding.copyWith(
top: reserveSpace ? 0 : barHeight,
),
),
child: _ReservedBarHeight(
height: reserveSpace ? barHeight : 0,
child: child,
),
child: child,
);
},
),
@@ -70,6 +85,8 @@ class _ContentConstraints extends BoxConstraints {
}
class _OverlayLayout extends MultiChildLayoutDelegate {
_OverlayLayout(this.reserveSpace);
final bool reserveSpace;
@override
void performLayout(Size size) {
final bar = layoutChild(
@@ -82,11 +99,26 @@ class _OverlayLayout extends MultiChildLayoutDelegate {
positionChild(_Slot.bar, Offset.zero);
layoutChild(
_Slot.content,
_ContentConstraints(size, barHeight: bar.height),
_ContentConstraints(
Size(
size.width,
(size.height - (reserveSpace ? bar.height : 0)).clamp(0, size.height),
),
barHeight: bar.height,
),
);
positionChild(_Slot.content, Offset.zero);
positionChild(_Slot.content, Offset(0, reserveSpace ? bar.height : 0));
}
@override
bool shouldRelayout(_OverlayLayout oldDelegate) => false;
bool shouldRelayout(_OverlayLayout oldDelegate) =>
reserveSpace != oldDelegate.reserveSpace;
}
class _ReservedBarHeight extends InheritedWidget {
const _ReservedBarHeight({required this.height, required super.child});
final double height;
@override
bool updateShouldNotify(_ReservedBarHeight oldWidget) =>
height != oldWidget.height;
}
@@ -41,7 +41,7 @@ Widget _app(_Gateway gateway, {int sync = 0}) => MaterialApp(
body: ChatScreen(gateway: gateway, syncToken: sync),
),
);
Future<_Gateway> _setup(WidgetTester tester) async {
Future<_Gateway> _setup(WidgetTester tester, {bool inShell = false}) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1800, 1000);
tester.view.devicePixelRatio = 1;
@@ -60,7 +60,21 @@ Future<_Gateway> _setup(WidgetTester tester) async {
]);
};
addTearDown(gateway.close);
await tester.pumpWidget(_app(gateway));
await tester.pumpWidget(
inShell
? MaterialApp(
home: AdaptiveShell(
cupertino: false,
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
AppDestination.runs: (_) =>
const Center(child: Text('Runs destination')),
},
),
)
: _app(gateway),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pumpAndSettle();
@@ -79,6 +93,35 @@ Future<void> _split(WidgetTester tester, String id, String action) async {
}
void main() {
testWidgets(
'compact navigation reaches Runs and returns without losing draft',
(tester) async {
await _setup(tester, inShell: true);
final state = tester.state(_thread('a'));
await tester.enterText(_input('a'), 'Keep compact draft');
await tester.drag(
find.byKey(const ValueKey('list-detail-divider')),
const Offset(-500, 0),
);
await tester.pumpAndSettle();
expect(find.text('Menu'), findsOneWidget);
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
await tester.tap(find.text('Runs'));
await tester.pumpAndSettle();
expect(find.text('Runs destination'), findsOneWidget);
await tester.tap(find.byTooltip('Chat'));
await tester.pumpAndSettle();
expect(find.text('Menu'), findsOneWidget);
expect(tester.state(_thread('a')), same(state));
expect(
tester.widget<EditableText>(_input('a')).controller.text,
'Keep compact draft',
);
expect(tester.takeException(), isNull);
},
);
testWidgets('phone peeks fit a small keyboard viewport at large text', (
tester,
) async {
@@ -226,44 +226,47 @@ void main() {
}
});
testWidgets('Cupertino mode is icon-only below 600px', (tester) async {
if (!cupertino) return;
final semantics = tester.ensureSemantics();
_size(tester, const Size(560, 800));
await _pump(
tester,
cupertino: true,
messages: 1,
session: const {
'id': 's',
'backend': 'opencode',
'model': 'p/sonnet-4-5',
'mode': 'default',
'mode_name': 'Ask for permission',
},
);
testWidgets(
'Cupertino narrow header displays the current permission value',
(tester) async {
if (!cupertino) return;
final semantics = tester.ensureSemantics();
_size(tester, const Size(560, 800));
await _pump(
tester,
cupertino: true,
messages: 1,
session: const {
'id': 's',
'backend': 'opencode',
'model': 'p/sonnet-4-5',
'mode': 'default',
'mode_name': 'Ask for permission',
},
);
final mode = find.byKey(const Key('chat-mode'));
expect(mode, findsOneWidget);
expect(
find.descendant(of: mode, matching: find.text('Ask for permission')),
findsNothing,
);
expect(
tester.getSemantics(mode).label,
contains('Change mode, currently Ask for permission'),
);
await tester.tap(mode);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget);
// The fixture has no chat_modes catalog, but the recorded session mode
// remains visible in the sheet.
expect(
find.byKey(const ValueKey('chat-mode-option-default')),
findsOneWidget,
);
expect(find.text('Ask for permission'), findsOneWidget);
semantics.dispose();
});
final mode = find.byKey(const Key('chat-mode'));
expect(mode, findsOneWidget);
expect(
find.descendant(of: mode, matching: find.text('Ask for permission')),
findsOneWidget,
);
expect(
tester.getSemantics(mode).label,
contains('Change mode, currently Ask for permission'),
);
await tester.tap(mode);
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget);
// The fixture has no chat_modes catalog, but the recorded session mode
// remains visible in the sheet.
expect(
find.byKey(const ValueKey('chat-mode-option-default')),
findsOneWidget,
);
expect(find.text('Ask for permission'), findsWidgets);
semantics.dispose();
},
);
}
}
@@ -65,8 +65,11 @@ void main() {
) async {
await _pump(tester, peek: false, reveal: 1);
expect(header, findsOneWidget);
expect(listTop(tester), greaterThan(8));
expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5));
expect(listTop(tester), 8);
expect(
tester.getTopLeft(find.byType(ChatTranscriptScrollView)).dy,
closeTo(tester.getBottomLeft(header).dy, .5),
);
});
testWidgets('a resting peek keeps its bar offstage and reads from the top', (
@@ -95,8 +98,8 @@ void main() {
await _pump(tester, peek: true, reveal: .4);
expect(header, findsOneWidget);
expect(
listTop(tester),
closeTo(tester.getSize(header).height * .4 + 8, .5),
tester.getTopLeft(find.byType(ChatTranscriptScrollView)).dy,
closeTo(tester.getSize(header).height * .4, .5),
);
final fade = tester.widget<FadeTransition>(
find.ancestor(of: header, matching: find.byType(FadeTransition)).first,
@@ -41,62 +41,69 @@ void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host header keeps back, title pill and model on one row', (
tester,
) async {
_useNarrowText(tester);
final semantics = tester.ensureSemantics();
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage(const []);
gateway.subscribe = () async => const {};
var backed = 0;
testWidgets(
'$host narrow header keeps native back/title and readable model',
(tester) async {
_useNarrowText(tester);
final semantics = tester.ensureSemantics();
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage(const []);
gateway.subscribe = () async => const {};
var backed = 0;
await tester.pumpWidget(
_host(
ChatThreadView(
gateway: gateway,
sessionId: 's',
title: _title,
session: _session,
onBack: () => backed++,
await tester.pumpWidget(
_host(
ChatThreadView(
gateway: gateway,
sessionId: 's',
title: _title,
session: _session,
onBack: () => backed++,
),
cupertino: cupertino,
),
cupertino: cupertino,
),
);
await tester.pumpAndSettle();
);
await tester.pumpAndSettle();
final title = find.text(_title);
final model = find.byKey(const Key('chat-model'));
final info = find.byKey(const Key('chat-info'));
final back = find.byKey(const Key('chat-back'));
expect(title, findsOneWidget);
expect(model, findsOneWidget);
expect(info, findsOneWidget);
expect(back, findsOneWidget);
expect(tester.takeException(), isNull);
// Back is the platform's own control, as on every other page.
expect(
find.descendant(of: back, matching: findNativeBack()),
findsOneWidget,
);
final title = find.text(_title);
final model = find.byKey(const Key('chat-model'));
final info = find.byKey(const Key('chat-info'));
final back = find.byKey(const Key('chat-back'));
expect(title, findsOneWidget);
expect(model, findsOneWidget);
expect(info, findsOneWidget);
expect(back, findsOneWidget);
expect(tester.takeException(), isNull);
// Back is the platform's own control, as on every other page.
expect(
find.descendant(of: back, matching: findNativeBack()),
findsOneWidget,
);
// One floating row of separate pieces: the round Back, the title pill
// (which is the information control and holds the title), then the
// model in the trailing pill.
double centerY(Finder finder) => tester.getCenter(finder).dy;
expect((centerY(back) - centerY(info)).abs(), lessThan(16));
expect((centerY(model) - centerY(info)).abs(), lessThan(16));
expect(find.descendant(of: info, matching: title), findsOneWidget);
double right(Finder finder) => tester.getTopRight(finder).dx;
expect(right(back), lessThanOrEqualTo(tester.getTopLeft(info).dx));
expect(right(info), lessThanOrEqualTo(tester.getTopLeft(model).dx));
// One floating row of separate pieces: the round Back, the title pill
// (which is the information control and holds the title), then the
// model in the trailing pill.
double centerY(Finder finder) => tester.getCenter(finder).dy;
expect((centerY(back) - centerY(info)).abs(), lessThan(16));
expect(
tester.getTopLeft(model).dy,
greaterThanOrEqualTo(tester.getBottomLeft(info).dy),
);
expect(find.descendant(of: info, matching: title), findsOneWidget);
double right(Finder finder) => tester.getTopRight(finder).dx;
expect(right(back), lessThanOrEqualTo(tester.getTopLeft(info).dx));
expect(
find.textContaining('an-extremely-long-recorded-model-id'),
findsOneWidget,
);
await tester.tap(back);
await tester.pump();
expect(backed, 1);
semantics.dispose();
});
await tester.tap(back);
await tester.pump();
expect(backed, 1);
semantics.dispose();
},
);
}
for (final cupertino in [false, true]) {
@@ -151,10 +158,17 @@ void main() {
final actions = find.byKey(const Key('chat-actions-island'));
expect(selectors, findsOneWidget);
expect(actions, findsOneWidget);
expect(
tester.getTopRight(selectors).dx,
lessThan(tester.getTopLeft(actions).dx),
);
if (width >= 800) {
expect(
tester.getTopRight(selectors).dx,
lessThan(tester.getTopLeft(actions).dx),
);
} else {
expect(
tester.getTopLeft(selectors).dy,
greaterThanOrEqualTo(tester.getBottomLeft(actions).dy),
);
}
expect(find.byKey(const Key('chat-next')), findsNothing);
expect(find.text('Next chat'), findsNothing);
expect(find.byKey(const Key('chat-model')), findsOneWidget);
@@ -0,0 +1,34 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/shell_destination_menu.dart';
import 'package:pipelines_app/shell/destination.dart';
void main() {
for (final cupertino in [false, true]) {
testWidgets('compact menu exposes all named destinations ($cupertino)', (
tester,
) async {
AppDestination? selected;
final menu = ShellDestinationMenu(
cupertino: cupertino,
current: AppDestination.chat,
onSelected: (value) => selected = value,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: menu))
: MaterialApp(home: Scaffold(body: menu)),
);
await tester.tap(find.text('Menu'));
await tester.pumpAndSettle();
for (final name in ['Pipelines', 'Runs', 'Chat', 'Search', 'Settings']) {
expect(find.text(name), findsOneWidget);
}
await tester.tap(find.text('Runs'));
await tester.pumpAndSettle();
expect(selected, AppDestination.runs);
expect(tester.takeException(), isNull);
});
}
}
@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overlay.dart';
void main() {
testWidgets('reserved header gives scrolling text an independent viewport', (
tester,
) async {
final scroll = ScrollController();
addTearDown(scroll.dispose);
double? topPadding;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: SegmentedBarOverlay(
reserveSpace: true,
bar: const SizedBox(key: Key('header'), height: 80),
child: Builder(
builder: (context) {
topPadding = MediaQuery.paddingOf(context).top;
return ListView(
controller: scroll,
children: List.generate(
50,
(i) => ListTile(title: Text('Line $i')),
),
);
},
),
),
),
),
);
expect(
tester.getTopLeft(find.byType(ListView)).dy,
tester.getBottomLeft(find.byKey(const Key('header'))).dy,
);
expect(topPadding, 0);
await tester.drag(find.byType(ListView), const Offset(0, -300));
await tester.pumpAndSettle();
expect(scroll.offset, greaterThan(0));
expect(tester.getTopLeft(find.byType(ListView)).dy, 80);
expect(tester.takeException(), isNull);
});
}
+4
View File
@@ -95,6 +95,10 @@ JsonMap _chatRow(int i) {
'title': _colorTitles[i % _colorTitles.length],
'directory': i.isEven ? '/workspace/demo' : '/workspace/site',
'model': 'claude-opus',
if (_params['header'] == '1') ...{
'mode': 'default',
'mode_name': 'Ask for permission',
},
'backend': 'claude',
'updated_at': DateTime.now().millisecondsSinceEpoch - (i + 1) * 600000,
if (_colorStarred.contains(i)) 'starred': true,