Merge: draggable list/detail divider, remembered per tab

This commit is contained in:
2026-11-03 10:49:35 +00:00
10 changed files with 837 additions and 115 deletions
+222
View File
@@ -0,0 +1,222 @@
import 'dart:ui' show SemanticsAction;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/list_detail.dart';
import 'package:pipelines_app/shell/list_pane_divider.dart';
import 'package:pipelines_app/shell/list_pane_widths.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
/// Dragging the divider between a list and its open item resizes the list,
/// within bounds, per destination, remembered on this device.
void main() {
Future<void> setSize(WidgetTester tester, Size size) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
Widget panes(String name) => ListDetailPanes(
list: ShellBar(child: ListView(children: [Text('$name list')])),
detail: Center(child: Text('$name detail')),
);
Widget shell({
required bool cupertino,
required ListPaneWidthStore store,
AppDestination destination = AppDestination.runs,
}) {
final app = AdaptiveShell(
cupertino: cupertino,
destination: destination,
listPaneWidthStore: store,
destinationBodies: {
AppDestination.runs: (_) => panes('runs'),
AppDestination.chat: (_) => panes('chat'),
},
);
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
}
Future<void> settle(WidgetTester tester) async {
await tester.pump();
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
}
double listWidth(WidgetTester tester) =>
tester.getSize(find.byKey(const ValueKey('list-detail-list'))).width;
double bodyWidth(WidgetTester tester) =>
tester.getSize(find.byKey(const ValueKey('list-detail-body'))).width;
// The shell's top bar, narrowed to the list pane.
double shellBarWidth(WidgetTester tester) => tester
.getSize(
find
.descendant(
of: find.byType(ListPaneWidth),
matching: find.byType(SizedBox),
)
.first,
)
.width;
final divider = find.byKey(const ValueKey('list-detail-divider'));
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: dragging resizes the list live, the shell bar '
'follows, and the width clamps', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore();
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
expect(shellBarWidth(tester), kListPaneMaxWidth);
final gesture = await tester.startGesture(tester.getCenter(divider));
await gesture.moveBy(const Offset(-50, 0));
await gesture.moveBy(const Offset(-50, 0));
await tester.pump();
// Live, before the drag ends; nothing saved yet.
expect(listWidth(tester), closeTo(340, 0.5));
expect(shellBarWidth(tester), closeTo(340, 0.5));
expect(bodyWidth(tester), closeTo(1200 - 1 - 340, 0.5));
expect(store.values, isEmpty);
await gesture.up();
await tester.pump();
expect(store.values['runs'], closeTo(340, 0.5));
// Never narrower than the minimum...
await tester.drag(divider, const Offset(-400, 0));
await settle(tester);
expect(listWidth(tester), kListPaneMinWidth);
// ...nor wider than leaves the open item half the window.
await tester.drag(divider, const Offset(900, 0));
await settle(tester);
expect(listWidth(tester), closeTo(1200 - 1 - 600, 0.5));
expect(shellBarWidth(tester), closeTo(599, 0.5));
expect(store.values['runs'], closeTo(599, 0.5));
});
testWidgets('$host: a double tap returns to the default policy', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore({'runs': 300});
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), 300);
await tester.tap(divider);
await tester.pump(const Duration(milliseconds: 50));
await tester.tap(divider);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
expect(shellBarWidth(tester), kListPaneMaxWidth);
expect(store.values, isEmpty);
});
testWidgets('$host: widths are kept per destination and restored', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore({'runs': 300, 'chat': 500});
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), 300);
expect(shellBarWidth(tester), 300);
await tester.pumpWidget(
shell(
cupertino: cupertino,
store: store,
destination: AppDestination.chat,
),
);
await settle(tester);
final chatList = find.byKey(const ValueKey('list-detail-list')).last;
expect(tester.getSize(chatList).width, 500);
expect(shellBarWidth(tester), 500);
// A destination nobody resized keeps the default policy.
final fresh = MemoryListPaneWidthStore({'chat': 500});
await tester.pumpWidget(const SizedBox());
await tester.pumpWidget(shell(cupertino: cupertino, store: fresh));
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
});
testWidgets('$host: a small window clamps the saved width without '
'overwriting it', (tester) async {
await setSize(tester, const Size(1000, 800));
final store = MemoryListPaneWidthStore({'runs': 600});
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
expect(listWidth(tester), closeTo(1000 - 1 - 500, 0.5));
expect(shellBarWidth(tester), closeTo(499, 0.5));
expect(store.values['runs'], 600);
await setSize(tester, const Size(1600, 800));
await settle(tester);
expect(listWidth(tester), 600);
expect(shellBarWidth(tester), 600);
});
testWidgets('$host: arrow keys move the divider and it reads as a '
'slider', (tester) async {
await setSize(tester, const Size(1200, 800));
final store = MemoryListPaneWidthStore();
final semantics = tester.ensureSemantics();
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
await settle(tester);
Focus.of(tester.element(divider)).requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth - kListPaneDividerKeyStep);
expect(store.values['runs'], kListPaneMaxWidth - kListPaneDividerKeyStep);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth + kListPaneDividerKeyStep);
expect(
tester.getSemantics(divider),
matchesSemantics(
label: 'List width',
hint: 'Drag, or use the arrow keys, to resize the list',
value: '456 pixels',
increasedValue: '472 pixels',
decreasedValue: '440 pixels',
isSlider: true,
isFocusable: true,
isFocused: true,
hasIncreaseAction: true,
hasDecreaseAction: true,
hasFocusAction: true,
),
);
tester.semantics.performAction(
find.semantics.byLabel('List width'),
SemanticsAction.decrease,
);
await settle(tester);
expect(listWidth(tester), kListPaneMaxWidth);
semantics.dispose();
});
}
test('bounds: list at least 240, open item at least half the window', () {
expect(listPaneWidthBounds(1200, 1200), (min: 240.0, max: 599.0));
expect(listPaneWidthBounds(600, 600), (min: 240.0, max: 279.0));
expect(listPaneWidthBounds(500, 500), isNull);
expect(listDetailListWidth(1200, 1200, 100), 240);
expect(listDetailListWidth(1200, 1200, 300), 300);
expect(listDetailListWidth(500, 500, 300), listDetailListWidth(500, 500));
});
}