40e94cc3da
The four destination buttons move from the bottom right over the detail pane to the bottom of the list pane, centred in the (dragged) list width. The list now keeps the bar's height as bottom clearance; the detail pane clears only the system inset, so its tabs, the chat composer and the artifact actions sit at its bottom edge. Phone layout is unchanged. kStackedBarGap is gone with the stacked bars.
258 lines
9.3 KiB
Dart
258 lines
9.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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_widths.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
|
|
|
/// While a tab shows its list beside an open item, the shell's destination
|
|
/// bar moves to the bottom of the list pane, centred in the list's (dragged)
|
|
/// width. The list clears the bar; the item keeps its whole height, its own
|
|
/// bottom control (its tabs, or a composer) at its bottom edge.
|
|
void main() {
|
|
Future<void> setSize(WidgetTester tester, Size size) async {
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
}
|
|
|
|
/// A detail whose composer sits at the bottom, padded by the media inset
|
|
/// the way the chat composer is.
|
|
Widget composerDetail() => Builder(
|
|
builder: (context) => Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
|
|
child: const SizedBox(
|
|
key: Key('composer'),
|
|
height: 56,
|
|
width: double.infinity,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
Widget listBody() => Builder(
|
|
builder: (context) => ListView(
|
|
key: const Key('list'),
|
|
children: [
|
|
for (var index = 0; index < 40; index++)
|
|
SizedBox(height: 40, child: Text('row $index')),
|
|
],
|
|
),
|
|
);
|
|
|
|
/// A detail with its own floating tabs over a list, like run detail.
|
|
Widget tabsDetail(bool cupertino) => FloatingBarOverlay(
|
|
bar: KeyedSubtree(
|
|
key: const Key('detail-tabs'),
|
|
child: FloatingDestinationBar(
|
|
cupertino: cupertino,
|
|
currentIndex: 0,
|
|
onTap: (_) {},
|
|
items: const [
|
|
FloatingDestinationItem(icon: Icon(Icons.summarize), label: 'One'),
|
|
FloatingDestinationItem(icon: Icon(Icons.timeline), label: 'Two'),
|
|
FloatingDestinationItem(icon: Icon(Icons.inventory), label: 'Three'),
|
|
],
|
|
),
|
|
),
|
|
child: Builder(
|
|
builder: (context) => ListView(
|
|
key: const Key('detail-list'),
|
|
children: [
|
|
for (var index = 0; index < 40; index++)
|
|
SizedBox(height: 40, child: Text('item $index')),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
Widget shell({
|
|
required bool cupertino,
|
|
bool split = true,
|
|
bool tabs = false,
|
|
double textScale = 1,
|
|
ListPaneWidthStore? store,
|
|
}) {
|
|
final app = AdaptiveShell(
|
|
cupertino: cupertino,
|
|
listPaneWidthStore: store ?? MemoryListPaneWidthStore(),
|
|
destination: AppDestination.chat,
|
|
destinationBodies: {
|
|
AppDestination.chat: (_) => split
|
|
? ListDetailPanes(
|
|
list: listBody(),
|
|
detail: tabs ? tabsDetail(cupertino) : composerDetail(),
|
|
)
|
|
: listBody(),
|
|
},
|
|
);
|
|
return MediaQuery(
|
|
data: MediaQueryData.fromView(
|
|
WidgetsBinding.instance.platformDispatcher.views.first,
|
|
).copyWith(textScaler: TextScaler.linear(textScale)),
|
|
child: cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
|
|
);
|
|
}
|
|
|
|
Rect destinationPill(WidgetTester tester) => tester.getRect(
|
|
find
|
|
.ancestor(
|
|
of: find.byKey(const ValueKey('shell.destination.chat')).first,
|
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
|
)
|
|
.first,
|
|
);
|
|
|
|
for (final cupertino in [false, true]) {
|
|
final host = cupertino ? 'Cupertino' : 'Material';
|
|
|
|
for (final width in [1200.0, 1600.0]) {
|
|
testWidgets('$host $width split: the destination bar sits under the '
|
|
'list and the composer at the detail\'s bottom edge', (tester) async {
|
|
await setSize(tester, Size(width, 800));
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
final list = tester.getRect(
|
|
find.byKey(const ValueKey('list-detail-list')),
|
|
);
|
|
final body = tester.getRect(
|
|
find.byKey(const ValueKey('list-detail-body')),
|
|
);
|
|
final pill = destinationPill(tester);
|
|
// Centred at the bottom of the list pane, never over the detail.
|
|
expect(pill.center.dx, closeTo(list.center.dx, 0.5));
|
|
expect(pill.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
|
|
expect(pill.right, lessThanOrEqualTo(list.right));
|
|
expect(pill.overlaps(body), isFalse, reason: 'never over the detail');
|
|
expect(
|
|
pill.width,
|
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
|
);
|
|
|
|
// The composer reaches the detail's bottom edge: nothing is reserved
|
|
// there for the shell's bar any more.
|
|
final composer = tester.getRect(find.byKey(const Key('composer')));
|
|
expect(composer.left, body.left);
|
|
expect(composer.bottom, closeTo(800, 0.5));
|
|
expect(composer.overlaps(pill), isFalse);
|
|
|
|
// The list clears the bar, so its last rows scroll out from under it.
|
|
final listContext = tester.element(find.byKey(const Key('list')));
|
|
expect(
|
|
MediaQuery.paddingOf(listContext).bottom,
|
|
greaterThanOrEqualTo(800 - pill.top),
|
|
);
|
|
await tester.drag(
|
|
find.byKey(const Key('list')),
|
|
const Offset(0, -4000),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final last = tester.getRect(find.text('row 39'));
|
|
expect(last.bottom, lessThanOrEqualTo(pill.top));
|
|
});
|
|
|
|
testWidgets('$host $width split: the item tabs sit at the bottom right '
|
|
'of the detail, and its content clears only them', (tester) async {
|
|
await setSize(tester, Size(width, 800));
|
|
await tester.pumpWidget(shell(cupertino: cupertino, tabs: true));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
final body = tester.getRect(
|
|
find.byKey(const ValueKey('list-detail-body')),
|
|
);
|
|
final pill = destinationPill(tester);
|
|
final tabs = tester.getRect(
|
|
find
|
|
.descendant(
|
|
of: find.byKey(const Key('detail-tabs')),
|
|
matching: find.byKey(FloatingDestinationBar.rowKey),
|
|
)
|
|
.first,
|
|
);
|
|
expect(tabs.right, closeTo(width - kFloatingBarMargin, 0.5));
|
|
expect(tabs.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
|
|
expect(tabs.left, greaterThan(body.left));
|
|
expect(tabs.overlaps(pill), isFalse);
|
|
expect(pill.right, lessThan(body.left));
|
|
|
|
// The item's list pads its end clear of its own tabs.
|
|
final listContext = tester.element(
|
|
find.byKey(const Key('detail-list')),
|
|
);
|
|
expect(
|
|
MediaQuery.paddingOf(listContext).bottom,
|
|
closeTo(800 - tabs.top, 0.5),
|
|
);
|
|
});
|
|
}
|
|
|
|
testWidgets('$host 1200 split: the bar follows a dragged list width', (
|
|
tester,
|
|
) async {
|
|
await setSize(tester, const Size(1200, 800));
|
|
final store = MemoryListPaneWidthStore({'chat': 300});
|
|
await tester.pumpWidget(shell(cupertino: cupertino, store: store));
|
|
await tester.pumpAndSettle();
|
|
final list = tester.getRect(
|
|
find.byKey(const ValueKey('list-detail-list')),
|
|
);
|
|
expect(list.width, closeTo(300, 0.5));
|
|
final pill = destinationPill(tester);
|
|
expect(pill.center.dx, closeTo(list.center.dx, 0.5));
|
|
expect(pill.left, greaterThanOrEqualTo(kFloatingBarMargin - 0.5));
|
|
expect(pill.right, lessThanOrEqualTo(list.right - kFloatingBarMargin));
|
|
});
|
|
|
|
testWidgets('$host 1200 unsplit: the bar is compact at the right edge', (
|
|
tester,
|
|
) async {
|
|
await setSize(tester, const Size(1200, 800));
|
|
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
|
|
await tester.pump();
|
|
final pill = destinationPill(tester);
|
|
expect(pill.right, closeTo(1200 - kFloatingBarMargin, 0.5));
|
|
expect(pill.width, lessThan(1200 * 0.6));
|
|
});
|
|
|
|
testWidgets('$host 390: the bar hugs its tabs at the phone\'s bottom '
|
|
'right', (tester) async {
|
|
await setSize(tester, const Size(390, 844));
|
|
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
|
|
await tester.pump();
|
|
final pill = destinationPill(tester);
|
|
expect(
|
|
pill.width,
|
|
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
|
|
);
|
|
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
|
});
|
|
|
|
for (final width in [600.0, 840.0]) {
|
|
testWidgets('$host $width split at 2x: the bar fits the list pane and '
|
|
'the item tabs the detail, without overflow', (tester) async {
|
|
await setSize(tester, Size(width, 800));
|
|
await tester.pumpWidget(
|
|
shell(cupertino: cupertino, tabs: true, textScale: 2),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(tester.takeException(), isNull);
|
|
final list = tester.getRect(
|
|
find.byKey(const ValueKey('list-detail-list')),
|
|
);
|
|
final pill = destinationPill(tester);
|
|
expect(pill.left, greaterThanOrEqualTo(list.left));
|
|
expect(pill.right, lessThanOrEqualTo(list.right));
|
|
});
|
|
}
|
|
}
|
|
}
|