Polish adaptive app chrome
This commit is contained in:
@@ -230,9 +230,15 @@ class _ChangesViewerState extends State<ChangesViewer> {
|
||||
bar: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
heightFactor: 1,
|
||||
widthFactor: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: GlassPill(cupertino: usesCupertinoHost(context), child: pager),
|
||||
child: IntrinsicWidth(
|
||||
child: GlassPill(
|
||||
cupertino: usesCupertinoHost(context),
|
||||
child: pager,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: content,
|
||||
|
||||
@@ -60,6 +60,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
final picker = _ChatModePicker(
|
||||
load: () => repository.modes(widget.sessionId),
|
||||
current: _mode,
|
||||
currentName: _name,
|
||||
cupertino: cupertino,
|
||||
choose: (mode) async {
|
||||
final applied = await repository.selectMode(widget.sessionId, mode.id);
|
||||
@@ -95,6 +96,9 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
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 = cupertino && MediaQuery.sizeOf(context).width < 600;
|
||||
final content = Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -103,8 +107,10 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
? CupertinoIcons.shield_lefthalf_fill
|
||||
: Icons.shield_outlined,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
|
||||
if (!iconOnly) ...[
|
||||
const SizedBox(width: 4),
|
||||
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
|
||||
],
|
||||
],
|
||||
);
|
||||
const key = Key('chat-mode');
|
||||
@@ -146,12 +152,14 @@ class _ChatModePicker extends StatefulWidget {
|
||||
const _ChatModePicker({
|
||||
required this.load,
|
||||
required this.current,
|
||||
required this.currentName,
|
||||
required this.cupertino,
|
||||
required this.choose,
|
||||
});
|
||||
|
||||
final Future<({List<JsonMap> modes, String current})> Function() load;
|
||||
final String current;
|
||||
final String currentName;
|
||||
final bool cupertino;
|
||||
final Future<void> Function(_Mode mode) choose;
|
||||
|
||||
@@ -165,6 +173,23 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
bool _busy = false;
|
||||
String? _error;
|
||||
|
||||
/// The session row has already named the selected mode. Some harnesses do
|
||||
/// not return a catalog, so retain that known value in the picker rather
|
||||
/// than opening an action sheet with no visible mode.
|
||||
List<_Mode> get _visibleModes {
|
||||
final modes = _modes;
|
||||
if (modes == null ||
|
||||
_current.isEmpty ||
|
||||
widget.currentName.isEmpty ||
|
||||
modes.any((mode) => mode.id == _current)) {
|
||||
return modes ?? const [];
|
||||
}
|
||||
return [
|
||||
...modes,
|
||||
(id: _current, name: widget.currentName, description: ''),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -230,7 +255,8 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
|
||||
Widget _materialSheet(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final modes = _modes;
|
||||
final modes = _visibleModes;
|
||||
final loaded = _modes != null;
|
||||
return SafeArea(
|
||||
child: ListView(
|
||||
key: const Key('chat-mode-sheet'),
|
||||
@@ -248,7 +274,7 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
style: TextStyle(color: theme.colorScheme.error),
|
||||
),
|
||||
),
|
||||
if (modes == null)
|
||||
if (!loaded)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
@@ -274,7 +300,8 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
|
||||
Widget _cupertinoSheet(BuildContext context) {
|
||||
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
final modes = _modes;
|
||||
final modes = _visibleModes;
|
||||
final loaded = _modes != null;
|
||||
return CupertinoActionSheet(
|
||||
key: const Key('chat-mode-sheet'),
|
||||
title: const Text('Mode'),
|
||||
@@ -285,11 +312,11 @@ class _ChatModePickerState extends State<_ChatModePicker> {
|
||||
color: CupertinoColors.systemRed.resolveFrom(context),
|
||||
),
|
||||
)
|
||||
: modes == null
|
||||
: !loaded
|
||||
? const CupertinoActivityIndicator()
|
||||
: null,
|
||||
actions: [
|
||||
for (final mode in modes ?? const <_Mode>[])
|
||||
for (final mode in modes)
|
||||
CupertinoActionSheetAction(
|
||||
key: ValueKey<String>('chat-mode-option-${mode.id}'),
|
||||
onPressed: () => _choose(mode),
|
||||
|
||||
@@ -7,9 +7,6 @@ import '../../../ui/adaptive/floating_bar_layout.dart';
|
||||
import 'graph_viewport.dart';
|
||||
import 'graph_viewport_controller.dart';
|
||||
|
||||
/// The expanded presentation's close wording (`Close`).
|
||||
const String graphExpandedClose = 'Close';
|
||||
|
||||
/// Builds the same canvas for another viewport, with the selection that
|
||||
/// presentation is showing.
|
||||
typedef GraphExpandedCanvasBuilder =
|
||||
@@ -88,6 +85,7 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
|
||||
key: const Key('graph-expanded-viewport'),
|
||||
controller: _controller,
|
||||
contentSize: widget.contentSize,
|
||||
showControls: false,
|
||||
// The larger box fits the whole graph, as the web does when its panel
|
||||
// expands; a later resize re-fits until the reader pans or zooms, then
|
||||
// only clamps.
|
||||
@@ -107,13 +105,12 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
|
||||
navigationBar: SegmentedBar(
|
||||
cupertino: true,
|
||||
automaticallyImplyLeading: false,
|
||||
leading: SegmentedBackButton(cupertino: true, onPressed: _close),
|
||||
title: widget.title,
|
||||
actions: [
|
||||
CupertinoButton(
|
||||
key: const Key('graph-expanded-close'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
onPressed: _close,
|
||||
child: const Text(graphExpandedClose),
|
||||
_GraphFitButton(
|
||||
cupertino: true,
|
||||
onPressed: _controller.fitToViewport,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -126,11 +123,11 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
|
||||
cupertino: false,
|
||||
title: widget.title,
|
||||
automaticallyImplyLeading: false,
|
||||
leading: SegmentedBackButton(cupertino: false, onPressed: _close),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('graph-expanded-close'),
|
||||
onPressed: _close,
|
||||
child: const Text(graphExpandedClose),
|
||||
_GraphFitButton(
|
||||
cupertino: false,
|
||||
onPressed: _controller.fitToViewport,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -139,6 +136,37 @@ class _GraphExpandedViewState extends State<GraphExpandedView> {
|
||||
}
|
||||
}
|
||||
|
||||
class _GraphFitButton extends StatelessWidget {
|
||||
const _GraphFitButton({required this.cupertino, required this.onPressed});
|
||||
|
||||
final bool cupertino;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => MergeSemantics(
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: graphFitLabel,
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
key: const Key('graph-fit'),
|
||||
padding: const EdgeInsets.all(8),
|
||||
onPressed: onPressed,
|
||||
child: const ExcludeSemantics(child: Icon(CupertinoIcons.resize)),
|
||||
)
|
||||
: Tooltip(
|
||||
message: graphFitLabel,
|
||||
excludeFromSemantics: true,
|
||||
child: IconButton(
|
||||
key: const Key('graph-fit'),
|
||||
onPressed: onPressed,
|
||||
icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Pushes [GraphExpandedView] with the host's native full-screen transition.
|
||||
///
|
||||
/// This is the seam a Graph tab or run detail can call: pass the measured
|
||||
|
||||
@@ -25,6 +25,7 @@ class GraphViewport extends StatefulWidget {
|
||||
required this.contentSize,
|
||||
required this.child,
|
||||
this.onExpand,
|
||||
this.showControls = true,
|
||||
});
|
||||
|
||||
final GraphViewportController controller;
|
||||
@@ -38,6 +39,10 @@ class GraphViewport extends StatefulWidget {
|
||||
/// Opens the expanded presentation. Null hides the expand control.
|
||||
final VoidCallback? onExpand;
|
||||
|
||||
/// Whether this canvas draws its own fit/expand pill. Full-screen graph
|
||||
/// views place Fit in their top-bar actions instead.
|
||||
final bool showControls;
|
||||
|
||||
@override
|
||||
State<GraphViewport> createState() => _GraphViewportState();
|
||||
}
|
||||
@@ -111,31 +116,32 @@ class _GraphViewportState extends State<GraphViewport> {
|
||||
),
|
||||
),
|
||||
),
|
||||
PositionedDirectional(
|
||||
top: 8,
|
||||
end: 8,
|
||||
child: GlassPill(
|
||||
cupertino: usesCupertinoHost(context),
|
||||
child: Wrap(
|
||||
spacing: 2,
|
||||
children: [
|
||||
_ViewportButton(
|
||||
buttonKey: const Key('graph-fit'),
|
||||
icon: _fitIcon(context),
|
||||
label: graphFitLabel,
|
||||
onPressed: widget.controller.fitToViewport,
|
||||
),
|
||||
if (widget.onExpand != null)
|
||||
if (widget.showControls)
|
||||
PositionedDirectional(
|
||||
top: 8,
|
||||
end: 8,
|
||||
child: GlassPill(
|
||||
cupertino: usesCupertinoHost(context),
|
||||
child: Wrap(
|
||||
spacing: 2,
|
||||
children: [
|
||||
_ViewportButton(
|
||||
buttonKey: const Key('graph-expand'),
|
||||
icon: _expandIcon(context),
|
||||
label: graphExpandLabel,
|
||||
onPressed: widget.onExpand,
|
||||
buttonKey: const Key('graph-fit'),
|
||||
icon: _fitIcon(context),
|
||||
label: graphFitLabel,
|
||||
onPressed: widget.controller.fitToViewport,
|
||||
),
|
||||
],
|
||||
if (widget.onExpand != null)
|
||||
_ViewportButton(
|
||||
buttonKey: const Key('graph-expand'),
|
||||
icon: _expandIcon(context),
|
||||
label: graphExpandLabel,
|
||||
onPressed: widget.onExpand,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -93,9 +93,15 @@ class _StageDefinitionViewState extends State<StageDefinitionView> {
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
if (fields.any((field) => field.block)) ...[
|
||||
MarkdownModeSwitch(
|
||||
raw: _raw,
|
||||
onChanged: (raw) => setState(() => _raw = raw),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 220),
|
||||
child: MarkdownModeSwitch(
|
||||
raw: _raw,
|
||||
onChanged: (raw) => setState(() => _raw = raw),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
@@ -254,10 +254,10 @@ class SegmentedBar extends StatelessWidget
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
background,
|
||||
background.withValues(alpha: background.a * 0.85),
|
||||
background.withValues(alpha: background.a * 0.95),
|
||||
background.withValues(alpha: 0),
|
||||
],
|
||||
stops: const [0, 0.45, 1],
|
||||
stops: const [0, 0.5, 1],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -120,7 +120,8 @@ class SegmentedTitlePill extends StatelessWidget {
|
||||
fontWeight: FontWeight.w600,
|
||||
color: foreground,
|
||||
);
|
||||
subtitleStyle = text.tabLabelTextStyle.copyWith(
|
||||
subtitleStyle = text.textStyle.copyWith(
|
||||
fontSize: 13,
|
||||
color:
|
||||
foreground ?? CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
|
||||
@@ -111,7 +111,7 @@ class StickySectionTitle extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
final row = Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 13, end: 8),
|
||||
padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
||||
@@ -147,6 +147,11 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
final pagerPill = find.ancestor(
|
||||
of: find.byKey(ChangesVisitPager.nextKey),
|
||||
matching: find.byType(GlassPill),
|
||||
);
|
||||
expect(tester.getRect(pagerPill).width, lessThan(400));
|
||||
|
||||
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
|
||||
await tester.pump();
|
||||
|
||||
@@ -206,5 +206,45 @@ 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',
|
||||
},
|
||||
);
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/graph/viewport/graph_expanded_view.dart';
|
||||
import 'package:pipelines_app/features/graph/viewport/graph_viewport.dart';
|
||||
import 'package:pipelines_app/features/graph/viewport/graph_viewport_math.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
||||
@@ -103,7 +105,7 @@ void main() {
|
||||
isTrue,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expanded-close')));
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GraphExpandedView), findsNothing);
|
||||
@@ -195,14 +197,18 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('graph-expand')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(GraphExpandedView), findsOneWidget);
|
||||
expect(_inExpanded(find.text(graphExpandedClose)), findsOneWidget);
|
||||
expect(
|
||||
_inExpanded(find.byType(CupertinoNavigationBarBackButton)),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_inExpanded(find.byKey(const Key('graph-fit'))), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<GraphStageNode>(_inExpanded(_node('build'))).selected,
|
||||
isTrue,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expanded-close')));
|
||||
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(GraphExpandedView), findsNothing);
|
||||
expect(tester.widget<GraphStageNode>(_node('build')).selected, isTrue);
|
||||
@@ -210,4 +216,43 @@ void main() {
|
||||
expect(picked, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('expanded Fit is an activatable labelled button on both hosts', (
|
||||
tester,
|
||||
) async {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: DefinitionGraphView(
|
||||
graph: linearGraph(),
|
||||
selectedStage: 'build',
|
||||
onSelected: (_) {},
|
||||
),
|
||||
),
|
||||
)
|
||||
: _materialHost(
|
||||
graph: linearGraph(),
|
||||
selected: 'build',
|
||||
onSelected: (_) {},
|
||||
),
|
||||
);
|
||||
await _settle(tester);
|
||||
await tester.tap(find.byKey(const Key('graph-expand')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final fit = tester
|
||||
.getSemantics(_inExpanded(find.byKey(const Key('graph-fit'))))
|
||||
.getSemanticsData();
|
||||
expect(fit.label, graphFitLabel, reason: '$host Fit must be labelled');
|
||||
expect(fit.flagsCollection.isButton, isTrue);
|
||||
expect(
|
||||
fit.hasAction(SemanticsAction.tap),
|
||||
isTrue,
|
||||
reason: '$host Fit must expose its tap action on the labelled node',
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,6 +82,16 @@ void main() {
|
||||
expect(_text('error'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the rendered/raw control remains compact', (tester) async {
|
||||
tester.view.physicalSize = const Size(800, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(_material(_view()));
|
||||
|
||||
final control = find.byKey(const Key('markdown-source-mode'));
|
||||
expect(tester.getRect(control).width, lessThan(221));
|
||||
});
|
||||
|
||||
testWidgets('the raw section keeps unknown fields exact and selectable', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -128,7 +128,7 @@ void main() {
|
||||
isTrue,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expanded-close')));
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GraphExpandedView), findsNothing);
|
||||
@@ -149,7 +149,7 @@ void main() {
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expand')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('graph-expanded-close')));
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GraphExpandedView), findsNothing);
|
||||
|
||||
@@ -55,6 +55,7 @@ void main() {
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host())));
|
||||
expect(tester.getTopLeft(find.text('Input')).dx, 16);
|
||||
expect(find.text('line 0'), findsOneWidget);
|
||||
// Empty space well right of the short title, left of the chevron.
|
||||
final strip = tester.getRect(find.byType(StickySectionTitle));
|
||||
|
||||
Reference in New Issue
Block a user