merge(app): land detail pages and the still artifact viewer

This commit is contained in:
2026-10-23 23:02:18 +01:00
13 changed files with 616 additions and 120 deletions
@@ -13,8 +13,8 @@ typedef ArtifactHtmlBuilder =
/// empty `sandbox` blocks scripts, forms, popups and navigation; on Android and
/// iOS in a web view with JavaScript disabled and navigation refused. The
/// document never runs code with the app's origin or credentials.
Widget defaultArtifactHtml(BuildContext context, String html) => SizedBox(
key: const Key('artifact-html-preview'),
height: MediaQuery.sizeOf(context).height * 0.7,
child: impl.InertHtmlView(html: html),
);
Widget defaultArtifactHtml(BuildContext context, String html) =>
SizedBox.expand(
key: const Key('artifact-html-preview'),
child: impl.InertHtmlView(html: html),
);
@@ -62,30 +62,26 @@ class ArtifactViewerBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
final resolved = plan.resolved;
final content = SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
child: ArtifactSelectionFacts(
group: page.group,
artifact: page.artifact,
step: null,
resolved: plan.resolved,
),
// The page never scrolls: a thin strip on top, the preview filling the
// middle (it zooms or scrolls itself), the controls along the bottom.
final content = Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_InfoStrip(
label: artifactViewerPositionLabel(
index,
count,
page.artifact.contentType,
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
child: Text(
artifactViewerPositionLabel(
index,
count,
page.artifact.contentType,
),
),
facts: ArtifactSelectionFacts(
group: page.group,
artifact: page.artifact,
step: null,
resolved: plan.resolved,
),
ArtifactPreviewBody(
),
Expanded(
child: ArtifactPreviewBody(
plan: plan,
loading: loading,
markdownBuilder: markdownBuilder,
@@ -93,8 +89,8 @@ class ArtifactViewerBody extends StatelessWidget {
bytes: bytes,
error: error,
),
],
),
),
],
);
final hasPrevious = pagedIndex(index, -1, count) != index;
final hasNext = pagedIndex(index, 1, count) != index;
@@ -332,3 +328,73 @@ class _Pager extends StatelessWidget {
);
}
}
/// The viewer's top edge: where this artifact sits in the list, and an
/// information button for its recorded facts.
class _InfoStrip extends StatelessWidget {
const _InfoStrip({required this.label, required this.facts});
final String label;
final Widget facts;
void _show(BuildContext context) {
if (usesCupertinoHost(context)) {
showCupertinoModalPopup<void>(
context: context,
builder: (context) => CupertinoPopupSurface(
child: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: facts,
),
),
),
);
return;
}
showModalBottomSheet<void>(
context: context,
showDragHandle: true,
builder: (context) => SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: facts,
),
),
);
}
@override
Widget build(BuildContext context) {
final muted = usesCupertinoHost(context)
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
)
: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
return Padding(
padding: const EdgeInsetsDirectional.only(start: 16, end: 4),
child: Row(
children: [
Expanded(
child: Text(
label,
key: const Key('artifact-viewer-position'),
style: muted,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
ArtifactIconAction(
key: const Key('artifact-info'),
label: 'Details',
icon: Icons.info_outline,
cupertinoIcon: CupertinoIcons.info,
onPressed: () => _show(context),
),
],
),
);
}
}
@@ -66,7 +66,8 @@ class ArtifactPreviewBody extends StatelessWidget {
case ArtifactPreviewKind.image:
final data = bytes;
if (data == null) return const _Message('The image is empty.');
return Center(
// Fitted to the frame; pinch to zoom and pan inside it.
return _ZoomableImage(
child: Image.memory(
data,
fit: BoxFit.contain,
@@ -76,23 +77,32 @@ class ArtifactPreviewBody extends StatelessWidget {
);
case ArtifactPreviewKind.text:
// Logs, JSON and source keep their columns: a monospace body.
return _PreviewPadding(
child: SelectableText(
text ?? '',
key: const Key('artifact-text-preview'),
style: const TextStyle(fontFamily: appMonospaceFamily),
return _Scrolling(
child: _PreviewPadding(
child: SelectableText(
text ?? '',
key: const Key('artifact-text-preview'),
style: const TextStyle(fontFamily: appMonospaceFamily),
),
),
);
case ArtifactPreviewKind.markdown:
return _PreviewPadding(child: markdownBuilder(context, text ?? ''));
return _Scrolling(
child: _PreviewPadding(child: markdownBuilder(context, text ?? '')),
);
case ArtifactPreviewKind.html:
return _PreviewPadding(child: htmlBuilder(context, text ?? ''));
// The document fills the frame and scrolls itself.
return htmlBuilder(context, text ?? '');
case ArtifactPreviewKind.table:
return ArtifactTableView(text: text ?? '', delimiter: plan.delimiter);
return _Scrolling(
child: ArtifactTableView(text: text ?? '', delimiter: plan.delimiter),
);
case ArtifactPreviewKind.video:
return ArtifactVideoPlayer(
uri: plan.resolved!.uri,
controllerFactory: videoControllerFactory,
return Center(
child: ArtifactVideoPlayer(
uri: plan.resolved!.uri,
controllerFactory: videoControllerFactory,
),
);
case ArtifactPreviewKind.unsupported:
case ArtifactPreviewKind.unavailable:
@@ -122,8 +132,61 @@ class _Loading extends StatelessWidget {
}
}
/// Preview text at its natural height; the viewer body owns the page scroll so
/// a long document and its actions scroll together instead of nested scrolls.
/// A long document scrolls inside the preview frame; the page itself stays
/// still, with its controls at the edges.
class _Scrolling extends StatelessWidget {
const _Scrolling({required this.child});
final Widget child;
@override
Widget build(BuildContext context) => SingleChildScrollView(
key: const Key('artifact-preview-scroll'),
child: child,
);
}
/// An image fitted to the frame that can be pinched to zoom; panning only
/// starts once zoomed, so a swipe at normal size still turns the page.
class _ZoomableImage extends StatefulWidget {
const _ZoomableImage({required this.child});
final Widget child;
@override
State<_ZoomableImage> createState() => _ZoomableImageState();
}
class _ZoomableImageState extends State<_ZoomableImage> {
final TransformationController _transform = TransformationController();
bool _zoomed = false;
@override
void initState() {
super.initState();
_transform.addListener(() {
final zoomed = _transform.value.getMaxScaleOnAxis() > 1.01;
if (zoomed != _zoomed) setState(() => _zoomed = zoomed);
});
}
@override
void dispose() {
_transform.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => InteractiveViewer(
key: const Key('artifact-image-zoom'),
transformationController: _transform,
panEnabled: _zoomed,
maxScale: 8,
child: SizedBox.expand(child: widget.child),
);
}
/// Preview text with room around it inside its frame.
class _PreviewPadding extends StatelessWidget {
const _PreviewPadding({required this.child});
+52 -32
View File
@@ -1,3 +1,5 @@
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
import 'dart:async';
import 'package:flutter/material.dart';
@@ -163,49 +165,67 @@ class _ChatScreenState extends State<ChatScreen> {
}
}
/// The open chat is its own page over the tabs on a phone.
final DetailPageHost _page = DetailPageHost();
@override
void dispose() {
_page.dispose();
_sessions.dispose();
super.dispose();
}
Widget _thread(String selected, VoidCallback onBack) {
final row = _rowFor(selected);
final start = _startNotice;
return ChatThreadView(
key: ValueKey<String>('chat-session-$selected'),
gateway: widget.gateway,
sessionId: selected,
title: '${row?['title'] ?? ''}'.trim(),
session: row,
syncToken: widget.syncToken,
scrollPositions: _scrollPositions,
initialNotice: start != null && start.id == selected
? start.notice
: null,
onBack: onBack,
onModelChanged: (applied) => _modelChanged(selected, applied),
onCreatedSession: _openCreated,
onSessionRenamed: (title) => _renamed(selected, title),
onSessionClosed: _closed,
);
}
@override
Widget build(BuildContext context) {
final selected = _selected;
final row = selected == null ? null : _rowFor(selected);
final start = _startNotice;
// On a phone an open chat is its own page over the tabs; a wide window
// keeps it in the tab, beside the destination rail.
final narrow = MediaQuery.sizeOf(context).width < kDetailPageMaxWidth;
_page.sync(
context,
selected: selected != null && narrow,
destination: AppDestination.chat,
onClosed: _back,
builder: (context) => selected == null
? const SizedBox.shrink()
: _thread(selected, () => Navigator.of(context).maybePop()),
);
final list = ChatSessionsScreen(
gateway: widget.gateway,
embedded: true,
syncToken: widget.syncToken,
controller: _sessions,
onOpen: _open,
onSessions: _adoptRows,
activeSessionId: narrow ? null : selected,
);
if (narrow) return list;
return Stack(
children: [
Offstage(
offstage: selected != null,
child: ChatSessionsScreen(
gateway: widget.gateway,
embedded: true,
syncToken: widget.syncToken,
controller: _sessions,
onOpen: _open,
onSessions: _adoptRows,
activeSessionId: selected,
),
),
if (selected != null)
ChatThreadView(
key: ValueKey<String>('chat-session-$selected'),
gateway: widget.gateway,
sessionId: selected,
title: '${row?['title'] ?? ''}'.trim(),
session: row,
syncToken: widget.syncToken,
scrollPositions: _scrollPositions,
initialNotice: start != null && start.id == selected
? start.notice
: null,
onBack: _back,
onModelChanged: (applied) => _modelChanged(selected, applied),
onCreatedSession: _openCreated,
onSessionRenamed: (title) => _renamed(selected, title),
onSessionClosed: _closed,
),
Offstage(offstage: selected != null, child: list),
if (selected != null) _thread(selected, _back),
],
);
}
+31 -15
View File
@@ -1,3 +1,5 @@
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -78,6 +80,9 @@ class PipelinesScreen extends StatefulWidget {
class _PipelinesScreenState extends State<PipelinesScreen> {
late PipelinesController _controller;
/// The open pipeline is its own page over the tabs on a phone.
final DetailPageHost _page = DetailPageHost();
/// Counts route stage requests so a re-read detail cannot replay an old one.
int _stageRequest = 0;
@@ -132,6 +137,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
@override
void dispose() {
_page.dispose();
_controller.dispose();
super.dispose();
}
@@ -180,21 +186,31 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
final body = LayoutBuilder(
builder: (context, constraints) {
final wide = constraints.maxWidth >= kPipelinesWideBreakpoint;
if (!wide) {
return _controller.hasSelection
? PipelineDetailPanel(
controller: _controller,
gateway: widget.gateway,
showBack: true,
onRunStarted: widget.onRunStarted,
onViewPipelineRuns: widget.onViewPipelineRuns,
stageKey: stageKey,
stagePipelineId: widget.initialPipelineId,
stageVersion: widget.initialVersion,
stageRequest: _stageRequest,
)
: PipelineListPanel(controller: _controller);
}
// On a phone an open pipeline is its own page over the tabs.
_page.sync(
context,
selected: _controller.hasSelection && !wide,
destination: AppDestination.pipelines,
onClosed: _controller.clearSelection,
builder: (context) => AnimatedBuilder(
animation: _controller,
builder: (context, _) => ShellBar(
title: _controller.detail?.displayName,
child: PipelineDetailPanel(
controller: _controller,
gateway: widget.gateway,
showBack: false,
onRunStarted: widget.onRunStarted,
onViewPipelineRuns: widget.onViewPipelineRuns,
stageKey: stageKey,
stagePipelineId: widget.initialPipelineId,
stageVersion: widget.initialVersion,
stageRequest: _stageRequest,
),
),
),
);
if (!wide) return PipelineListPanel(controller: _controller);
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
+42 -26
View File
@@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
import '../../ui/adaptive/host.dart';
import '../attention/notify/notification_controller.dart';
import '../attention/runtime/attention_controller.dart';
@@ -98,6 +100,9 @@ class _RunsScreenState extends State<RunsScreen> {
/// named run consumes it, whether or not that run is waiting.
bool _decideConsumed = false;
/// The open run is its own page over the tabs.
final DetailPageHost _page = DetailPageHost();
@override
void initState() {
super.initState();
@@ -224,41 +229,52 @@ class _RunsScreenState extends State<RunsScreen> {
controller.removeListener(_selectionChanged);
controller.removeListener(_pipelineFilterChanged);
controller.removeListener(_detailChanged);
_page.dispose();
controller.dispose();
super.dispose();
}
Widget _detail(VoidCallback onBack) => RunDetailView(
controller: controller,
gateway: widget.gateway,
onBack: onBack,
onRunOpened: _select,
onOpenPipeline: widget.onOpenPipeline,
initialStageKey: widget.initialStageKey,
initialVisit: widget.initialVisit,
);
@override
Widget build(BuildContext context) {
final selected = controller.selectedRunId != null;
// On a phone an open run is its own page over the tabs; a wide window
// keeps it in the tab, beside the destination rail.
final narrow = MediaQuery.sizeOf(context).width < kDetailPageMaxWidth;
_page.sync(
context,
selected: selected && narrow,
destination: AppDestination.runs,
onClosed: _back,
builder: (context) => _detail(() => Navigator.of(context).maybePop()),
);
final list = AnimatedBuilder(
animation: controller,
builder: (context, _) => RunsList(
active: !selected,
controller: controller,
onSelected: _select,
syncToken: widget.syncToken,
attentionStore: widget.attentionStore,
attentionNow: widget.attentionNow,
notifications: widget.notifications,
attention: widget.attention,
),
);
if (narrow) return list;
return Stack(
children: [
AnimatedBuilder(
animation: controller,
builder: (context, _) => Offstage(
offstage: selected,
child: RunsList(
active: !selected,
controller: controller,
onSelected: _select,
syncToken: widget.syncToken,
attentionStore: widget.attentionStore,
attentionNow: widget.attentionNow,
notifications: widget.notifications,
attention: widget.attention,
),
),
),
if (selected)
RunDetailView(
controller: controller,
gateway: widget.gateway,
onBack: _back,
onRunOpened: _select,
onOpenPipeline: widget.onOpenPipeline,
initialStageKey: widget.initialStageKey,
initialVisit: widget.initialVisit,
),
Offstage(offstage: selected, child: list),
if (selected) _detail(_back),
],
);
}
+157
View File
@@ -0,0 +1,157 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/adaptive/host.dart';
import 'destination.dart';
import 'shell_bar.dart';
/// Narrower than this, an open item is its own page; wider windows keep it
/// beside the destination rail.
const double kDetailPageMaxWidth = 600;
/// Keeps one full-screen detail page (an open run, pipeline or chat) in step
/// with a screen's selection: selecting pushes the page over the tabs, like a
/// new activity, and closing it (its Back, the system Back) clears the
/// selection. A selection cleared elsewhere (a route change) removes the page.
class DetailPageHost {
Route<void>? _route;
/// The owner's latest build of the page's content, so the open page
/// follows the owner's state (a renamed title, a newer reply).
final ValueNotifier<WidgetBuilder?> _content = ValueNotifier(null);
/// Whether the page is pushed (or about to be).
bool get open => _route != null;
void sync(
BuildContext context, {
required bool selected,
required AppDestination destination,
required WidgetBuilder builder,
required VoidCallback onClosed,
}) {
if (selected && _route != null) {
// Another route cannot be rebuilt mid-build; the page follows next frame.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_route != null) _content.value = builder;
});
}
if (selected && _route == null) {
_content.value = builder;
final route = detailPageRoute(
context,
destination: destination,
builder: (context) => ValueListenableBuilder<WidgetBuilder?>(
valueListenable: _content,
builder: (context, build, _) =>
build == null ? const SizedBox.shrink() : build(context),
),
);
_route = route;
// Pushing during a build is not allowed; the page follows this frame.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!context.mounted || _route != route) return;
Navigator.of(context).push(route).then((_) {
if (_route != route) return;
_route = null;
onClosed();
});
});
} else if (!selected && _route != null) {
final route = _route!;
_route = null;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (route.isActive) route.navigator?.removeRoute(route);
});
}
}
/// Removes the page with its owner.
void dispose() {
// The notifier is left to the page: a page still animating out keeps
// listening to it until it is gone.
final route = _route;
_route = null;
if (route != null && route.isActive) route.navigator?.removeRoute(route);
}
}
/// A full-screen page whose bar shows what the page's content publishes
/// through [ShellBar] (title and actions), with the platform's Back.
Route<void> detailPageRoute(
BuildContext context, {
required AppDestination destination,
required WidgetBuilder builder,
}) {
final page = _DetailPage(destination: destination, builder: builder);
return usesCupertinoHost(context)
? CupertinoPageRoute<void>(builder: (_) => page)
: MaterialPageRoute<void>(builder: (_) => page);
}
class _DetailPage extends StatefulWidget {
const _DetailPage({required this.destination, required this.builder});
final AppDestination destination;
final WidgetBuilder builder;
@override
State<_DetailPage> createState() => _DetailPageState();
}
class _DetailPageState extends State<_DetailPage> {
final ShellBarRegistry _bar = ShellBarRegistry();
@override
void dispose() {
_bar.dispose();
super.dispose();
}
void _back() => Navigator.of(context).maybePop();
@override
Widget build(BuildContext context) {
final body = ShellBarScope(
registry: _bar,
destination: widget.destination,
child: Builder(builder: widget.builder),
);
return ListenableBuilder(
listenable: _bar,
builder: (context, _) {
final spec = _bar.specFor(widget.destination);
final title = spec?.title ?? '';
final actions = spec?.actions ?? const <Widget>[];
if (usesCupertinoHost(context)) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
leading: CupertinoNavigationBarBackButton(
key: const ValueKey('shell.back'),
onPressed: _back,
),
automaticallyImplyLeading: false,
middle: Text(title),
trailing: actions.isEmpty
? null
: Row(mainAxisSize: MainAxisSize.min, children: actions),
),
child: SafeArea(child: body),
);
}
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
leading: BackButton(
key: const ValueKey('shell.back'),
onPressed: _back,
),
title: Text(title),
actions: actions,
),
body: SafeArea(top: false, child: body),
);
},
);
}
}
@@ -118,6 +118,8 @@ void main() {
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsOneWidget);
expect(find.text('# Recorded input'), findsOneWidget);
await tester.tap(find.byKey(const Key('artifact-info')));
await tester.pumpAndSettle();
expect(find.text('review · visit 1'), findsOneWidget);
expect(find.text('text/markdown · 120\u00a0B'), findsOneWidget);
});
@@ -108,6 +108,17 @@ Future<void> _openMarkdownFromGallery(
await tester.pumpAndSettle();
}
/// The recorded facts sit behind the viewer's Details button.
Future<void> showFacts(WidgetTester tester) async {
await tester.tap(find.byKey(const Key('artifact-info')));
await tester.pumpAndSettle();
}
Future<void> hideFacts(WidgetTester tester) async {
await tester.tapAt(const Offset(5, 5));
await tester.pumpAndSettle();
}
void main() {
testWidgets('an image is previewed in-app without opening a tab', (
tester,
@@ -154,7 +165,14 @@ void main() {
Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'),
});
expect(find.byType(Image), findsOneWidget);
// The page itself does not scroll; the image zooms inside its frame.
expect(find.byKey(const Key('artifact-image-zoom')), findsOneWidget);
expect(
find.ancestor(of: find.byType(Image), matching: find.byType(Scrollable)),
findsNothing,
);
expect(find.text('1 of 1 · image/png'), findsOneWidget);
await showFacts(tester);
expect(find.text('image/png · 1.0\u00a0KiB'), findsOneWidget);
expect(opened, isEmpty);
expect(find.byType(AlertDialog), findsNothing);
@@ -180,6 +198,7 @@ void main() {
expect(find.byType(SelectableText), findsOneWidget);
expect(find.text('build ok\n'), findsOneWidget);
await showFacts(tester);
expect(find.text('text/plain · 0\u00a0B'), findsOneWidget);
});
@@ -366,7 +385,9 @@ void main() {
await tester.tap(find.byKey(artifactNextKey));
await tester.pumpAndSettle();
expect(find.text('2 of 3 · image/png'), findsOneWidget);
await showFacts(tester);
expect(find.text('review · visit 2'), findsOneWidget);
await hideFacts(tester);
expect(
tester.widget<IconButton>(find.byKey(artifactPreviousKey)).onPressed,
isNotNull,
@@ -475,8 +496,9 @@ void main() {
expect(find.text('final n = 1;'), findsOneWidget);
expect(find.text('# Report'), findsNothing);
expect(find.text('A paragraph with bold and code.'), findsOneWidget);
// The recorded facts stay visible above the preview.
// The position stays on the top edge; the facts are one tap away.
expect(find.text('1 of 1 · text/markdown'), findsOneWidget);
await showFacts(tester);
expect(find.text('text/markdown · 4.0\u00a0KiB'), findsOneWidget);
expect(find.text('review · visit 1'), findsOneWidget);
});
@@ -496,6 +518,7 @@ void main() {
expect(find.text('Report'), findsOneWidget);
expect(find.text('dart'), findsOneWidget);
expect(find.text('1 of 1 · artifact'), findsOneWidget);
await showFacts(tester);
expect(find.text('type not recorded · 4.0\u00a0KiB'), findsOneWidget);
});
@@ -243,7 +243,7 @@ void main() {
await tester.pageBack();
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back to pipelines'));
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
@@ -282,7 +282,7 @@ void main() {
await tester.pageBack();
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back to pipelines'));
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
@@ -33,9 +33,12 @@ void main() {
expect(find.byKey(const Key('pipeline-list')), findsNothing);
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
await tester.tap(find.byTooltip('Back to pipelines'));
// The open pipeline is its own page: its bar names it and Back closes it.
expect(find.text('Alpha review'), findsWidgets);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
expect(find.byKey(const Key('pipeline-detail')), findsNothing);
});
testWidgets(
@@ -298,4 +298,36 @@ void main() {
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
testWidgets('on a phone an open run is its own page and Back returns', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
int? selected;
var backs = 0;
await tester.pumpWidget(
_materialScreen(
gateway,
onRunSelected: (id) => selected = id,
onBack: (_) => backs++,
),
);
await _mountList(tester, gateway);
await tester.tap(find.text('Beta run'));
await tester.pump();
expect(selected, 2);
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
await tester.pumpAndSettle();
// The run covers the list as a page with its own Back.
expect(find.text('Alpha run'), findsNothing);
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
expect(backs, 1);
expect(find.text('Alpha run'), findsOneWidget);
});
}
+98
View File
@@ -0,0 +1,98 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/shell/detail_page.dart';
import 'package:pipelines_app/shell/shell_bar.dart';
class _Owner extends StatefulWidget {
const _Owner({required this.selection});
final ValueNotifier<String?> selection;
@override
State<_Owner> createState() => _OwnerState();
}
class _OwnerState extends State<_Owner> {
final DetailPageHost page = DetailPageHost();
int closed = 0;
@override
void dispose() {
page.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => ValueListenableBuilder<String?>(
valueListenable: widget.selection,
builder: (context, selected, _) {
page.sync(
context,
selected: selected != null,
destination: AppDestination.runs,
onClosed: () {
closed++;
widget.selection.value = null;
},
builder: (context) =>
ShellBar(title: 'Run $selected', child: Text('detail $selected')),
);
return const Text('the list');
},
);
}
void main() {
testWidgets('a selection opens its page; Back closes it and clears it', (
tester,
) async {
final selection = ValueNotifier<String?>(null);
await tester.pumpWidget(MaterialApp(home: _Owner(selection: selection)));
expect(find.text('the list'), findsOneWidget);
selection.value = '7';
await tester.pumpAndSettle();
// A page of its own over the list, titled by its content.
expect(find.text('detail 7'), findsOneWidget);
expect(find.text('Run 7'), findsOneWidget);
expect(find.text('the list'), findsNothing);
// The open page follows the owner's later state.
selection.value = '8';
await tester.pumpAndSettle();
expect(find.text('detail 8'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('shell.back')));
await tester.pumpAndSettle();
expect(find.text('the list'), findsOneWidget);
expect(selection.value, isNull);
final state = tester.state<_OwnerState>(find.byType(_Owner));
expect(state.closed, 1);
});
testWidgets('a selection cleared elsewhere removes the page', (tester) async {
final selection = ValueNotifier<String?>('3');
await tester.pumpWidget(MaterialApp(home: _Owner(selection: selection)));
await tester.pumpAndSettle();
expect(find.text('detail 3'), findsOneWidget);
selection.value = null;
await tester.pumpAndSettle();
expect(find.text('detail 3'), findsNothing);
expect(find.text('the list'), findsOneWidget);
// Removed by the owner, so nothing is reported back.
expect(tester.state<_OwnerState>(find.byType(_Owner)).closed, 0);
});
testWidgets('the system Back closes the page first', (tester) async {
final selection = ValueNotifier<String?>('5');
await tester.pumpWidget(MaterialApp(home: _Owner(selection: selection)));
await tester.pumpAndSettle();
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
expect(await navigator.maybePop(), isTrue);
await tester.pumpAndSettle();
expect(find.text('the list'), findsOneWidget);
expect(selection.value, isNull);
});
}